Files
piratepoet/tests/acceptance/SubscriptionFormCest.php
Ján Mikláš c547d348e0 Fix tests
[MAILPOET-2187]
2019-08-20 13:09:35 -04:00

111 lines
4.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace MailPoet\Test\Acceptance;
use Codeception\Util\Locator;
use MailPoet\Test\DataFactories\Form;
use MailPoet\Test\DataFactories\Settings;
class SubscriptionFormCest {
const CONFIRMATION_MESSAGE_TIMEOUT = 20;
/** @var string */
private $subscriber_email;
function __construct() {
$this->subscriber_email = 'test-form@example.com';
}
function _before() {
$settings = new Settings();
$settings
->withConfirmationEmailSubject()
->withConfirmationEmailBody()
->withConfirmationEmailEnabled();
}
function subscriptionFormWidget(\AcceptanceTester $I) {
$form_name = 'Subscription Acceptance Test Form';
$form_factory = new Form();
$form = $form_factory->withName($form_name)->create();
$I->wantTo('Subscribe using form widget');
$I->cli('widget add mailpoet_form sidebar-1 2 --form=' . $form->id . ' --title="Subscribe to Our Newsletter" --allow-root');
//login to avoid time limit for subscribing
$I->login();
$I->amOnPage('/');
$I->fillField('[data-automation-id="form_email"]', $this->subscriber_email);
$I->click('.mailpoet_submit');
$I->waitForText('Check your inbox or spam folder to confirm your subscription.', self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success');
$I->seeNoJSErrors();
}
function subscriptionFormShortcode(\AcceptanceTester $I) {
$I->wantTo('Subscribe using form shortcode');
$I->amOnPage('/form-test');
$I->fillField('[data-automation-id="form_email"]', $this->subscriber_email);
$I->scrollTo('.mailpoet_submit');
$I->click('.mailpoet_submit');
$I->waitForText('Check your inbox or spam folder to confirm your subscription.', self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success');
$I->seeNoJSErrors();
$I->seeCurrentUrlEquals('/form-test/');
}
function subscriptionFormIframe(\AcceptanceTester $I) {
$I->wantTo('Subscribe using iframe form');
$I->amOnPage('/form-test');
$I->switchToIframe('mailpoet_form_iframe');
$I->fillField('[data-automation-id="form_email"]', $this->subscriber_email);
$I->click('.mailpoet_submit');
$I->waitForText('Check your inbox or spam folder to confirm your subscription.', self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success');
$I->seeNoJSErrors();
}
/**
* @depends subscriptionFormWidget
*/
function subscriptionConfirmation(\AcceptanceTester $I) {
$I->amOnPage('/form-test');
$I->fillField('[data-automation-id="form_email"]', $this->subscriber_email);
$I->scrollTo('.mailpoet_submit');
$I->click('.mailpoet_submit');
$I->waitForText('Check your inbox or spam folder to confirm your subscription.', self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success');
$I->amOnMailboxAppPage();
$I->waitForElement(Locator::contains('span.subject', 'Confirm your subscription'));
$I->click(Locator::contains('span.subject', 'Confirm your subscription'));
$I->switchToIframe('preview-html');
$I->click('I confirm my subscription!');
$I->switchToNextTab();
$I->see('You have subscribed');
$I->seeNoJSErrors();
$I->amOnUrl(\AcceptanceTester::WP_URL);
$I->login();
$I->amOnMailpoetPage('Subscribers');
$I->waitForText($this->subscriber_email);
$I->see('Subscribed', Locator::contains('tr', $this->subscriber_email));
}
function subscriptionAfterDisablingConfirmation(\AcceptanceTester $I) {
$I->wantTo('Disable sign-up confirmation then subscribe and see a different message');
$I->login();
$I->amOnMailPoetPage('Settings');
$I->click('[data-automation-id="signup_settings_tab"]');
$I->waitForText('Enable sign-up confirmation');
$I->click('[data-automation-id="disable_signup_confirmation"]');
$I->acceptPopup();
$I->click('[data-automation-id="settings-submit-button"]');
$I->waitForText('Settings saved');
$I->amOnPage('/form-test');
$I->switchToIframe('mailpoet_form_iframe');
$I->fillField('[data-automation-id="form_email"]', $this->subscriber_email);
$I->click('.mailpoet_submit');
$I->waitForText("Youve been successfully subscribed to our newsletter!", self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success');
$I->seeNoJSErrors();
}
}