diff --git a/lib/Config/Initializer.php b/lib/Config/Initializer.php index f9ca4d35ba..3ede1b9cfd 100644 --- a/lib/Config/Initializer.php +++ b/lib/Config/Initializer.php @@ -55,6 +55,9 @@ class Initializer { /** @var PermanentNotices */ private $permanent_notices; + /** @var Shortcodes */ + private $shortcodes; + const INITIALIZED = 'MAILPOET_INITIALIZED'; function __construct( @@ -68,7 +71,8 @@ class Initializer { Changelog $changelog, Menu $menu, CronTrigger $cron_trigger, - PermanentNotices $permanent_notices + PermanentNotices $permanent_notices, + Shortcodes $shortcodes ) { $this->renderer_factory = $renderer_factory; $this->access_control = $access_control; @@ -81,6 +85,7 @@ class Initializer { $this->menu = $menu; $this->cron_trigger = $cron_trigger; $this->permanent_notices = $permanent_notices; + $this->shortcodes = $shortcodes; } function init() { @@ -248,8 +253,7 @@ class Initializer { } function setupShortcodes() { - $shortcodes = new Shortcodes(); - $shortcodes->init(); + $this->shortcodes->init(); } function setupImages() { diff --git a/lib/Config/Shortcodes.php b/lib/Config/Shortcodes.php index e01c7ab46a..2b7804ea84 100644 --- a/lib/Config/Shortcodes.php +++ b/lib/Config/Shortcodes.php @@ -2,6 +2,7 @@ namespace MailPoet\Config; +use MailPoet\Form\Widget; use MailPoet\Models\Newsletter; use MailPoet\Models\Subscriber; use MailPoet\Models\SubscriberSegment; @@ -10,26 +11,31 @@ use MailPoet\Subscription\Pages; use MailPoet\WP\Functions as WPFunctions; class Shortcodes { + /** @var Pages */ + private $subscription_pages; + + /** @var WPFunctions */ private $wp; - function __construct() { - $this->wp = new WPFunctions; + function __construct(Pages $subscription_pages, WPFunctions $wp) { + $this->subscription_pages = $subscription_pages; + $this->wp = $wp; } function init() { // form widget shortcode - WPFunctions::get()->addShortcode('mailpoet_form', [$this, 'formWidget']); + $this->wp->addShortcode('mailpoet_form', [$this, 'formWidget']); // subscribers count shortcode - WPFunctions::get()->addShortcode('mailpoet_subscribers_count', [ + $this->wp->addShortcode('mailpoet_subscribers_count', [ $this, 'getSubscribersCount', ]); - WPFunctions::get()->addShortcode('wysija_subscribers_count', [ + $this->wp->addShortcode('wysija_subscribers_count', [ $this, 'getSubscribersCount', ]); // archives page - WPFunctions::get()->addShortcode('mailpoet_archive', [ + $this->wp->addShortcode('mailpoet_archive', [ $this, 'getArchive', ]); @@ -39,18 +45,18 @@ class Shortcodes { $this->wp->addFilter('mailpoet_archive_subject', [ $this, 'renderArchiveSubject', ], 2, 3); - + // initialize subscription pages data + $this->subscription_pages->init(); // initialize subscription management shortcodes - $subscription_page = new Pages(); - $subscription_page->initShortcodes(); + $this->subscription_pages->initShortcodes(); } function formWidget($params = []) { // IMPORTANT: fixes conflict with MagicMember - WPFunctions::get()->removeShortcode('user_list'); + $this->wp->removeShortcode('user_list'); if (isset($params['id']) && (int)$params['id'] > 0) { - $form_widget = new \MailPoet\Form\Widget(); + $form_widget = new Widget(); return $form_widget->widget([ 'form' => (int)$params['id'], 'form_type' => 'shortcode', @@ -66,9 +72,9 @@ class Shortcodes { } if (empty($segment_ids)) { - return WPFunctions::get()->numberFormatI18n(Subscriber::filter('subscribed')->count()); + return $this->wp->numberFormatI18n(Subscriber::filter('subscribed')->count()); } else { - return WPFunctions::get()->numberFormatI18n( + return $this->wp->numberFormatI18n( SubscriberSegment::whereIn('segment_id', $segment_ids) ->select('subscriber_id')->distinct() ->filter('subscribed') @@ -94,7 +100,7 @@ class Shortcodes { if (empty($newsletters)) { return $this->wp->applyFilters( 'mailpoet_archive_no_newsletters', - WPFunctions::get()->__('Oops! There are no newsletters to display.', 'mailpoet') + $this->wp->__('Oops! There are no newsletters to display.', 'mailpoet') ); } else { $title = $this->wp->applyFilters('mailpoet_archive_title', ''); @@ -119,8 +125,8 @@ class Shortcodes { } function renderArchiveDate($newsletter) { - return WPFunctions::get()->dateI18n( - WPFunctions::get()->getOption('date_format'), + return $this->wp->dateI18n( + $this->wp->getOption('date_format'), strtotime($newsletter->processed_at) ); } diff --git a/lib/DI/ContainerConfigurator.php b/lib/DI/ContainerConfigurator.php index f2c391fc51..4f9d13204a 100644 --- a/lib/DI/ContainerConfigurator.php +++ b/lib/DI/ContainerConfigurator.php @@ -64,6 +64,8 @@ class ContainerConfigurator implements IContainerConfigurator { $container->autowire(\MailPoet\Config\Menu::class)->setPublic(true); $container->autowire(\MailPoet\Config\RendererFactory::class)->setPublic(true); $container->autowire(\MailPoet\Config\ServicesChecker::class); + $container->autowire(\MailPoet\Config\Shortcodes::class) + ->setShared(false); $container->register(\MailPoet\Config\Renderer::class) ->setPublic(true) ->setFactory([new Reference(\MailPoet\Config\RendererFactory::class), 'getRenderer']); @@ -121,6 +123,8 @@ class ContainerConfigurator implements IContainerConfigurator { $container->autowire(\MailPoet\Subscription\Comment::class)->setPublic(true); $container->autowire(\MailPoet\Subscription\Form::class)->setPublic(true); $container->autowire(\MailPoet\Subscription\Manage::class)->setPublic(true); + $container->autowire(\MailPoet\Subscription\Pages::class)->setPublic(true) + ->setShared(false); $container->autowire(\MailPoet\Subscription\Registration::class)->setPublic(true); // Newsletter $container->autowire(\MailPoet\Newsletter\AutomatedLatestContent::class)->setPublic(true); diff --git a/lib/Router/Endpoints/Subscription.php b/lib/Router/Endpoints/Subscription.php index a8f6174e62..6022abfd89 100644 --- a/lib/Router/Endpoints/Subscription.php +++ b/lib/Router/Endpoints/Subscription.php @@ -21,6 +21,13 @@ class Subscription { 'global' => AccessControl::NO_ACCESS_RESTRICTION, ]; + /** @var UserSubscription\Pages */ + private $subscription_pages; + + function __construct(UserSubscription\Pages $subscription_pages) { + $this->subscription_pages = $subscription_pages; + } + function confirm($data) { $subscription = $this->initSubscriptionPage(UserSubscription\Pages::ACTION_CONFIRM, $data); $subscription->confirm(); @@ -36,6 +43,6 @@ class Subscription { } private function initSubscriptionPage($action, $data) { - return new UserSubscription\Pages($action, $data, true, true); + return $this->subscription_pages->init($action, $data, true, true); } } diff --git a/lib/Subscription/Pages.php b/lib/Subscription/Pages.php index 112d8b5219..d9e114570d 100644 --- a/lib/Subscription/Pages.php +++ b/lib/Subscription/Pages.php @@ -24,27 +24,38 @@ class Pages { private $action; private $data; private $subscriber; + /** @var NewSubscriberNotificationMailer */ private $new_subscriber_notification_sender; + /** @var SettingsController */ private $settings; /** @var UrlHelper */ private $url_helper; - function __construct($action = false, $data = [], $init_shortcodes = false, $init_page_filters = false, $new_subscriber_notification_sender = null) { + /** @var WPFunctions */ + private $wp; + + function __construct( + NewSubscriberNotificationMailer $new_subscriber_notification_sender, + WPFunctions $wp, + SettingsController $settings, + UrlHelper $url_helper + ) { + $this->wp = $wp; + $this->new_subscriber_notification_sender = $new_subscriber_notification_sender; + $this->settings = $settings; + $this->url_helper = $url_helper; + } + + function init($action = false, $data = [], $init_shortcodes = false, $init_page_filters = false) { $this->action = $action; $this->data = $data; $this->subscriber = $this->getSubscriber(); if ($init_page_filters) $this->initPageFilters(); if ($init_shortcodes) $this->initShortcodes(); - if ($new_subscriber_notification_sender) { - $this->new_subscriber_notification_sender = $new_subscriber_notification_sender; - } else { - $this->new_subscriber_notification_sender = new NewSubscriberNotificationMailer(); - } - $this->settings = new SettingsController(); - $this->url_helper = new UrlHelper(new WPFunctions()); + return $this; } private function isPreview() { @@ -52,21 +63,25 @@ class Pages { } function initPageFilters() { - WPFunctions::get()->addFilter('wp_title', [$this,'setWindowTitle'], 10, 3); - WPFunctions::get()->addFilter('document_title_parts', [$this,'setWindowTitleParts'], 10, 1); - WPFunctions::get()->addFilter('the_title', [$this,'setPageTitle'], 10, 1); - WPFunctions::get()->addFilter('the_content', [$this,'setPageContent'], 10, 1); + $this->wp->addFilter('wp_title', [$this,'setWindowTitle'], 10, 3); + $this->wp->addFilter('document_title_parts', [$this,'setWindowTitleParts'], 10, 1); + $this->wp->addFilter('the_title', [$this,'setPageTitle'], 10, 1); + $this->wp->addFilter('the_content', [$this,'setPageContent'], 10, 1); } function initShortcodes() { - WPFunctions::get()->addShortcode('mailpoet_manage', [$this, 'getManageLink']); - WPFunctions::get()->addShortcode('mailpoet_manage_subscription', [$this, 'getManageContent']); + $this->wp->addShortcode('mailpoet_manage', [$this, 'getManageLink']); + $this->wp->addShortcode('mailpoet_manage_subscription', [$this, 'getManageContent']); } - function getSubscriber() { + private function getSubscriber() { + if (!is_null($this->subscriber)) { + return $this->subscriber; + } + $token = (isset($this->data['token'])) ? $this->data['token'] : null; $email = (isset($this->data['email'])) ? $this->data['email'] : null; - $wp_user = WPFunctions::get()->wpGetCurrentUser(); + $wp_user = $this->wp->wpGetCurrentUser(); if (!$email && $wp_user->exists()) { return Subscriber::where('wp_user_id', $wp_user->ID)->findOne(); @@ -82,6 +97,7 @@ class Pages { } function confirm() { + $this->subscriber = $this->getSubscriber(); if ($this->subscriber === false || $this->subscriber->status === Subscriber::STATUS_SUBSCRIBED) { return false; } @@ -130,13 +146,13 @@ class Pages { global $post; if ($this->isPreview() === false && $this->subscriber === false) { - return WPFunctions::get()->__("Hmmm... we don't have a record of you.", 'mailpoet'); + return $this->wp->__("Hmmm... we don't have a record of you.", 'mailpoet'); } if ( - ($post->post_title !== WPFunctions::get()->__('MailPoet Page', 'mailpoet')) + ($post->post_title !== $this->wp->__('MailPoet Page', 'mailpoet')) || - ($page_title !== WPFunctions::get()->singlePostTitle('', false)) + ($page_title !== $this->wp->singlePostTitle('', false)) ) { // when it's a custom page, just return the original page title return $page_title; @@ -160,7 +176,7 @@ class Pages { // if we're not in preview mode and the subscriber does not exist if ($this->isPreview() === false && $this->subscriber === false) { - return WPFunctions::get()->__("Your email address doesn't appear in our lists anymore. Sign up again or contact us if this appears to be a mistake.", 'mailpoet'); + return $this->wp->__("Your email address doesn't appear in our lists anymore. Sign up again or contact us if this appears to be a mistake.", 'mailpoet'); } if (strpos($page_content, '[mailpoet_page]') !== false) { @@ -204,7 +220,7 @@ class Pages { private function getConfirmTitle() { if ($this->isPreview()) { $title = sprintf( - WPFunctions::get()->__("You have subscribed to: %s", 'mailpoet'), + $this->wp->__("You have subscribed to: %s", 'mailpoet'), 'demo 1, demo 2' ); } else { @@ -213,10 +229,10 @@ class Pages { }, $this->subscriber->segments()->findMany()); if (empty($segment_names)) { - $title = WPFunctions::get()->__("You are now subscribed!", 'mailpoet'); + $title = $this->wp->__("You are now subscribed!", 'mailpoet'); } else { $title = sprintf( - WPFunctions::get()->__("You have subscribed to: %s", 'mailpoet'), + $this->wp->__("You have subscribed to: %s", 'mailpoet'), join(', ', $segment_names) ); } @@ -226,19 +242,19 @@ class Pages { private function getManageTitle() { if ($this->isPreview() || $this->subscriber !== false) { - return WPFunctions::get()->__("Manage your subscription", 'mailpoet'); + return $this->wp->__("Manage your subscription", 'mailpoet'); } } private function getUnsubscribeTitle() { if ($this->isPreview() || $this->subscriber !== false) { - return WPFunctions::get()->__("You are now unsubscribed.", 'mailpoet'); + return $this->wp->__("You are now unsubscribed.", 'mailpoet'); } } private function getConfirmContent() { if ($this->isPreview() || $this->subscriber !== false) { - return WPFunctions::get()->__("Yup, we've added you to our email list. You'll hear from us shortly.", 'mailpoet'); + return $this->wp->__("Yup, we've added you to our email list. You'll hear from us shortly.", 'mailpoet'); } } @@ -255,7 +271,7 @@ class Pages { ->withCustomFields() ->withSubscriptions(); } else { - return WPFunctions::get()->__('Subscription management form is only available to mailing lists subscribers.', 'mailpoet'); + return $this->wp->__('Subscription management form is only available to mailing lists subscribers.', 'mailpoet'); } $custom_fields = array_map(function($custom_field) use($subscriber) { @@ -305,7 +321,7 @@ class Pages { 'id' => 'first_name', 'type' => 'text', 'params' => [ - 'label' => WPFunctions::get()->__('First name', 'mailpoet'), + 'label' => $this->wp->__('First name', 'mailpoet'), 'value' => $subscriber->first_name, 'disabled' => ($subscriber->isWPUser() || $subscriber->isWooCommerceUser()), ], @@ -314,7 +330,7 @@ class Pages { 'id' => 'last_name', 'type' => 'text', 'params' => [ - 'label' => WPFunctions::get()->__('Last name', 'mailpoet'), + 'label' => $this->wp->__('Last name', 'mailpoet'), 'value' => $subscriber->last_name, 'disabled' => ($subscriber->isWPUser() || $subscriber->isWooCommerceUser()), ], @@ -324,11 +340,11 @@ class Pages { 'type' => 'select', 'params' => [ 'required' => true, - 'label' => WPFunctions::get()->__('Status', 'mailpoet'), + 'label' => $this->wp->__('Status', 'mailpoet'), 'values' => [ [ 'value' => [ - Subscriber::STATUS_SUBSCRIBED => WPFunctions::get()->__('Subscribed', 'mailpoet'), + Subscriber::STATUS_SUBSCRIBED => $this->wp->__('Subscribed', 'mailpoet'), ], 'is_checked' => ( $subscriber->status === Subscriber::STATUS_SUBSCRIBED @@ -336,7 +352,7 @@ class Pages { ], [ 'value' => [ - Subscriber::STATUS_UNSUBSCRIBED => WPFunctions::get()->__('Unsubscribed', 'mailpoet'), + Subscriber::STATUS_UNSUBSCRIBED => $this->wp->__('Unsubscribed', 'mailpoet'), ], 'is_checked' => ( $subscriber->status === Subscriber::STATUS_UNSUBSCRIBED @@ -344,7 +360,7 @@ class Pages { ], [ 'value' => [ - Subscriber::STATUS_BOUNCED => WPFunctions::get()->__('Bounced', 'mailpoet'), + Subscriber::STATUS_BOUNCED => $this->wp->__('Bounced', 'mailpoet'), ], 'is_checked' => ( $subscriber->status === Subscriber::STATUS_BOUNCED @@ -356,7 +372,7 @@ class Pages { ], [ 'value' => [ - Subscriber::STATUS_INACTIVE => WPFunctions::get()->__('Inactive', 'mailpoet'), + Subscriber::STATUS_INACTIVE => $this->wp->__('Inactive', 'mailpoet'), ], 'is_checked' => ( $subscriber->status === Subscriber::STATUS_INACTIVE @@ -378,7 +394,7 @@ class Pages { 'id' => 'segments', 'type' => 'segment', 'params' => [ - 'label' => WPFunctions::get()->__('Your lists', 'mailpoet'), + 'label' => $this->wp->__('Your lists', 'mailpoet'), 'values' => $segments, ], ], @@ -386,7 +402,7 @@ class Pages { 'id' => 'submit', 'type' => 'submit', 'params' => [ - 'label' => WPFunctions::get()->__('Save', 'mailpoet'), + 'label' => $this->wp->__('Save', 'mailpoet'), ], ], ] @@ -413,22 +429,22 @@ class Pages { // special case for WP users as they cannot edit their subscriber's email if ($subscriber->isWPUser() || $subscriber->isWooCommerceUser()) { // check if subscriber's associated WP user is the currently logged in WP user - $wp_current_user = WPFunctions::get()->wpGetCurrentUser(); + $wp_current_user = $this->wp->wpGetCurrentUser(); if ($wp_current_user->user_email === $subscriber->email) { $form_html .= Helpers::replaceLinkTags( - WPFunctions::get()->__('[link]Edit your profile[/link] to update your email.', 'mailpoet'), - WPFunctions::get()->getEditProfileUrl(), + $this->wp->__('[link]Edit your profile[/link] to update your email.', 'mailpoet'), + $this->wp->getEditProfileUrl(), ['target' => '_blank'] ); } else { $form_html .= Helpers::replaceLinkTags( - WPFunctions::get()->__('[link]Log in to your account[/link] to update your email.', 'mailpoet'), - WPFunctions::get()->wpLoginUrl(), + $this->wp->__('[link]Log in to your account[/link] to update your email.', 'mailpoet'), + $this->wp->wpLoginUrl(), ['target' => '_blank'] ); } } else { - $form_html .= WPFunctions::get()->__('Need to change your email address? Unsubscribe here, then simply sign up again.', 'mailpoet'); + $form_html .= $this->wp->__('Need to change your email address? Unsubscribe here, then simply sign up again.', 'mailpoet'); } $form_html .= ''; $form_html .= '

'; @@ -450,13 +466,13 @@ class Pages { } function getManageLink($params) { - if (!$this->subscriber) return WPFunctions::get()->__('Link to subscription management page is only available to mailing lists subscribers.', 'mailpoet'); + if (!$this->subscriber) return $this->wp->__('Link to subscription management page is only available to mailing lists subscribers.', 'mailpoet'); // get label or display default label $text = ( isset($params['text']) ? htmlspecialchars($params['text']) - : WPFunctions::get()->__('Manage your subscription', 'mailpoet') + : $this->wp->__('Manage your subscription', 'mailpoet') ); return 'isUserLoggedIn())->true(); expect(Subscriber::findOne($wp_user->data->user_email))->false(); - $shortcodes = new Shortcodes(); + $shortcodes = ContainerWrapper::getInstance()->get(Shortcodes::class); $shortcodes->init(); $result = do_shortcode('[mailpoet_manage_subscription]'); expect($result)->contains('Subscription management form is only available to mailing lists subscribers.'); @@ -87,7 +88,7 @@ class ShortcodesTest extends \MailPoetTest { wp_set_current_user(0); expect((new WPFunctions)->isUserLoggedIn())->false(); - $shortcodes = new Shortcodes(); + $shortcodes = ContainerWrapper::getInstance()->get(Shortcodes::class); $shortcodes->init(); $result = do_shortcode('[mailpoet_manage_subscription]'); expect($result)->contains('Subscription management form is only available to mailing lists subscribers.'); @@ -102,7 +103,7 @@ class ShortcodesTest extends \MailPoetTest { $subscriber->wp_user_id = $wp_user->ID; $subscriber->save(); - $shortcodes = new Shortcodes(); + $shortcodes = ContainerWrapper::getInstance()->get(Shortcodes::class); $shortcodes->init(); $result = do_shortcode('[mailpoet_manage]'); expect($result)->contains('Manage your subscription'); @@ -113,7 +114,7 @@ class ShortcodesTest extends \MailPoetTest { expect((new WPFunctions)->isUserLoggedIn())->true(); expect(Subscriber::findOne($wp_user->data->user_email))->false(); - $shortcodes = new Shortcodes(); + $shortcodes = ContainerWrapper::getInstance()->get(Shortcodes::class); $shortcodes->init(); $result = do_shortcode('[mailpoet_manage]'); expect($result)->contains('Link to subscription management page is only available to mailing lists subscribers.'); @@ -123,7 +124,7 @@ class ShortcodesTest extends \MailPoetTest { wp_set_current_user(0); expect((new WPFunctions)->isUserLoggedIn())->false(); - $shortcodes = new Shortcodes(); + $shortcodes = ContainerWrapper::getInstance()->get(Shortcodes::class); $shortcodes->init(); $result = do_shortcode('[mailpoet_manage]'); expect($result)->contains('Link to subscription management page is only available to mailing lists subscribers.'); diff --git a/tests/integration/Router/Endpoints/SubscriptionTest.php b/tests/integration/Router/Endpoints/SubscriptionTest.php new file mode 100644 index 0000000000..f010939e13 --- /dev/null +++ b/tests/integration/Router/Endpoints/SubscriptionTest.php @@ -0,0 +1,48 @@ +data = []; + // instantiate class + $this->subscription = ContainerWrapper::getInstance()->get(Subscription::class); + } + + function testItDisplaysConfirmPage() { + $pages = Stub::make(Pages::class, [ + 'wp' => new WPFunctions, + 'confirm' => Expected::exactly(1), + ], $this); + $subscription = new Subscription($pages); + $subscription->confirm($this->data); + } + + function testItDisplaysManagePage() { + $pages = Stub::make(Pages::class, [ + 'wp' => new WPFunctions, + 'getManageLink' => Expected::exactly(1), + 'getManageContent' => Expected::exactly(1), + ], $this); + $subscription = new Subscription($pages); + $subscription->manage($this->data); + do_shortcode('[mailpoet_manage]'); + do_shortcode('[mailpoet_manage_subscription]'); + } + + function testItDisplaysUnsubscribePage() { + $pages = Stub::make(Pages::class, [ + 'wp' => new WPFunctions, + 'unsubscribe' => Expected::exactly(1), + ], $this); + $subscription = new Subscription($pages); + $subscription->unsubscribe($this->data); + } +} diff --git a/tests/integration/Subscription/PagesTest.php b/tests/integration/Subscription/PagesTest.php index 8bd6499047..2c7e81b95e 100644 --- a/tests/integration/Subscription/PagesTest.php +++ b/tests/integration/Subscription/PagesTest.php @@ -3,6 +3,7 @@ namespace MailPoet\Test\Subscription; use Codeception\Stub; use Codeception\Util\Fixtures; +use MailPoet\DI\ContainerWrapper; use MailPoet\Models\Newsletter; use MailPoet\Models\NewsletterOption; use MailPoet\Models\NewsletterOptionField; @@ -30,11 +31,12 @@ class PagesTest extends \MailPoetTest { expect($this->subscriber->getErrors())->false(); $this->test_data['email'] = $this->subscriber->email; $this->test_data['token'] = Subscriber::generateToken($this->subscriber->email); + $this->pages = ContainerWrapper::getInstance()->get(Pages::class); } function testItConfirmsSubscription() { $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 = $this->pages->init($action = false, $this->test_data, false, false, $new_subscriber_notification_sender); $subscription->confirm(); $confirmed_subscriber = Subscriber::findOne($this->subscriber->id); expect($confirmed_subscriber->status)->equals(Subscriber::STATUS_SUBSCRIBED); @@ -45,13 +47,13 @@ class PagesTest extends \MailPoetTest { $subscriber = $this->subscriber; $subscriber->status = Subscriber::STATUS_SUBSCRIBED; $subscriber->save(); - $subscription = new Pages($action = false, $this->test_data, false, false, $new_subscriber_notification_sender); + $subscription = $this->pages->init($action = false, $this->test_data, false, false, $new_subscriber_notification_sender); expect($subscription->confirm())->false(); } function testItSendsWelcomeNotificationUponConfirmingSubscription() { $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 = $this->pages->init($action = false, $this->test_data, false, false, $new_subscriber_notification_sender); // create segment $segment = Segment::create(); $segment->hydrate(['name' => 'List #1']); @@ -104,7 +106,7 @@ class PagesTest extends \MailPoetTest { } function testItUnsubscribes() { - $pages = new Pages($action = 'unsubscribe', $this->test_data); + $pages = $this->pages->init($action = 'unsubscribe', $this->test_data); $pages->unsubscribe(); $updated_subscriber = Subscriber::findOne($this->subscriber->id); expect($updated_subscriber->status)->equals(Subscriber::STATUS_UNSUBSCRIBED); @@ -112,7 +114,7 @@ class PagesTest extends \MailPoetTest { function testItDoesntUnsubscribeWhenPreviewing() { $this->test_data['preview'] = 1; - $pages = new Pages($action = 'unsubscribe', $this->test_data); + $pages = $this->pages->init($action = 'unsubscribe', $this->test_data); $pages->unsubscribe(); $updated_subscriber = Subscriber::findOne($this->subscriber->id); expect($updated_subscriber->status)->notEquals(Subscriber::STATUS_UNSUBSCRIBED);