Files
piratepoet/tests/acceptance/SubscriptionCaptchaCest.php

62 lines
2.1 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 MailPoet\Subscription\Captcha;
use MailPoet\Test\DataFactories\Form;
use MailPoet\Test\DataFactories\Settings;
use MailPoet\Test\DataFactories\Subscriber;
class SubscriptionCaptchaCest {
/** @var Settings */
private $settings_factory;
/** @var string */
private $subscriber_email;
function _before(\AcceptanceTester $I) {
$this->subscriber_email = 'test-form@example.com';
$this->settings_factory = new Settings();
$this->settings_factory->withCaptchaType(Captcha::TYPE_BUILTIN);
$this->settings_factory
->withConfirmationEmailSubject()
->withConfirmationEmailBody()
->withConfirmationEmailEnabled();
$form_name = 'Subscription Acceptance Test Form';
$form_factory = new Form();
$form = $form_factory->withName($form_name)->create();
$subscriber_factory = new Subscriber();
$subscriber_factory->withEmail($this->subscriber_email)->withCountConfirmations(1)->create();
$I->cli('widget add mailpoet_form sidebar-1 2 --form=' . $form->id . ' --title="Subscribe to Our Newsletter" --allow-root');
}
function checkCaptchaPageExistsAfterSubscription(\AcceptanceTester $I) {
$I->wantTo('See the built-in captcha after subscribing using form widget');
$I->amOnPage('/');
$I->fillField('[data-automation-id="form_email"]', $this->subscriber_email);
$I->click('.mailpoet_submit');
$I->waitForText('Confirm youre not a robot');
$I->seeNoJSErrors();
}
function checkCaptchaPageIsNotShownToLoggedInUsers(\AcceptanceTester $I) {
$I->wantTo('check that captcha page is not shown to logged in users');
$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.');
$I->seeNoJSErrors();
}
function _after(\AcceptanceTester $I) {
$I->cli('widget reset sidebar-1 --allow-root');
$I->cli('db query "TRUNCATE TABLE mp_mailpoet_subscriber_ips" --allow-root');
$this->settings_factory->withCaptchaType(Captcha::TYPE_DISABLED);
}
}