From f96e65dc159b24acf90cb34f343c5175c68a4ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ja=CC=81n=20Mikla=CC=81s=CC=8C?= Date: Wed, 30 Jan 2019 13:49:32 +0100 Subject: [PATCH] Add integration test for limiting confirmation emails --- .../ConfirmationEmailMailerTest.php | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/integration/Subscribers/ConfirmationEmailMailerTest.php b/tests/integration/Subscribers/ConfirmationEmailMailerTest.php index 4e07528ab1..90cafb798f 100644 --- a/tests/integration/Subscribers/ConfirmationEmailMailerTest.php +++ b/tests/integration/Subscribers/ConfirmationEmailMailerTest.php @@ -8,6 +8,7 @@ use MailPoet\Mailer\Mailer; use MailPoet\Models\Segment; use MailPoet\Models\Subscriber; use MailPoet\Models\SubscriberSegment; +use MailPoet\WP\Functions as WPFunctions; class ConfirmationEmailMailerTest extends \MailPoetTest { @@ -68,6 +69,52 @@ class ConfirmationEmailMailerTest extends \MailPoetTest { expect($subscriber->getErrors()[0])->equals('send error'); } + function testItLimitsNumberOfConfirmationEmailsForNotLoggedInUser() { + wp_set_current_user(0); + expect((new WPFunctions)->isUserLoggedIn())->false(); + $subscriber = Subscriber::create(); + $subscriber->hydrate([ + 'first_name' => 'John', + 'last_name' => 'Mailer', + 'email' => 'john@mailpoet.com' + ]); + + $mailer = Stub::makeEmpty(Mailer::class, [ + 'send' => function() { + return true; + } + ], $this); + $sender = new ConfirmationEmailMailer($mailer); + + for($i = 0; $i < $sender::MAX_CONFIRMATION_EMAILS; $i++) { + expect($sender->sendConfirmationEmail($subscriber))->equals(true); + } + expect($sender->sendConfirmationEmail($subscriber))->equals(false); + } + + function testItDoesNotLimitNumberOfConfirmationEmailsForLoggedInUser() { + wp_set_current_user(1); + expect((new WPFunctions)->isUserLoggedIn())->true(); + $subscriber = Subscriber::create(); + $subscriber->hydrate([ + 'first_name' => 'John', + 'last_name' => 'Mailer', + 'email' => 'john@mailpoet.com' + ]); + + $mailer = Stub::makeEmpty(Mailer::class, [ + 'send' => function() { + return true; + } + ], $this); + $sender = new ConfirmationEmailMailer($mailer); + + for($i = 0; $i < $sender::MAX_CONFIRMATION_EMAILS; $i++) { + expect($sender->sendConfirmationEmail($subscriber))->equals(true); + } + expect($sender->sendConfirmationEmail($subscriber))->equals(true); + } + function _after() { \ORM::raw_execute('TRUNCATE ' . Subscriber::$_table); \ORM::raw_execute('TRUNCATE ' . Segment::$_table);