Add an option for sending admin notification
[MAILPOET-2042]
This commit is contained in:
@ -89,6 +89,7 @@ class API {
|
|||||||
function subscribeToLists($subscriber_id, array $list_ids, $options = []) {
|
function subscribeToLists($subscriber_id, array $list_ids, $options = []) {
|
||||||
$schedule_welcome_email = (isset($options['schedule_welcome_email']) && $options['schedule_welcome_email'] === false) ? false : true;
|
$schedule_welcome_email = (isset($options['schedule_welcome_email']) && $options['schedule_welcome_email'] === false) ? false : true;
|
||||||
$send_confirmation_email = (isset($options['send_confirmation_email']) && $options['send_confirmation_email'] === false) ? false : true;
|
$send_confirmation_email = (isset($options['send_confirmation_email']) && $options['send_confirmation_email'] === false) ? false : true;
|
||||||
|
$skip_subscriber_notification = (isset($options['skip_subscriber_notification']) && $options['skip_subscriber_notification'] === true) ? true : false;
|
||||||
|
|
||||||
if (empty($list_ids)) {
|
if (empty($list_ids)) {
|
||||||
throw new \Exception(__('At least one segment ID is required.', 'mailpoet'));
|
throw new \Exception(__('At least one segment ID is required.', 'mailpoet'));
|
||||||
@ -153,6 +154,10 @@ class API {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$skip_subscriber_notification) {
|
||||||
|
$this->sendSubscriberNotification($subscriber, $found_segments_ids);
|
||||||
|
}
|
||||||
|
|
||||||
return $subscriber->withCustomFields()->withSubscriptions()->asArray();
|
return $subscriber->withCustomFields()->withSubscriptions()->asArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,21 +245,45 @@ class APITest extends \MailPoetTest {
|
|||||||
$segments = [$segment->id];
|
$segments = [$segment->id];
|
||||||
|
|
||||||
// should not send
|
// should not send
|
||||||
$API->subscribeToLists($subscriber->email, $segments, ['send_confirmation_email' => false]);
|
$API->subscribeToLists($subscriber->email, $segments, ['send_confirmation_email' => false, 'skip_subscriber_notification' => true]);
|
||||||
expect($sent)->equals(false);
|
expect($sent)->equals(false);
|
||||||
|
|
||||||
// should send
|
// should send
|
||||||
$API->subscribeToLists($subscriber->email, $segments);
|
$API->subscribeToLists($subscriber->email, $segments, ['skip_subscriber_notification' => true]);
|
||||||
expect($sent)->equals(true);
|
expect($sent)->equals(true);
|
||||||
|
|
||||||
// should not send
|
// should not send
|
||||||
$sent = false;
|
$sent = false;
|
||||||
$subscriber->count_confirmations = 1;
|
$subscriber->count_confirmations = 1;
|
||||||
$subscriber->save();
|
$subscriber->save();
|
||||||
$API->subscribeToLists($subscriber->email, $segments);
|
$API->subscribeToLists($subscriber->email, $segments, ['skip_subscriber_notification' => true]);
|
||||||
expect($sent)->equals(false);
|
expect($sent)->equals(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testItSendsNotifiationEmailWhenBeingAddedToList() {
|
||||||
|
$subscriber = Subscriber::create();
|
||||||
|
$subscriber->hydrate(Fixtures::get('subscriber_template'));
|
||||||
|
$subscriber->status = Subscriber::STATUS_UNCONFIRMED;
|
||||||
|
$subscriber->save();
|
||||||
|
$segment = Segment::createOrUpdate([
|
||||||
|
'name' => 'Default',
|
||||||
|
'type' => Segment::TYPE_DEFAULT,
|
||||||
|
]);
|
||||||
|
$segment->save();
|
||||||
|
$segments = [$segment->id];
|
||||||
|
|
||||||
|
// should not send
|
||||||
|
$notificationMailer = $this->make(NewSubscriberNotificationMailer::class, ['send' => \Codeception\Stub\Expected::never()]);
|
||||||
|
$API = new \MailPoet\API\MP\v1\API($notificationMailer, $this->makeEmpty(ConfirmationEmailMailer::class), $this->makeEmpty(RequiredCustomFieldValidator::class));
|
||||||
|
$API->subscribeToLists($subscriber->email, $segments, ['send_confirmation_email' => false, 'skip_subscriber_notification' => true]);
|
||||||
|
|
||||||
|
|
||||||
|
// should send
|
||||||
|
$notificationMailer = $this->make(NewSubscriberNotificationMailer::class, ['send' => \Codeception\Stub\Expected::once()]);
|
||||||
|
$API = new \MailPoet\API\MP\v1\API($notificationMailer, $this->makeEmpty(ConfirmationEmailMailer::class), $this->makeEmpty(RequiredCustomFieldValidator::class));
|
||||||
|
$API->subscribeToLists($subscriber->email, $segments, ['send_confirmation_email' => false, 'skip_subscriber_notification' => false]);
|
||||||
|
}
|
||||||
|
|
||||||
function testItSubscribesSubscriberWithEmailIdentifier() {
|
function testItSubscribesSubscriberWithEmailIdentifier() {
|
||||||
$subscriber = Subscriber::create();
|
$subscriber = Subscriber::create();
|
||||||
$subscriber->hydrate(Fixtures::get('subscriber_template'));
|
$subscriber->hydrate(Fixtures::get('subscriber_template'));
|
||||||
@ -293,7 +317,7 @@ class APITest extends \MailPoetTest {
|
|||||||
'type' => Segment::TYPE_DEFAULT,
|
'type' => Segment::TYPE_DEFAULT,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$API->subscribeToLists($subscriber->id, [$segment->id]);
|
$API->subscribeToLists($subscriber->id, [$segment->id], ['skip_subscriber_notification' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItDoesNotScheduleWelcomeNotificationAfterSubscribingSubscriberToListsIfStatusIsNotSubscribed() {
|
function testItDoesNotScheduleWelcomeNotificationAfterSubscribingSubscriberToListsIfStatusIsNotSubscribed() {
|
||||||
@ -312,7 +336,7 @@ class APITest extends \MailPoetTest {
|
|||||||
'type' => Segment::TYPE_DEFAULT,
|
'type' => Segment::TYPE_DEFAULT,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$API->subscribeToLists($subscriber->id, [$segment->id]);
|
$API->subscribeToLists($subscriber->id, [$segment->id], ['skip_subscriber_notification' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItDoesNotScheduleWelcomeNotificationAfterSubscribingSubscriberToListsWhenDisabledByOption() {
|
function testItDoesNotScheduleWelcomeNotificationAfterSubscribingSubscriberToListsWhenDisabledByOption() {
|
||||||
@ -332,7 +356,7 @@ class APITest extends \MailPoetTest {
|
|||||||
'type' => Segment::TYPE_DEFAULT,
|
'type' => Segment::TYPE_DEFAULT,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$options = ['schedule_welcome_email' => false];
|
$options = ['schedule_welcome_email' => false, 'skip_subscriber_notification' => true];
|
||||||
$API->subscribeToLists($subscriber->id, [$segment->id], $options);
|
$API->subscribeToLists($subscriber->id, [$segment->id], $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user