Use short array syntax
[MAILPOET-2090]
This commit is contained in:
@@ -36,50 +36,50 @@ class SubscribersTest extends \MailPoetTest {
|
||||
$obfuscator = new FieldNameObfuscator();
|
||||
$this->obfuscatedEmail = $obfuscator->obfuscate('email');
|
||||
$this->obfuscatedSegments = $obfuscator->obfuscate('segments');
|
||||
$this->segment_1 = Segment::createOrUpdate(array('name' => 'Segment 1'));
|
||||
$this->segment_2 = Segment::createOrUpdate(array('name' => 'Segment 2'));
|
||||
$this->segment_1 = Segment::createOrUpdate(['name' => 'Segment 1']);
|
||||
$this->segment_2 = Segment::createOrUpdate(['name' => 'Segment 2']);
|
||||
|
||||
$this->subscriber_1 = Subscriber::createOrUpdate(array(
|
||||
$this->subscriber_1 = Subscriber::createOrUpdate([
|
||||
'email' => 'john@mailpoet.com',
|
||||
'first_name' => 'John',
|
||||
'last_name' => 'Doe',
|
||||
'status' => Subscriber::STATUS_UNCONFIRMED,
|
||||
'source' => Source::API,
|
||||
));
|
||||
$this->subscriber_2 = Subscriber::createOrUpdate(array(
|
||||
]);
|
||||
$this->subscriber_2 = Subscriber::createOrUpdate([
|
||||
'email' => 'jane@mailpoet.com',
|
||||
'first_name' => 'Jane',
|
||||
'last_name' => 'Doe',
|
||||
'status' => Subscriber::STATUS_SUBSCRIBED,
|
||||
'segments' => array(
|
||||
'segments' => [
|
||||
$this->segment_1->id,
|
||||
$this->segment_2->id
|
||||
),
|
||||
$this->segment_2->id,
|
||||
],
|
||||
'source' => Source::API,
|
||||
));
|
||||
]);
|
||||
|
||||
$this->form = Form::createOrUpdate(array(
|
||||
$this->form = Form::createOrUpdate([
|
||||
'name' => 'My Form',
|
||||
'body' => Fixtures::get('form_body_template'),
|
||||
'settings' => array(
|
||||
'settings' => [
|
||||
'segments_selected_by' => 'user',
|
||||
'segments' => array(
|
||||
'segments' => [
|
||||
$this->segment_1->id,
|
||||
$this->segment_2->id
|
||||
)
|
||||
)
|
||||
));
|
||||
$this->segment_2->id,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->settings = new SettingsController();
|
||||
// setup mailer
|
||||
$this->settings->set('sender', array(
|
||||
$this->settings->set('sender', [
|
||||
'address' => 'sender@mailpoet.com',
|
||||
'name' => 'Sender'
|
||||
));
|
||||
'name' => 'Sender',
|
||||
]);
|
||||
}
|
||||
|
||||
function testItCanGetASubscriber() {
|
||||
$response = $this->endpoint->get(array('id' => 'not_an_id'));
|
||||
$response = $this->endpoint->get(['id' => 'not_an_id']);
|
||||
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
|
||||
expect($response->errors[0]['message'])->equals(
|
||||
'This subscriber does not exist.'
|
||||
@@ -91,7 +91,7 @@ class SubscribersTest extends \MailPoetTest {
|
||||
'This subscriber does not exist.'
|
||||
);
|
||||
|
||||
$response = $this->endpoint->get(array('id' => $this->subscriber_1->id));
|
||||
$response = $this->endpoint->get(['id' => $this->subscriber_1->id]);
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
expect($response->data)->equals(
|
||||
Subscriber::findOne($this->subscriber_1->id)
|
||||
@@ -102,15 +102,15 @@ class SubscribersTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testItCanSaveANewSubscriber() {
|
||||
$valid_data = array(
|
||||
$valid_data = [
|
||||
'email' => 'raul.doe@mailpoet.com',
|
||||
'first_name' => 'Raul',
|
||||
'last_name' => 'Doe',
|
||||
'segments' => array(
|
||||
'segments' => [
|
||||
$this->segment_1->id,
|
||||
$this->segment_2->id
|
||||
)
|
||||
);
|
||||
$this->segment_2->id,
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->endpoint->save($valid_data);
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
@@ -131,9 +131,9 @@ class SubscribersTest extends \MailPoetTest {
|
||||
expect($response->errors[0]['message'])
|
||||
->equals('Please enter your email address');
|
||||
|
||||
$invalid_data = array(
|
||||
'email' => 'john.doe@invalid'
|
||||
);
|
||||
$invalid_data = [
|
||||
'email' => 'john.doe@invalid',
|
||||
];
|
||||
|
||||
$response = $this->endpoint->save($invalid_data);
|
||||
expect($response->status)->equals(APIResponse::STATUS_BAD_REQUEST);
|
||||
@@ -145,7 +145,7 @@ class SubscribersTest extends \MailPoetTest {
|
||||
function testItCanSaveAnExistingSubscriber() {
|
||||
$subscriber_data = $this->subscriber_2->asArray();
|
||||
unset($subscriber_data['created_at']);
|
||||
$subscriber_data['segments'] = array($this->segment_1->id);
|
||||
$subscriber_data['segments'] = [$this->segment_1->id];
|
||||
$subscriber_data['first_name'] = 'Super Jane';
|
||||
|
||||
$response = $this->endpoint->save($subscriber_data);
|
||||
@@ -176,7 +176,7 @@ class SubscribersTest extends \MailPoetTest {
|
||||
$trashed_subscriber = Subscriber::findOne($this->subscriber_1->id);
|
||||
expect($trashed_subscriber->deleted_at)->notNull();
|
||||
|
||||
$response = $this->endpoint->restore(array('id' => $this->subscriber_1->id));
|
||||
$response = $this->endpoint->restore(['id' => $this->subscriber_1->id]);
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
expect($response->data)->equals(
|
||||
Subscriber::findOne($this->subscriber_1->id)->asArray()
|
||||
@@ -186,7 +186,7 @@ class SubscribersTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testItCanTrashASubscriber() {
|
||||
$response = $this->endpoint->trash(array('id' => $this->subscriber_2->id));
|
||||
$response = $this->endpoint->trash(['id' => $this->subscriber_2->id]);
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
expect($response->data)->equals(
|
||||
Subscriber::findOne($this->subscriber_2->id)->asArray()
|
||||
@@ -196,7 +196,7 @@ class SubscribersTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testItCanDeleteASubscriber() {
|
||||
$response = $this->endpoint->delete(array('id' => $this->subscriber_1->id));
|
||||
$response = $this->endpoint->delete(['id' => $this->subscriber_1->id]);
|
||||
expect($response->data)->isEmpty();
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
expect($response->meta['count'])->equals(1);
|
||||
@@ -204,31 +204,31 @@ class SubscribersTest extends \MailPoetTest {
|
||||
|
||||
function testItCanFilterListing() {
|
||||
// filter by non existing segment
|
||||
$response = $this->endpoint->listing(array(
|
||||
'filter' => array(
|
||||
'segment' => '### invalid_segment_id ###'
|
||||
)
|
||||
));
|
||||
$response = $this->endpoint->listing([
|
||||
'filter' => [
|
||||
'segment' => '### invalid_segment_id ###',
|
||||
],
|
||||
]);
|
||||
|
||||
// it should return all subscribers
|
||||
expect($response->meta['count'])->equals(2);
|
||||
|
||||
// filter by 1st segment
|
||||
$response = $this->endpoint->listing(array(
|
||||
'filter' => array(
|
||||
'segment' => $this->segment_1->id
|
||||
)
|
||||
));
|
||||
$response = $this->endpoint->listing([
|
||||
'filter' => [
|
||||
'segment' => $this->segment_1->id,
|
||||
],
|
||||
]);
|
||||
|
||||
expect($response->meta['count'])->equals(1);
|
||||
expect($response->data[0]['email'])->equals($this->subscriber_2->email);
|
||||
|
||||
// filter by 2nd segment
|
||||
$response = $this->endpoint->listing(array(
|
||||
'filter' => array(
|
||||
'segment' => $this->segment_2->id
|
||||
)
|
||||
));
|
||||
$response = $this->endpoint->listing([
|
||||
'filter' => [
|
||||
'segment' => $this->segment_2->id,
|
||||
],
|
||||
]);
|
||||
|
||||
expect($response->meta['count'])->equals(1);
|
||||
expect($response->data[0]['email'])->equals($this->subscriber_2->email);
|
||||
@@ -239,83 +239,83 @@ class SubscribersTest extends \MailPoetTest {
|
||||
return 'segment';
|
||||
};
|
||||
add_filter('mailpoet_subscribers_listings_filters_segments', $add_segment);
|
||||
$response = $this->endpoint->listing(array(
|
||||
'filter' => array(
|
||||
'segment' => $this->segment_2->id
|
||||
)
|
||||
));
|
||||
$response = $this->endpoint->listing([
|
||||
'filter' => [
|
||||
'segment' => $this->segment_2->id,
|
||||
],
|
||||
]);
|
||||
expect($response->meta['filters']['segment'])->equals('segment');
|
||||
}
|
||||
|
||||
function testItCanSearchListing() {
|
||||
$new_subscriber = Subscriber::createOrUpdate(array(
|
||||
$new_subscriber = Subscriber::createOrUpdate([
|
||||
'email' => 'search.me@find.me',
|
||||
'first_name' => 'Billy Bob',
|
||||
'last_name' => 'Thornton'
|
||||
));
|
||||
'last_name' => 'Thornton',
|
||||
]);
|
||||
|
||||
// empty search returns everything
|
||||
$response = $this->endpoint->listing(array(
|
||||
'search' => ''
|
||||
));
|
||||
$response = $this->endpoint->listing([
|
||||
'search' => '',
|
||||
]);
|
||||
expect($response->meta['count'])->equals(3);
|
||||
|
||||
// search by email
|
||||
$response = $this->endpoint->listing(array(
|
||||
'search' => '.me'
|
||||
));
|
||||
$response = $this->endpoint->listing([
|
||||
'search' => '.me',
|
||||
]);
|
||||
expect($response->meta['count'])->equals(1);
|
||||
expect($response->data[0]['email'])->equals($new_subscriber->email);
|
||||
|
||||
// search by last name
|
||||
$response = $this->endpoint->listing(array(
|
||||
'search' => 'doe'
|
||||
));
|
||||
$response = $this->endpoint->listing([
|
||||
'search' => 'doe',
|
||||
]);
|
||||
expect($response->meta['count'])->equals(2);
|
||||
expect($response->data[0]['email'])->equals($this->subscriber_1->email);
|
||||
expect($response->data[1]['email'])->equals($this->subscriber_2->email);
|
||||
|
||||
// search by first name
|
||||
$response = $this->endpoint->listing(array(
|
||||
'search' => 'billy'
|
||||
));
|
||||
$response = $this->endpoint->listing([
|
||||
'search' => 'billy',
|
||||
]);
|
||||
expect($response->meta['count'])->equals(1);
|
||||
expect($response->data[0]['email'])->equals($new_subscriber->email);
|
||||
}
|
||||
|
||||
function testItCanGroupListing() {
|
||||
$subscribed_group = $this->endpoint->listing(array(
|
||||
'group' => Subscriber::STATUS_SUBSCRIBED
|
||||
));
|
||||
$subscribed_group = $this->endpoint->listing([
|
||||
'group' => Subscriber::STATUS_SUBSCRIBED,
|
||||
]);
|
||||
expect($subscribed_group->meta['count'])->equals(1);
|
||||
expect($subscribed_group->data[0]['email'])->equals(
|
||||
$this->subscriber_2->email
|
||||
);
|
||||
|
||||
$unsubscribed_group = $this->endpoint->listing(array(
|
||||
'group' => Subscriber::STATUS_UNSUBSCRIBED
|
||||
));
|
||||
$unsubscribed_group = $this->endpoint->listing([
|
||||
'group' => Subscriber::STATUS_UNSUBSCRIBED,
|
||||
]);
|
||||
expect($unsubscribed_group->meta['count'])->equals(0);
|
||||
|
||||
$unconfirmed_group = $this->endpoint->listing(array(
|
||||
'group' => Subscriber::STATUS_UNCONFIRMED
|
||||
));
|
||||
$unconfirmed_group = $this->endpoint->listing([
|
||||
'group' => Subscriber::STATUS_UNCONFIRMED,
|
||||
]);
|
||||
expect($unconfirmed_group->meta['count'])->equals(1);
|
||||
expect($unconfirmed_group->data[0]['email'])->equals(
|
||||
$this->subscriber_1->email
|
||||
);
|
||||
|
||||
$trashed_group = $this->endpoint->listing(array(
|
||||
'group' => 'trash'
|
||||
));
|
||||
$trashed_group = $this->endpoint->listing([
|
||||
'group' => 'trash',
|
||||
]);
|
||||
expect($trashed_group->meta['count'])->equals(0);
|
||||
|
||||
// trash 1st subscriber
|
||||
$this->subscriber_1->trash();
|
||||
|
||||
$trashed_group = $this->endpoint->listing(array(
|
||||
'group' => 'trash'
|
||||
));
|
||||
$trashed_group = $this->endpoint->listing([
|
||||
'group' => 'trash',
|
||||
]);
|
||||
expect($trashed_group->meta['count'])->equals(1);
|
||||
expect($trashed_group->data[0]['email'])->equals(
|
||||
$this->subscriber_1->email
|
||||
@@ -323,13 +323,13 @@ class SubscribersTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testItCorrectSubscriptionStatus() {
|
||||
$segment = Segment::createOrUpdate(array('name' => 'Segment185245'));
|
||||
$segment = Segment::createOrUpdate(['name' => 'Segment185245']);
|
||||
$subscriber = Subscriber::createOrUpdate([
|
||||
'email' => 'third@example.com',
|
||||
'status' => Subscriber::STATUS_SUBSCRIBED,
|
||||
'segments' => array(
|
||||
'segments' => [
|
||||
$segment->id,
|
||||
),
|
||||
],
|
||||
'source' => Source::API,
|
||||
]);
|
||||
SubscriberSegment::createOrUpdate([
|
||||
@@ -348,11 +348,11 @@ class SubscribersTest extends \MailPoetTest {
|
||||
|
||||
function testItCanSortAndLimitListing() {
|
||||
// get 1st page (limit items per page to 1)
|
||||
$response = $this->endpoint->listing(array(
|
||||
$response = $this->endpoint->listing([
|
||||
'limit' => 1,
|
||||
'sort_by' => 'first_name',
|
||||
'sort_order' => 'asc'
|
||||
));
|
||||
'sort_order' => 'asc',
|
||||
]);
|
||||
|
||||
expect($response->meta['count'])->equals(2);
|
||||
expect($response->data)->count(1);
|
||||
@@ -361,12 +361,12 @@ class SubscribersTest extends \MailPoetTest {
|
||||
);
|
||||
|
||||
// get 1st page (limit items per page to 1)
|
||||
$response = $this->endpoint->listing(array(
|
||||
$response = $this->endpoint->listing([
|
||||
'limit' => 1,
|
||||
'offset' => 1,
|
||||
'sort_by' => 'first_name',
|
||||
'sort_order' => 'asc'
|
||||
));
|
||||
'sort_order' => 'asc',
|
||||
]);
|
||||
|
||||
expect($response->meta['count'])->equals(2);
|
||||
expect($response->data)->count(1);
|
||||
@@ -376,21 +376,21 @@ class SubscribersTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testItCanBulkDeleteSelectionOfSubscribers() {
|
||||
$deletable_subscriber = Subscriber::createOrUpdate(array(
|
||||
'email' => 'to.be.removed@mailpoet.com'
|
||||
));
|
||||
$deletable_subscriber = Subscriber::createOrUpdate([
|
||||
'email' => 'to.be.removed@mailpoet.com',
|
||||
]);
|
||||
|
||||
$selection_ids = array(
|
||||
$selection_ids = [
|
||||
$this->subscriber_1->id,
|
||||
$deletable_subscriber->id
|
||||
);
|
||||
$deletable_subscriber->id,
|
||||
];
|
||||
|
||||
$response = $this->endpoint->bulkAction(array(
|
||||
'listing' => array(
|
||||
'selection' => $selection_ids
|
||||
),
|
||||
'action' => 'delete'
|
||||
));
|
||||
$response = $this->endpoint->bulkAction([
|
||||
'listing' => [
|
||||
'selection' => $selection_ids,
|
||||
],
|
||||
'action' => 'delete',
|
||||
]);
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
expect($response->data)->isEmpty();
|
||||
expect($response->meta['count'])->equals(count($selection_ids));
|
||||
@@ -407,88 +407,88 @@ class SubscribersTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testItCanBulkDeleteSubscribers() {
|
||||
$response = $this->endpoint->bulkAction(array(
|
||||
$response = $this->endpoint->bulkAction([
|
||||
'action' => 'trash',
|
||||
'listing' => array('group' => 'all')
|
||||
));
|
||||
'listing' => ['group' => 'all'],
|
||||
]);
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
expect($response->meta['count'])->equals(2);
|
||||
|
||||
$response = $this->endpoint->bulkAction(array(
|
||||
$response = $this->endpoint->bulkAction([
|
||||
'action' => 'delete',
|
||||
'listing' => array('group' => 'trash')
|
||||
));
|
||||
'listing' => ['group' => 'trash'],
|
||||
]);
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
expect($response->meta['count'])->equals(2);
|
||||
|
||||
$response = $this->endpoint->bulkAction(array(
|
||||
$response = $this->endpoint->bulkAction([
|
||||
'action' => 'delete',
|
||||
'listing' => array('group' => 'trash')
|
||||
));
|
||||
'listing' => ['group' => 'trash'],
|
||||
]);
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
expect($response->meta['count'])->equals(0);
|
||||
}
|
||||
|
||||
function testItCannotRunAnInvalidBulkAction() {
|
||||
$response = $this->endpoint->bulkAction(array(
|
||||
$response = $this->endpoint->bulkAction([
|
||||
'action' => 'invalidAction',
|
||||
'listing' => array()
|
||||
));
|
||||
'listing' => [],
|
||||
]);
|
||||
expect($response->status)->equals(APIResponse::STATUS_NOT_FOUND);
|
||||
expect($response->errors[0]['message'])->contains('has no method');
|
||||
}
|
||||
|
||||
function testItFailsWithEmailFilled() {
|
||||
$response = $this->endpoint->subscribe(array(
|
||||
$response = $this->endpoint->subscribe([
|
||||
'form_id' => $this->form->id,
|
||||
'email' => 'toto@mailpoet.com'
|
||||
'email' => 'toto@mailpoet.com',
|
||||
// no form ID specified
|
||||
));
|
||||
]);
|
||||
|
||||
expect($response->status)->equals(APIResponse::STATUS_BAD_REQUEST);
|
||||
expect($response->errors[0]['message'])->equals('Please leave the first field empty.');
|
||||
}
|
||||
|
||||
function testItCannotSubscribeWithoutFormID() {
|
||||
$response = $this->endpoint->subscribe(array(
|
||||
'form_field_ZW1haWw' => 'toto@mailpoet.com'
|
||||
$response = $this->endpoint->subscribe([
|
||||
'form_field_ZW1haWw' => 'toto@mailpoet.com',
|
||||
// no form ID specified
|
||||
));
|
||||
]);
|
||||
|
||||
expect($response->status)->equals(APIResponse::STATUS_BAD_REQUEST);
|
||||
expect($response->errors[0]['message'])->equals('Please specify a valid form ID.');
|
||||
}
|
||||
|
||||
function testItCannotSubscribeWithoutSegmentsIfTheyAreSelectedByUser() {
|
||||
$response = $this->endpoint->subscribe(array(
|
||||
$response = $this->endpoint->subscribe([
|
||||
$this->obfuscatedEmail => 'toto@mailpoet.com',
|
||||
'form_id' => $this->form->id
|
||||
'form_id' => $this->form->id,
|
||||
// no segments specified
|
||||
));
|
||||
]);
|
||||
|
||||
expect($response->status)->equals(APIResponse::STATUS_BAD_REQUEST);
|
||||
expect($response->errors[0]['message'])->equals('Please select a list.');
|
||||
}
|
||||
|
||||
function testItCanSubscribe() {
|
||||
$response = $this->endpoint->subscribe(array(
|
||||
$response = $this->endpoint->subscribe([
|
||||
$this->obfuscatedEmail => 'toto@mailpoet.com',
|
||||
'form_id' => $this->form->id,
|
||||
$this->obfuscatedSegments => array($this->segment_1->id, $this->segment_2->id)
|
||||
));
|
||||
$this->obfuscatedSegments => [$this->segment_1->id, $this->segment_2->id],
|
||||
]);
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
}
|
||||
|
||||
function testItCannotSubscribeWithoutCaptchaWhenEnabled() {
|
||||
$this->settings->set('re_captcha', array('enabled' => true));
|
||||
$response = $this->endpoint->subscribe(array(
|
||||
$this->settings->set('re_captcha', ['enabled' => true]);
|
||||
$response = $this->endpoint->subscribe([
|
||||
$this->obfuscatedEmail => 'toto@mailpoet.com',
|
||||
'form_id' => $this->form->id,
|
||||
$this->obfuscatedSegments => array($this->segment_1->id, $this->segment_2->id)
|
||||
));
|
||||
$this->obfuscatedSegments => [$this->segment_1->id, $this->segment_2->id],
|
||||
]);
|
||||
expect($response->status)->equals(APIResponse::STATUS_BAD_REQUEST);
|
||||
expect($response->errors[0]['message'])->equals('Please check the CAPTCHA.');
|
||||
$this->settings->set('re_captcha', array());
|
||||
$this->settings->set('re_captcha', []);
|
||||
}
|
||||
|
||||
function testItCannotSubscribeWithoutMandatoryCustomField() {
|
||||
@@ -509,11 +509,11 @@ class SubscribersTest extends \MailPoetTest {
|
||||
'position' => '0',
|
||||
]],
|
||||
]);
|
||||
$response = $this->endpoint->subscribe(array(
|
||||
$response = $this->endpoint->subscribe([
|
||||
$this->obfuscatedEmail => 'toto@mailpoet.com',
|
||||
'form_id' => $form->id,
|
||||
$this->obfuscatedSegments => array($this->segment_1->id, $this->segment_2->id)
|
||||
));
|
||||
$this->obfuscatedSegments => [$this->segment_1->id, $this->segment_2->id],
|
||||
]);
|
||||
expect($response->status)->equals(APIResponse::STATUS_BAD_REQUEST);
|
||||
}
|
||||
|
||||
@@ -523,11 +523,11 @@ class SubscribersTest extends \MailPoetTest {
|
||||
$this->form->settings = $form['settings'];
|
||||
$this->form->save();
|
||||
|
||||
$response = $this->endpoint->subscribe(array(
|
||||
$response = $this->endpoint->subscribe([
|
||||
$this->obfuscatedEmail => 'toto@mailpoet.com',
|
||||
'form_id' => $this->form->id
|
||||
'form_id' => $this->form->id,
|
||||
// no segments specified
|
||||
));
|
||||
]);
|
||||
|
||||
expect($response->status)->equals(APIResponse::STATUS_OK);
|
||||
$subscriber = Subscriber::where('email', 'toto@mailpoet.com')->findOne();
|
||||
@@ -544,11 +544,11 @@ class SubscribersTest extends \MailPoetTest {
|
||||
$this->form->settings = $form['settings'];
|
||||
$this->form->save();
|
||||
|
||||
$response = $this->endpoint->subscribe(array(
|
||||
$response = $this->endpoint->subscribe([
|
||||
$this->obfuscatedEmail => 'toto@mailpoet.com',
|
||||
'form_id' => $this->form->id,
|
||||
$this->obfuscatedSegments => array($this->segment_1->id, $this->segment_2->id)
|
||||
));
|
||||
$this->obfuscatedSegments => [$this->segment_1->id, $this->segment_2->id],
|
||||
]);
|
||||
|
||||
expect($response->status)->equals(APIResponse::STATUS_BAD_REQUEST);
|
||||
expect($response->errors[0]['message'])->equals('Please select a list.');
|
||||
@@ -557,18 +557,18 @@ class SubscribersTest extends \MailPoetTest {
|
||||
function testItCannotMassSubscribe() {
|
||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||
|
||||
$this->endpoint->subscribe(array(
|
||||
$this->endpoint->subscribe([
|
||||
$this->obfuscatedEmail => 'toto@mailpoet.com',
|
||||
'form_id' => $this->form->id,
|
||||
$this->obfuscatedSegments => array($this->segment_1->id, $this->segment_2->id)
|
||||
));
|
||||
$this->obfuscatedSegments => [$this->segment_1->id, $this->segment_2->id],
|
||||
]);
|
||||
|
||||
try {
|
||||
$this->endpoint->subscribe(array(
|
||||
$this->endpoint->subscribe([
|
||||
$this->obfuscatedEmail => 'tata@mailpoet.com',
|
||||
'form_id' => $this->form->id,
|
||||
$this->obfuscatedSegments => array($this->segment_1->id, $this->segment_2->id)
|
||||
));
|
||||
$this->obfuscatedSegments => [$this->segment_1->id, $this->segment_2->id],
|
||||
]);
|
||||
$this->fail('It should not be possible to subscribe a second time so soon');
|
||||
} catch (\Exception $e) {
|
||||
expect($e->getMessage())->equals('You need to wait 60 seconds before subscribing again.');
|
||||
@@ -578,11 +578,11 @@ class SubscribersTest extends \MailPoetTest {
|
||||
function testItCannotMassResubscribe() {
|
||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||
|
||||
$this->endpoint->subscribe(array(
|
||||
$this->endpoint->subscribe([
|
||||
$this->obfuscatedEmail => 'toto@mailpoet.com',
|
||||
'form_id' => $this->form->id,
|
||||
$this->obfuscatedSegments => array($this->segment_1->id, $this->segment_2->id)
|
||||
));
|
||||
$this->obfuscatedSegments => [$this->segment_1->id, $this->segment_2->id],
|
||||
]);
|
||||
|
||||
// Try to resubscribe an existing subscriber that was updated just now
|
||||
$subscriber = Subscriber::where('email', 'toto@mailpoet.com')->findOne();
|
||||
@@ -591,11 +591,11 @@ class SubscribersTest extends \MailPoetTest {
|
||||
$subscriber->save();
|
||||
|
||||
try {
|
||||
$this->endpoint->subscribe(array(
|
||||
$this->endpoint->subscribe([
|
||||
$this->obfuscatedEmail => $subscriber->email,
|
||||
'form_id' => $this->form->id,
|
||||
$this->obfuscatedSegments => array($this->segment_1->id, $this->segment_2->id)
|
||||
));
|
||||
$this->obfuscatedSegments => [$this->segment_1->id, $this->segment_2->id],
|
||||
]);
|
||||
$this->fail('It should not be possible to resubscribe a second time so soon');
|
||||
} catch (\Exception $e) {
|
||||
expect($e->getMessage())->equals('You need to wait 60 seconds before subscribing again.');
|
||||
@@ -604,14 +604,14 @@ class SubscribersTest extends \MailPoetTest {
|
||||
|
||||
function testItSchedulesWelcomeEmailNotificationWhenSubscriberIsAdded() {
|
||||
$this->_createWelcomeNewsletter();
|
||||
$subscriber_data = array(
|
||||
$subscriber_data = [
|
||||
'email' => 'raul.doe@mailpoet.com',
|
||||
'first_name' => 'Raul',
|
||||
'last_name' => 'Doe',
|
||||
'segments' => array(
|
||||
$this->segment_1->id
|
||||
)
|
||||
);
|
||||
'segments' => [
|
||||
$this->segment_1->id,
|
||||
],
|
||||
];
|
||||
|
||||
$this->endpoint->save($subscriber_data);
|
||||
expect(SendingQueue::findMany())->count(1);
|
||||
@@ -619,27 +619,27 @@ class SubscribersTest extends \MailPoetTest {
|
||||
|
||||
function testItSchedulesWelcomeEmailNotificationWhenExistedSubscriberIsUpdated() {
|
||||
$this->_createWelcomeNewsletter();
|
||||
$subscriber_data = array(
|
||||
$subscriber_data = [
|
||||
'email' => 'raul.doe@mailpoet.com',
|
||||
'first_name' => 'Raul',
|
||||
'last_name' => 'Doe',
|
||||
'segments' => array(
|
||||
$this->segment_2->id
|
||||
)
|
||||
);
|
||||
'segments' => [
|
||||
$this->segment_2->id,
|
||||
],
|
||||
];
|
||||
|
||||
// welcome notification is created only for segment #1
|
||||
$this->endpoint->save($subscriber_data);
|
||||
expect(SendingQueue::findMany())->isEmpty();
|
||||
|
||||
$subscriber_data['segments'] = array($this->segment_1->id);
|
||||
$subscriber_data['segments'] = [$this->segment_1->id];
|
||||
$this->endpoint->save($subscriber_data);
|
||||
expect(SendingQueue::findMany())->count(1);
|
||||
}
|
||||
|
||||
function testItDoesNotSchedulesWelcomeEmailNotificationWhenNoNewSegmentIsAdded() {
|
||||
$this->_createWelcomeNewsletter();
|
||||
$subscriber = Subscriber::createOrUpdate(array(
|
||||
$subscriber = Subscriber::createOrUpdate([
|
||||
'email' => 'raul.doe@mailpoet.com',
|
||||
'first_name' => 'Jane',
|
||||
'last_name' => 'Doe',
|
||||
@@ -648,16 +648,16 @@ class SubscribersTest extends \MailPoetTest {
|
||||
$this->segment_1->id,
|
||||
],
|
||||
'source' => Source::IMPORTED,
|
||||
));
|
||||
$subscriber_data = array(
|
||||
]);
|
||||
$subscriber_data = [
|
||||
'id' => $subscriber->id(),
|
||||
'email' => 'raul.doe@mailpoet.com',
|
||||
'first_name' => 'Raul',
|
||||
'last_name' => 'Doe',
|
||||
'segments' => array(
|
||||
$this->segment_1->id
|
||||
)
|
||||
);
|
||||
'segments' => [
|
||||
$this->segment_1->id,
|
||||
],
|
||||
];
|
||||
|
||||
$this->endpoint->save($subscriber_data);
|
||||
expect(SendingQueue::findMany())->count(0);
|
||||
@@ -670,11 +670,11 @@ class SubscribersTest extends \MailPoetTest {
|
||||
$welcome_newsletter->save();
|
||||
expect($welcome_newsletter->getErrors())->false();
|
||||
|
||||
$welcome_newsletter_options = array(
|
||||
$welcome_newsletter_options = [
|
||||
'event' => 'segment',
|
||||
'segment' => $this->segment_1->id,
|
||||
'schedule' => '* * * * *'
|
||||
);
|
||||
'schedule' => '* * * * *',
|
||||
];
|
||||
|
||||
foreach ($welcome_newsletter_options as $option => $value) {
|
||||
$newsletter_option_field = NewsletterOptionField::create();
|
||||
|
Reference in New Issue
Block a user