Rename Send classes

[MAILPOET-1522]
This commit is contained in:
Pavel Dohnal
2018-10-15 13:06:19 +02:00
parent 40c19cd5d8
commit 654dd1e8d0
10 changed files with 36 additions and 36 deletions

View File

@ -7,8 +7,8 @@ use MailPoet\Models\Subscriber;
use MailPoet\Models\SubscriberSegment; use MailPoet\Models\SubscriberSegment;
use MailPoet\Newsletter\Scheduler\Scheduler; use MailPoet\Newsletter\Scheduler\Scheduler;
use MailPoet\Subscribers\RequiredCustomFieldValidator; use MailPoet\Subscribers\RequiredCustomFieldValidator;
use MailPoet\Subscribers\SendConfirmationEmail; use MailPoet\Subscribers\ConfirmationEmailMailer;
use MailPoet\Subscribers\SendNewSubscriberNotification; use MailPoet\Subscribers\NewSubscriberNotificationMailer;
use MailPoet\Subscribers\Source; use MailPoet\Subscribers\Source;
use MailPoet\Tasks\Sending; use MailPoet\Tasks\Sending;
@ -255,7 +255,7 @@ class API {
} }
protected function _sendConfirmationEmail(Subscriber $subscriber) { protected function _sendConfirmationEmail(Subscriber $subscriber) {
$sender = new SendConfirmationEmail(); $sender = new ConfirmationEmailMailer();
return $sender->sendConfirmationEmail($subscriber); return $sender->sendConfirmationEmail($subscriber);
} }
@ -274,7 +274,7 @@ class API {
} }
private function sendSubscriberNotification(Subscriber $subscriber, array $segment_ids) { private function sendSubscriberNotification(Subscriber $subscriber, array $segment_ids) {
$sender = new SendNewSubscriberNotification(); $sender = new NewSubscriberNotificationMailer();
$sender->send($subscriber, Segment::whereIn('id', $segment_ids)->findMany()); $sender->send($subscriber, Segment::whereIn('id', $segment_ids)->findMany());
} }
} }

View File

@ -9,7 +9,7 @@ use MailPoet\Models\Segment;
use MailPoet\Models\Setting; use MailPoet\Models\Setting;
use MailPoet\Models\Subscriber; use MailPoet\Models\Subscriber;
use MailPoet\Settings\Pages; use MailPoet\Settings\Pages;
use MailPoet\Subscribers\SendNewSubscriberNotification; use MailPoet\Subscribers\NewSubscriberNotificationMailer;
class Reporter { class Reporter {
@ -48,7 +48,7 @@ class Reporter {
'Newsletter task scheduler (cron)' => $isCronTriggerMethodWP ? 'visitors' : 'script', 'Newsletter task scheduler (cron)' => $isCronTriggerMethodWP ? 'visitors' : 'script',
'Open and click tracking' => (boolean)Setting::getValue('tracking.enabled', false), 'Open and click tracking' => (boolean)Setting::getValue('tracking.enabled', false),
'Premium key valid' => $checker->isPremiumKeyValid(), 'Premium key valid' => $checker->isPremiumKeyValid(),
'New subscriber notifications' => SendNewSubscriberNotification::isDisabled(Setting::getValue(SendNewSubscriberNotification::SETTINGS_KEY)), 'New subscriber notifications' => NewSubscriberNotificationMailer::isDisabled(Setting::getValue(NewSubscriberNotificationMailer::SETTINGS_KEY)),
'Number of standard newsletters sent in last 3 months' => $newsletters['sent_newsletters'], 'Number of standard newsletters sent in last 3 months' => $newsletters['sent_newsletters'],
'Number of active post notifications' => $newsletters['notifications_count'], 'Number of active post notifications' => $newsletters['notifications_count'],
'Number of active welcome emails' => $newsletters['welcome_newsletters_count'], 'Number of active welcome emails' => $newsletters['welcome_newsletters_count'],

View File

@ -11,7 +11,7 @@ use MailPoet\Models\Subscriber;
use MailPoet\Segments\WP; use MailPoet\Segments\WP;
use MailPoet\Models\Setting; use MailPoet\Models\Setting;
use MailPoet\Settings\Pages; use MailPoet\Settings\Pages;
use MailPoet\Subscribers\SendNewSubscriberNotification; use MailPoet\Subscribers\NewSubscriberNotificationMailer;
use MailPoet\Subscribers\Source; use MailPoet\Subscribers\Source;
use MailPoet\Util\Helpers; use MailPoet\Util\Helpers;
@ -171,7 +171,7 @@ class Populator {
)); ));
} }
$subscriber_email_notification = Setting::getValue(SendNewSubscriberNotification::SETTINGS_KEY); $subscriber_email_notification = Setting::getValue(NewSubscriberNotificationMailer::SETTINGS_KEY);
if(empty($subscriber_email_notification)) { if(empty($subscriber_email_notification)) {
$sender = Setting::getValue('sender', []); $sender = Setting::getValue('sender', []);
Setting::setValue('subscriber_email_notification', [ Setting::setValue('subscriber_email_notification', [

View File

@ -2,8 +2,8 @@
namespace MailPoet\Models; namespace MailPoet\Models;
use MailPoet\Mailer\Mailer; use MailPoet\Mailer\Mailer;
use MailPoet\Newsletter\Scheduler\Scheduler; use MailPoet\Newsletter\Scheduler\Scheduler;
use MailPoet\Subscribers\SendConfirmationEmail; use MailPoet\Subscribers\ConfirmationEmailMailer;
use MailPoet\Subscribers\SendNewSubscriberNotification; use MailPoet\Subscribers\NewSubscriberNotificationMailer;
use MailPoet\Subscribers\Source; use MailPoet\Subscribers\Source;
use MailPoet\Util\Helpers; use MailPoet\Util\Helpers;
use MailPoet\Subscription; use MailPoet\Subscription;
@ -152,11 +152,11 @@ class Subscriber extends Model {
// link subscriber to segments // link subscriber to segments
SubscriberSegment::subscribeToSegments($subscriber, $segment_ids); SubscriberSegment::subscribeToSegments($subscriber, $segment_ids);
$sender = new SendConfirmationEmail(); $sender = new ConfirmationEmailMailer();
$sender->sendConfirmationEmail($subscriber); $sender->sendConfirmationEmail($subscriber);
if($subscriber->status === self::STATUS_SUBSCRIBED) { if($subscriber->status === self::STATUS_SUBSCRIBED) {
$sender = new SendNewSubscriberNotification(); $sender = new NewSubscriberNotificationMailer();
$sender->send($subscriber, Segment::whereIn('id', $segment_ids)->findMany()); $sender->send($subscriber, Segment::whereIn('id', $segment_ids)->findMany());
Scheduler::scheduleSubscriberWelcomeNotification( Scheduler::scheduleSubscriberWelcomeNotification(

View File

@ -8,7 +8,7 @@ use MailPoet\Models\Subscriber;
use MailPoet\Subscription\Url; use MailPoet\Subscription\Url;
use MailPoet\Util\Helpers; use MailPoet\Util\Helpers;
class SendConfirmationEmail { class ConfirmationEmailMailer {
/** @var Mailer */ /** @var Mailer */
private $mailer; private $mailer;

View File

@ -7,7 +7,7 @@ use MailPoet\Models\Segment;
use MailPoet\Models\Setting; use MailPoet\Models\Setting;
use MailPoet\Models\Subscriber; use MailPoet\Models\Subscriber;
class SendNewSubscriberNotification { class NewSubscriberNotificationMailer {
const SENDER_EMAIL_PREFIX = 'wordpress@'; const SENDER_EMAIL_PREFIX = 'wordpress@';
const SETTINGS_KEY = 'subscriber_email_notification'; const SETTINGS_KEY = 'subscriber_email_notification';
@ -44,7 +44,7 @@ class SendNewSubscriberNotification {
* @throws \Exception * @throws \Exception
*/ */
function send(Subscriber $subscriber, array $segments) { function send(Subscriber $subscriber, array $segments) {
$settings = Setting::getValue(SendNewSubscriberNotification::SETTINGS_KEY); $settings = Setting::getValue(NewSubscriberNotificationMailer::SETTINGS_KEY);
if($this->isDisabled($settings)) { if($this->isDisabled($settings)) {
return; return;
} }

View File

@ -8,7 +8,7 @@ use MailPoet\Models\CustomField;
use MailPoet\Models\Setting; use MailPoet\Models\Setting;
use MailPoet\Models\Segment; use MailPoet\Models\Segment;
use MailPoet\Newsletter\Scheduler\Scheduler; use MailPoet\Newsletter\Scheduler\Scheduler;
use MailPoet\Subscribers\SendNewSubscriberNotification; use MailPoet\Subscribers\NewSubscriberNotificationMailer;
use MailPoet\Util\Helpers; use MailPoet\Util\Helpers;
use MailPoet\Util\Url as UrlHelper; use MailPoet\Util\Url as UrlHelper;
use MailPoet\Form\Renderer as FormRenderer; use MailPoet\Form\Renderer as FormRenderer;
@ -23,7 +23,7 @@ class Pages {
private $action; private $action;
private $data; private $data;
private $subscriber; private $subscriber;
/** @var SendNewSubscriberNotification */ /** @var NewSubscriberNotificationMailer */
private $new_subscriber_notification_sender; private $new_subscriber_notification_sender;
function __construct($action = false, $data = array(), $init_shortcodes = false, $init_page_filters = false, $new_subscriber_notification_sender = null) { function __construct($action = false, $data = array(), $init_shortcodes = false, $init_page_filters = false, $new_subscriber_notification_sender = null) {
@ -35,7 +35,7 @@ class Pages {
if($new_subscriber_notification_sender) { if($new_subscriber_notification_sender) {
$this->new_subscriber_notification_sender = $new_subscriber_notification_sender; $this->new_subscriber_notification_sender = $new_subscriber_notification_sender;
} else { } else {
$this->new_subscriber_notification_sender = new SendNewSubscriberNotification(); $this->new_subscriber_notification_sender = new NewSubscriberNotificationMailer();
} }
} }

View File

@ -9,7 +9,7 @@ use MailPoet\Models\Segment;
use MailPoet\Models\Subscriber; use MailPoet\Models\Subscriber;
use MailPoet\Models\SubscriberSegment; use MailPoet\Models\SubscriberSegment;
class SendConfirmationEmailTest extends \MailPoetTest { class ConfirmationEmailMailerTest extends \MailPoetTest {
function testItSendsConfirmationEmail() { function testItSendsConfirmationEmail() {
Mock::double('MailPoet\Subscription\Url', [ Mock::double('MailPoet\Subscription\Url', [
@ -30,7 +30,7 @@ class SendConfirmationEmailTest extends \MailPoetTest {
}), }),
], $this); ], $this);
$sender = new SendConfirmationEmail($mailer); $sender = new ConfirmationEmailMailer($mailer);
$segment = Segment::createOrUpdate( $segment = Segment::createOrUpdate(
@ -61,7 +61,7 @@ class SendConfirmationEmailTest extends \MailPoetTest {
}), }),
], $this); ], $this);
$sender = new SendConfirmationEmail($mailer); $sender = new ConfirmationEmailMailer($mailer);
$sender->sendConfirmationEmail($subscriber); $sender->sendConfirmationEmail($subscriber);
// error is set on the subscriber model object // error is set on the subscriber model object

View File

@ -9,7 +9,7 @@ use MailPoet\Models\Segment;
use MailPoet\Models\Setting; use MailPoet\Models\Setting;
use MailPoet\Models\Subscriber; use MailPoet\Models\Subscriber;
class SendNewSubscriberNotificationTest extends \MailPoetTest { class NewSubscriberNotificationMailerTest extends \MailPoetTest {
/** @var Subscriber */ /** @var Subscriber */
private $subscriber; private $subscriber;
@ -26,36 +26,36 @@ class SendNewSubscriberNotificationTest extends \MailPoetTest {
} }
function testItDoesNotSendIfNoSettings() { function testItDoesNotSendIfNoSettings() {
Setting::setValue(SendNewSubscriberNotification::SETTINGS_KEY, null); Setting::setValue(NewSubscriberNotificationMailer::SETTINGS_KEY, null);
$mailer = Stub::makeEmpty(Mailer::class, ['getSenderNameAndAddress' => Expected::never()], $this); $mailer = Stub::makeEmpty(Mailer::class, ['getSenderNameAndAddress' => Expected::never()], $this);
$service = new SendNewSubscriberNotification($mailer); $service = new NewSubscriberNotificationMailer($mailer);
$service->send($this->subscriber, $this->segments); $service->send($this->subscriber, $this->segments);
} }
function testItDoesNotSendIfSettingsDoesNotHaveEnabled() { function testItDoesNotSendIfSettingsDoesNotHaveEnabled() {
Setting::setValue(SendNewSubscriberNotification::SETTINGS_KEY, []); Setting::setValue(NewSubscriberNotificationMailer::SETTINGS_KEY, []);
$mailer = Stub::makeEmpty(Mailer::class, ['getSenderNameAndAddress' => Expected::never()], $this); $mailer = Stub::makeEmpty(Mailer::class, ['getSenderNameAndAddress' => Expected::never()], $this);
$service = new SendNewSubscriberNotification($mailer); $service = new NewSubscriberNotificationMailer($mailer);
$service->send($this->subscriber, $this->segments); $service->send($this->subscriber, $this->segments);
} }
function testItDoesNotSendIfSettingsDoesNotHaveAddress() { function testItDoesNotSendIfSettingsDoesNotHaveAddress() {
Setting::setValue(SendNewSubscriberNotification::SETTINGS_KEY, ['enabled' => false]); Setting::setValue(NewSubscriberNotificationMailer::SETTINGS_KEY, ['enabled' => false]);
$mailer = Stub::makeEmpty(Mailer::class, ['getSenderNameAndAddress' => Expected::never()], $this); $mailer = Stub::makeEmpty(Mailer::class, ['getSenderNameAndAddress' => Expected::never()], $this);
$service = new SendNewSubscriberNotification($mailer); $service = new NewSubscriberNotificationMailer($mailer);
$service->send($this->subscriber, $this->segments); $service->send($this->subscriber, $this->segments);
} }
function testItDoesNotSendIfDisabled() { function testItDoesNotSendIfDisabled() {
Setting::setValue(SendNewSubscriberNotification::SETTINGS_KEY, ['enabled' => false, 'address' => 'a@b.c']); Setting::setValue(NewSubscriberNotificationMailer::SETTINGS_KEY, ['enabled' => false, 'address' => 'a@b.c']);
$mailer = Stub::makeEmpty(Mailer::class, ['getSenderNameAndAddress' => Expected::never()], $this); $mailer = Stub::makeEmpty(Mailer::class, ['getSenderNameAndAddress' => Expected::never()], $this);
$service = new SendNewSubscriberNotification($mailer); $service = new NewSubscriberNotificationMailer($mailer);
$service->send($this->subscriber, $this->segments); $service->send($this->subscriber, $this->segments);
} }
function testItSends() { function testItSends() {
Setting::setValue(SendNewSubscriberNotification::SETTINGS_KEY, ['enabled' => true, 'address' => 'a@b.c']); Setting::setValue(NewSubscriberNotificationMailer::SETTINGS_KEY, ['enabled' => true, 'address' => 'a@b.c']);
$mailer = Stub::makeEmpty(Mailer::class, [ $mailer = Stub::makeEmpty(Mailer::class, [
'getSenderNameAndAddress' => 'getSenderNameAndAddress' =>
@ -79,7 +79,7 @@ class SendNewSubscriberNotificationTest extends \MailPoetTest {
}), }),
], $this); ], $this);
$service = new SendNewSubscriberNotification($mailer); $service = new NewSubscriberNotificationMailer($mailer);
$service->send($this->subscriber, $this->segments); $service->send($this->subscriber, $this->segments);
} }

View File

@ -11,7 +11,7 @@ use MailPoet\Models\Segment;
use MailPoet\Models\SendingQueue; use MailPoet\Models\SendingQueue;
use MailPoet\Models\Subscriber; use MailPoet\Models\Subscriber;
use MailPoet\Models\SubscriberSegment; use MailPoet\Models\SubscriberSegment;
use MailPoet\Subscribers\SendNewSubscriberNotification; use MailPoet\Subscribers\NewSubscriberNotificationMailer;
use MailPoet\Subscription\Pages; use MailPoet\Subscription\Pages;
class PagesTest extends \MailPoetTest { class PagesTest extends \MailPoetTest {
@ -29,7 +29,7 @@ class PagesTest extends \MailPoetTest {
} }
function testItConfirmsSubscription() { function testItConfirmsSubscription() {
$new_subscriber_notification_sender = Stub::makeEmpty(SendNewSubscriberNotification::class, ['send' => Stub\Expected::once()]); $new_subscriber_notification_sender = Stub::makeEmpty(NewSubscriberNotificationMailer::class, ['send' => Stub\Expected::once()]);
$subscription = new Pages($action = false, $this->test_data, false, false, $new_subscriber_notification_sender); $subscription = new Pages($action = false, $this->test_data, false, false, $new_subscriber_notification_sender);
$subscription->confirm(); $subscription->confirm();
$confirmed_subscriber = Subscriber::findOne($this->subscriber->id); $confirmed_subscriber = Subscriber::findOne($this->subscriber->id);
@ -37,7 +37,7 @@ class PagesTest extends \MailPoetTest {
} }
function testItDoesNotConfirmSubscriptionOnDuplicateAttempt() { function testItDoesNotConfirmSubscriptionOnDuplicateAttempt() {
$new_subscriber_notification_sender = Stub::makeEmpty(SendNewSubscriberNotification::class, ['send' => Stub\Expected::once()]); $new_subscriber_notification_sender = Stub::makeEmpty(NewSubscriberNotificationMailer::class, ['send' => Stub\Expected::once()]);
$subscriber = $this->subscriber; $subscriber = $this->subscriber;
$subscriber->status = Subscriber::STATUS_SUBSCRIBED; $subscriber->status = Subscriber::STATUS_SUBSCRIBED;
$subscriber->save(); $subscriber->save();
@ -46,7 +46,7 @@ class PagesTest extends \MailPoetTest {
} }
function testItSendsWelcomeNotificationUponConfirmingSubscription() { function testItSendsWelcomeNotificationUponConfirmingSubscription() {
$new_subscriber_notification_sender = Stub::makeEmpty(SendNewSubscriberNotification::class, ['send' => Stub\Expected::once()]); $new_subscriber_notification_sender = Stub::makeEmpty(NewSubscriberNotificationMailer::class, ['send' => Stub\Expected::once()]);
$subscription = new Pages($action = false, $this->test_data, false, false, $new_subscriber_notification_sender); $subscription = new Pages($action = false, $this->test_data, false, false, $new_subscriber_notification_sender);
// create segment // create segment
$segment = Segment::create(); $segment = Segment::create();