Create a data factory for settings
[MAILPOET-1665]
This commit is contained in:
committed by
Rostislav Wolny
parent
a0a5d2b76e
commit
52cc6d5604
39
tests/DataFactories/Settings.php
Normal file
39
tests/DataFactories/Settings.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MailPoet\Test\DataFactories;
|
||||||
|
|
||||||
|
use MailPoet\Models\Setting;
|
||||||
|
|
||||||
|
class Settings {
|
||||||
|
|
||||||
|
function withConfirmationEmailSubject($subject = null) {
|
||||||
|
if($subject === null) {
|
||||||
|
$subject = sprintf('Confirm your subscription to %1$s', get_option('blogname'));
|
||||||
|
}
|
||||||
|
Setting::setValue('signup_confirmation.subject', $subject);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
function withConfirmationEmailBody($body = null) {
|
||||||
|
if($body === null) {
|
||||||
|
$body = "Hello,\n\nWelcome to our newsletter!\n\nPlease confirm your subscription to the list(s): [lists_to_confirm] by clicking the link below: \n\n[activation_link]Click here to confirm your subscription.[/activation_link]\n\nThank you,\n\nThe Team";
|
||||||
|
}
|
||||||
|
Setting::setValue('signup_confirmation.body', $body);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
function withConfirmationEmailEnabled() {
|
||||||
|
Setting::setValue('signup_confirmation.enabled', '1');
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
function withConfirmationEmailDisabled() {
|
||||||
|
Setting::setValue('signup_confirmation.enabled', '');
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
function withTrackingDisabled() {
|
||||||
|
Setting::setValue('tracking.enabled', false);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
@@ -3,21 +3,25 @@
|
|||||||
namespace MailPoet\Test\Acceptance;
|
namespace MailPoet\Test\Acceptance;
|
||||||
|
|
||||||
use Codeception\Util\Locator;
|
use Codeception\Util\Locator;
|
||||||
|
use MailPoet\Test\DataFactories\Settings;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../DataFactories/Settings.php';
|
||||||
|
|
||||||
class EditSignUpConfirmationEmailCest {
|
class EditSignUpConfirmationEmailCest {
|
||||||
|
|
||||||
function edit(\AcceptanceTester $I) {
|
function edit(\AcceptanceTester $I) {
|
||||||
$I->wantTo('Edit sign up confirmation email');
|
$I->wantTo('Edit sign up confirmation email');
|
||||||
|
|
||||||
|
// make sure sign up confirmation is enabled
|
||||||
|
$settings = new Settings();
|
||||||
|
$settings
|
||||||
|
->withConfirmationEmailEnabled();
|
||||||
|
|
||||||
$I->login();
|
$I->login();
|
||||||
$I->amOnMailPoetPage('Settings');
|
$I->amOnMailPoetPage('Settings');
|
||||||
$I->click('[data-automation-id="signup_settings_tab"]');
|
$I->click('[data-automation-id="signup_settings_tab"]');
|
||||||
$I->waitForText('Enable sign-up confirmation');
|
$I->waitForText('Enable sign-up confirmation');
|
||||||
|
|
||||||
// make sure sign up confirmation is enabled
|
|
||||||
$I->click('[data-automation-id="enable_signup_confirmation"]');
|
|
||||||
$I->acceptPopup();
|
|
||||||
|
|
||||||
// edit confirmation email
|
// edit confirmation email
|
||||||
$I->fillField('[data-automation-id="signup_confirmation_email_from_name"]', 'Confirmation Test From');
|
$I->fillField('[data-automation-id="signup_confirmation_email_from_name"]', 'Confirmation Test From');
|
||||||
$I->fillField('[data-automation-id="signup_confirmation_email_from_email"]', 'from-confirmation-test@example.com');
|
$I->fillField('[data-automation-id="signup_confirmation_email_from_email"]', 'from-confirmation-test@example.com');
|
||||||
@@ -41,12 +45,5 @@ class EditSignUpConfirmationEmailCest {
|
|||||||
|
|
||||||
function _after(\AcceptanceTester $I) {
|
function _after(\AcceptanceTester $I) {
|
||||||
$I->cli('widget reset sidebar-1 --allow-root');
|
$I->cli('widget reset sidebar-1 --allow-root');
|
||||||
$I->amOnUrl(\AcceptanceTester::WP_URL);
|
|
||||||
$I->amOnMailPoetPage('Settings');
|
|
||||||
$I->click('[data-automation-id="signup_settings_tab"]');
|
|
||||||
$I->waitForText('Enable sign-up confirmation');
|
|
||||||
$I->fillField('[data-automation-id="signup_confirmation_email_subject"]', sprintf('Confirm your subscription to %1$s', get_option('blogname')));
|
|
||||||
$I->fillField('[data-automation-id="signup_confirmation_email_body"]', "Hello,\n\nWelcome to our newsletter!\n\nPlease confirm your subscription to the list(s): [lists_to_confirm] by clicking the link below: \n\n[activation_link]Click here to confirm your subscription.[/activation_link]\n\nThank you,\n\nThe Team");
|
|
||||||
$I->click('[data-automation-id="settings-submit-button"]');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,39 +3,40 @@
|
|||||||
namespace MailPoet\Test\Acceptance;
|
namespace MailPoet\Test\Acceptance;
|
||||||
|
|
||||||
use AcceptanceTester;
|
use AcceptanceTester;
|
||||||
use Codeception\Util\Locator;
|
use MailPoet\Test\DataFactories\Settings;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../DataFactories/Settings.php';
|
||||||
|
|
||||||
class EnableAndDisableSignupConfirmationCest {
|
class EnableAndDisableSignupConfirmationCest {
|
||||||
|
|
||||||
function removeAllEmails(AcceptanceTester $I) {
|
|
||||||
// Remove all mails, because when there is more mails than paging allows it causes
|
|
||||||
// problems with counting ones, which would be moved to other page after adding more mails
|
|
||||||
$I->amOnMailboxAppPage();
|
|
||||||
$I->waitForElement(Locator::contains('a', 'Delete all messages'), 10);
|
|
||||||
$I->click(Locator::contains('a', 'Delete all messages'));
|
|
||||||
$I->waitForElement('.modal-footer');
|
|
||||||
$I->wait(2); // Wait for modal fade-in animation to finish
|
|
||||||
$I->click(Locator::contains('.btn', 'Delete all messages'));
|
|
||||||
$I->waitForElementNotVisible('.modal');
|
|
||||||
}
|
|
||||||
|
|
||||||
function disableSignupConfirmation(AcceptanceTester $I) {
|
function disableSignupConfirmation(AcceptanceTester $I) {
|
||||||
|
$settings = new Settings();
|
||||||
|
$settings
|
||||||
|
->withConfirmationEmailEnabled()
|
||||||
|
->withConfirmationEmailSubject('Disable signup confirmation subject');
|
||||||
$I->wantTo('Disable signup confirmation');
|
$I->wantTo('Disable signup confirmation');
|
||||||
$I->login();
|
$I->login();
|
||||||
$this->setSignupConfirmationSetting($I, $enabled = false);
|
$this->setSignupConfirmationSetting($I, $enabled = false);
|
||||||
$confirmation_emails_count = $this->countConfirmationEmails($I);
|
|
||||||
$I->createFormAndSubscribe();
|
$I->createFormAndSubscribe();
|
||||||
$this->seeConfirmationEmailsCountIs($I, $confirmation_emails_count);
|
$I->amOnUrl(\AcceptanceTester::MAIL_URL);
|
||||||
$I->cli('widget reset sidebar-1 --allow-root');
|
$I->dontSee('Disable signup confirmation subject');
|
||||||
}
|
}
|
||||||
|
|
||||||
function enableSignupConfirmation(AcceptanceTester $I) {
|
function enableSignupConfirmation(AcceptanceTester $I) {
|
||||||
|
$settings = new Settings();
|
||||||
|
$settings
|
||||||
|
->withConfirmationEmailDisabled()
|
||||||
|
->withConfirmationEmailSubject('Enable signup confirmation subject');
|
||||||
$I->wantTo('Enable signup confirmation');
|
$I->wantTo('Enable signup confirmation');
|
||||||
$I->login();
|
$I->login();
|
||||||
$this->setSignupConfirmationSetting($I, $enabled = true);
|
$this->setSignupConfirmationSetting($I, $enabled = true);
|
||||||
$confirmation_emails_count = $this->countConfirmationEmails($I);
|
|
||||||
$I->createFormAndSubscribe();
|
$I->createFormAndSubscribe();
|
||||||
$this->seeConfirmationEmailsCountIs($I, $confirmation_emails_count + 1);
|
$I->amOnUrl(\AcceptanceTester::MAIL_URL);
|
||||||
|
$I->waitForText('Enable signup confirmation subject');
|
||||||
|
$I->see('Enable signup confirmation subject');
|
||||||
|
}
|
||||||
|
|
||||||
|
function _after(AcceptanceTester $I) {
|
||||||
$I->cli('widget reset sidebar-1 --allow-root');
|
$I->cli('widget reset sidebar-1 --allow-root');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,15 +51,4 @@ class EnableAndDisableSignupConfirmationCest {
|
|||||||
$I->acceptPopup();
|
$I->acceptPopup();
|
||||||
$I->click('[data-automation-id="settings-submit-button"]');
|
$I->click('[data-automation-id="settings-submit-button"]');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function countConfirmationEmails(AcceptanceTester $I) {
|
|
||||||
$I->amOnMailboxAppPage();
|
|
||||||
$confirmation_emails = $I->grabMultiple(Locator::contains('span.subject', 'Confirm your subscription'));
|
|
||||||
return count($confirmation_emails);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function seeConfirmationEmailsCountIs(AcceptanceTester $I, $n) {
|
|
||||||
$I->amOnMailboxAppPage();
|
|
||||||
$I->seeNumberOfElements(Locator::contains('span.subject', 'Confirm your subscription'), $n);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -3,6 +3,9 @@
|
|||||||
namespace MailPoet\Test\Acceptance;
|
namespace MailPoet\Test\Acceptance;
|
||||||
|
|
||||||
use Codeception\Util\Locator;
|
use Codeception\Util\Locator;
|
||||||
|
use MailPoet\Test\DataFactories\Settings;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../DataFactories/Settings.php';
|
||||||
|
|
||||||
class ManageSubscriptionLinkCest {
|
class ManageSubscriptionLinkCest {
|
||||||
|
|
||||||
@@ -10,6 +13,11 @@ class ManageSubscriptionLinkCest {
|
|||||||
$this->newsletter_title = 'Subscription links Email ' . \MailPoet\Util\Security::generateRandomString();
|
$this->newsletter_title = 'Subscription links Email ' . \MailPoet\Util\Security::generateRandomString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _before() {
|
||||||
|
$settings = new Settings();
|
||||||
|
$settings->withConfirmationEmailEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
function sendEmail(\AcceptanceTester $I) {
|
function sendEmail(\AcceptanceTester $I) {
|
||||||
$I->wantTo('Create and send new email to WordPress Users list');
|
$I->wantTo('Create and send new email to WordPress Users list');
|
||||||
|
|
||||||
|
@@ -5,19 +5,24 @@ namespace MailPoet\Test\Acceptance;
|
|||||||
use Codeception\Util\Locator;
|
use Codeception\Util\Locator;
|
||||||
use MailPoet\Models\ScheduledTask;
|
use MailPoet\Models\ScheduledTask;
|
||||||
use MailPoet\Models\SendingQueue;
|
use MailPoet\Models\SendingQueue;
|
||||||
use MailPoet\Models\Setting;
|
|
||||||
use MailPoet\Test\DataFactories\Newsletter;
|
use MailPoet\Test\DataFactories\Newsletter;
|
||||||
use MailPoet\Test\DataFactories\Segment;
|
use MailPoet\Test\DataFactories\Segment;
|
||||||
use MailPoet\Test\DataFactories\Subscriber;
|
use MailPoet\Test\DataFactories\Subscriber;
|
||||||
|
use MailPoet\Test\DataFactories\Settings;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../DataFactories/Settings.php';
|
||||||
require_once __DIR__ . '/../DataFactories/Newsletter.php';
|
require_once __DIR__ . '/../DataFactories/Newsletter.php';
|
||||||
require_once __DIR__ . '/../DataFactories/Segment.php';
|
require_once __DIR__ . '/../DataFactories/Segment.php';
|
||||||
require_once __DIR__ . '/../DataFactories/Subscriber.php';
|
require_once __DIR__ . '/../DataFactories/Subscriber.php';
|
||||||
|
|
||||||
class ReceivePostNotificationCest {
|
class ReceivePostNotificationCest {
|
||||||
|
|
||||||
|
function _before() {
|
||||||
|
$settings = new Settings();
|
||||||
|
$settings->withTrackingDisabled();
|
||||||
|
}
|
||||||
|
|
||||||
function receivePostNotification(\AcceptanceTester $I) {
|
function receivePostNotification(\AcceptanceTester $I) {
|
||||||
Setting::setValue('tracking.enabled', false); // tracking makes this test very slow for some reason
|
|
||||||
$I->wantTo('Receive a post notification email');
|
$I->wantTo('Receive a post notification email');
|
||||||
$newsletter_subject = 'Post Notification Receive Test';
|
$newsletter_subject = 'Post Notification Receive Test';
|
||||||
$post_title = 'A post ' . \MailPoet\Util\Security::generateRandomString();
|
$post_title = 'A post ' . \MailPoet\Util\Security::generateRandomString();
|
||||||
|
@@ -5,16 +5,21 @@ namespace MailPoet\Test\Acceptance;
|
|||||||
use Codeception\Util\Locator;
|
use Codeception\Util\Locator;
|
||||||
use MailPoet\Test\DataFactories\Form;
|
use MailPoet\Test\DataFactories\Form;
|
||||||
use MailPoet\Test\DataFactories\Segment;
|
use MailPoet\Test\DataFactories\Segment;
|
||||||
|
use MailPoet\Test\DataFactories\Settings;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../DataFactories/Settings.php';
|
||||||
require_once __DIR__ . '/../DataFactories/Form.php';
|
require_once __DIR__ . '/../DataFactories/Form.php';
|
||||||
require_once __DIR__ . '/../DataFactories/Segment.php';
|
require_once __DIR__ . '/../DataFactories/Segment.php';
|
||||||
|
|
||||||
class SubscribeToMultipleListsCest {
|
class SubscribeToMultipleListsCest {
|
||||||
const CONFIRMATION_MESSAGE_TIMEOUT = 20;
|
const CONFIRMATION_MESSAGE_TIMEOUT = 20;
|
||||||
|
|
||||||
private $subscriber_email;
|
private $subscriber_email;
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
$this->subscriber_email = 'multiple-test-form@example.com';
|
$this->subscriber_email = 'multiple-test-form@example.com';
|
||||||
}
|
}
|
||||||
|
|
||||||
function subsrcibeToMultipleLists(\AcceptanceTester $I) {
|
function subsrcibeToMultipleLists(\AcceptanceTester $I) {
|
||||||
//Step one - create form with three lists
|
//Step one - create form with three lists
|
||||||
$segment_factory = new Segment();
|
$segment_factory = new Segment();
|
||||||
@@ -27,11 +32,18 @@ class SubscribeToMultipleListsCest {
|
|||||||
$form_name = 'Multiple Lists Form';
|
$form_name = 'Multiple Lists Form';
|
||||||
$form_factory = new Form();
|
$form_factory = new Form();
|
||||||
$form = $form_factory->withName($form_name)->withSegments([$segment1, $segment2, $segment3])->create();
|
$form = $form_factory->withName($form_name)->withSegments([$segment1, $segment2, $segment3])->create();
|
||||||
|
|
||||||
|
$settings = new Settings();
|
||||||
|
$settings
|
||||||
|
->withConfirmationEmailEnabled()
|
||||||
|
->withConfirmationEmailBody()
|
||||||
|
->withConfirmationEmailSubject('Subscribe to multiple test subject');
|
||||||
|
|
||||||
//Add this form to a widget
|
//Add this form to a widget
|
||||||
$I->createFormAndSubscribe($form);
|
$I->createFormAndSubscribe($form);
|
||||||
//Subscribe via that form
|
//Subscribe via that form
|
||||||
$I->amOnMailboxAppPage();
|
$I->amOnMailboxAppPage();
|
||||||
$I->click(Locator::contains('span.subject', 'Confirm your subscription'));
|
$I->click(Locator::contains('span.subject', 'Subscribe to multiple test subject'));
|
||||||
$I->switchToIframe('preview-html');
|
$I->switchToIframe('preview-html');
|
||||||
$I->click('Click here to confirm your subscription');
|
$I->click('Click here to confirm your subscription');
|
||||||
$I->switchToNextTab();
|
$I->switchToNextTab();
|
||||||
|
@@ -4,7 +4,9 @@ namespace MailPoet\Test\Acceptance;
|
|||||||
|
|
||||||
use Codeception\Util\Locator;
|
use Codeception\Util\Locator;
|
||||||
use MailPoet\Test\DataFactories\Form;
|
use MailPoet\Test\DataFactories\Form;
|
||||||
|
use MailPoet\Test\DataFactories\Settings;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../DataFactories/Settings.php';
|
||||||
require_once __DIR__ . '/../DataFactories/Form.php';
|
require_once __DIR__ . '/../DataFactories/Form.php';
|
||||||
|
|
||||||
class SubscriptionFormCest {
|
class SubscriptionFormCest {
|
||||||
@@ -18,6 +20,13 @@ class SubscriptionFormCest {
|
|||||||
$this->subscriber_email = 'test-form@example.com';
|
$this->subscriber_email = 'test-form@example.com';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _before() {
|
||||||
|
$settings = new Settings();
|
||||||
|
$settings
|
||||||
|
->withConfirmationEmailSubject()
|
||||||
|
->withConfirmationEmailEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
function subscriptionFormWidget(\AcceptanceTester $I) {
|
function subscriptionFormWidget(\AcceptanceTester $I) {
|
||||||
$form_name = 'Subscription Acceptance Test Form';
|
$form_name = 'Subscription Acceptance Test Form';
|
||||||
$form_factory = new Form();
|
$form_factory = new Form();
|
||||||
|
Reference in New Issue
Block a user