Improve migration and tests
This commit is contained in:
committed by
M. Shull
parent
6608621ea8
commit
8da9a5f887
@ -52,7 +52,7 @@ class Settings extends APIEndpoint {
|
|||||||
}
|
}
|
||||||
$bridge = new Bridge();
|
$bridge = new Bridge();
|
||||||
$bridge->onSettingsSave($settings);
|
$bridge->onSettingsSave($settings);
|
||||||
if ($signup_confirmation != $this->settings->get('signup_confirmation.enabled')) {
|
if ($signup_confirmation !== $this->settings->get('signup_confirmation.enabled')) {
|
||||||
Form::updateSuccessMessages();
|
Form::updateSuccessMessages();
|
||||||
}
|
}
|
||||||
return $this->successResponse($this->settings->getAll());
|
return $this->successResponse($this->settings->getAll());
|
||||||
|
@ -134,7 +134,7 @@ class Populator {
|
|||||||
$this->createSourceForSubscribers();
|
$this->createSourceForSubscribers();
|
||||||
$this->updateNewsletterCategories();
|
$this->updateNewsletterCategories();
|
||||||
$this->scheduleInitialInactiveSubscribersCheck();
|
$this->scheduleInitialInactiveSubscribersCheck();
|
||||||
Form::updateSuccessMessages();
|
$this->updateFormsSuccessMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createMailPoetPage() {
|
private function createMailPoetPage() {
|
||||||
@ -526,4 +526,11 @@ class Populator {
|
|||||||
$task->scheduled_at = $datetime->addHour();
|
$task->scheduled_at = $datetime->addHour();
|
||||||
$task->save();
|
$task->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function updateFormsSuccessMessages() {
|
||||||
|
if (version_compare($this->settings->get('db_version', '3.23.2'), '3.23.1', '>')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Form::updateSuccessMessages();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,13 +16,13 @@ class Form extends Model {
|
|||||||
public static $_table = MP_FORMS_TABLE;
|
public static $_table = MP_FORMS_TABLE;
|
||||||
|
|
||||||
const MESSAGE_WHEN_CONFIRMATION_ENABLED = 'Check your inbox or spam folder to confirm your subscription.';
|
const MESSAGE_WHEN_CONFIRMATION_ENABLED = 'Check your inbox or spam folder to confirm your subscription.';
|
||||||
const MESSAGE_WHEN_CONFIRMATION_DISABLED = "You've been successfully subscribed to our newsletter!";
|
const MESSAGE_WHEN_CONFIRMATION_DISABLED = "You’ve been successfully subscribed to our newsletter!";
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->addValidations('name', array(
|
$this->addValidations('name', array(
|
||||||
'required' => WPFunctions::get()->__('Please specify a name.', 'mailpoet')
|
'required' => __('Please specify a name.', 'mailpoet')
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,12 +106,12 @@ class Form extends Model {
|
|||||||
return array(
|
return array(
|
||||||
array(
|
array(
|
||||||
'name' => 'all',
|
'name' => 'all',
|
||||||
'label' => WPFunctions::get()->__('All', 'mailpoet'),
|
'label' => __('All', 'mailpoet'),
|
||||||
'count' => Form::getPublished()->count()
|
'count' => Form::getPublished()->count()
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'name' => 'trash',
|
'name' => 'trash',
|
||||||
'label' => WPFunctions::get()->__('Trash', 'mailpoet'),
|
'label' => __('Trash', 'mailpoet'),
|
||||||
'count' => Form::getTrashed()->count()
|
'count' => Form::getTrashed()->count()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -127,9 +127,9 @@ class Form extends Model {
|
|||||||
static function getDefaultSuccessMessage() {
|
static function getDefaultSuccessMessage() {
|
||||||
$settings = new SettingsController;
|
$settings = new SettingsController;
|
||||||
if ($settings->get('signup_confirmation.enabled')) {
|
if ($settings->get('signup_confirmation.enabled')) {
|
||||||
return WPFunctions::get()->__(self::MESSAGE_WHEN_CONFIRMATION_ENABLED, 'mailpoet');
|
return __(self::MESSAGE_WHEN_CONFIRMATION_ENABLED, 'mailpoet');
|
||||||
}
|
}
|
||||||
return WPFunctions::get()->__(self::MESSAGE_WHEN_CONFIRMATION_DISABLED, 'mailpoet');
|
return __(self::MESSAGE_WHEN_CONFIRMATION_DISABLED, 'mailpoet');
|
||||||
}
|
}
|
||||||
|
|
||||||
static function updateSuccessMessages() {
|
static function updateSuccessMessages() {
|
||||||
@ -141,10 +141,11 @@ class Form extends Model {
|
|||||||
);
|
);
|
||||||
$forms = self::findMany();
|
$forms = self::findMany();
|
||||||
foreach ($forms as $form) {
|
foreach ($forms as $form) {
|
||||||
$data = $form->asArray();
|
$settings = $form->getSettings();
|
||||||
if (isset($data['settings']['success_message']) && $data['settings']['success_message'] === $wrong_message) {
|
if (isset($settings['success_message']) && $settings['success_message'] === $wrong_message) {
|
||||||
$data['settings']['success_message'] = $right_message;
|
$settings['success_message'] = $right_message;
|
||||||
self::createOrUpdate($data);
|
$form->set('settings', serialize($settings));
|
||||||
|
$form->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,4 +59,7 @@ class Form {
|
|||||||
return FormModel::createOrUpdate($this->data);
|
return FormModel::createOrUpdate($this->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withDefaultSuccessMessage() {
|
||||||
|
FormModel::updateSuccessMessages();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ namespace MailPoet\Test\DataFactories;
|
|||||||
|
|
||||||
use MailPoet\Mailer\Mailer;
|
use MailPoet\Mailer\Mailer;
|
||||||
use MailPoet\Settings\SettingsController;
|
use MailPoet\Settings\SettingsController;
|
||||||
use MailPoet\Models\Form as FormModel;
|
|
||||||
|
|
||||||
class Settings {
|
class Settings {
|
||||||
/** @var SettingsController */
|
/** @var SettingsController */
|
||||||
@ -33,7 +32,6 @@ class Settings {
|
|||||||
|
|
||||||
function withConfirmationEmailEnabled() {
|
function withConfirmationEmailEnabled() {
|
||||||
$this->settings->set('signup_confirmation.enabled', '1');
|
$this->settings->set('signup_confirmation.enabled', '1');
|
||||||
FormModel::updateSuccessMessages();
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +42,6 @@ class Settings {
|
|||||||
|
|
||||||
function withConfirmationEmailDisabled() {
|
function withConfirmationEmailDisabled() {
|
||||||
$this->settings->set('signup_confirmation.enabled', '');
|
$this->settings->set('signup_confirmation.enabled', '');
|
||||||
FormModel::updateSuccessMessages();
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,8 +4,10 @@ namespace MailPoet\Test\Acceptance;
|
|||||||
|
|
||||||
use Codeception\Util\Locator;
|
use Codeception\Util\Locator;
|
||||||
use MailPoet\Test\DataFactories\Settings;
|
use MailPoet\Test\DataFactories\Settings;
|
||||||
|
use MailPoet\Test\DataFactories\Form;
|
||||||
|
|
||||||
require_once __DIR__ . '/../DataFactories/Settings.php';
|
require_once __DIR__ . '/../DataFactories/Settings.php';
|
||||||
|
require_once __DIR__ . '/../DataFactories/Form.php';
|
||||||
|
|
||||||
class EditSignUpConfirmationEmailCest {
|
class EditSignUpConfirmationEmailCest {
|
||||||
|
|
||||||
@ -14,8 +16,10 @@ class EditSignUpConfirmationEmailCest {
|
|||||||
|
|
||||||
// make sure sign up confirmation is enabled
|
// make sure sign up confirmation is enabled
|
||||||
$settings = new Settings();
|
$settings = new Settings();
|
||||||
$settings
|
$settings->withConfirmationEmailEnabled();
|
||||||
->withConfirmationEmailEnabled();
|
|
||||||
|
$forms = new Form();
|
||||||
|
$forms->withDefaultSuccessMessage();
|
||||||
|
|
||||||
$I->login();
|
$I->login();
|
||||||
$I->amOnMailPoetPage('Settings');
|
$I->amOnMailPoetPage('Settings');
|
||||||
|
@ -37,6 +37,8 @@ class SubscribeToMultipleListsCest {
|
|||||||
->withConfirmationEmailBody()
|
->withConfirmationEmailBody()
|
||||||
->withConfirmationEmailSubject('Subscribe to multiple test subject');
|
->withConfirmationEmailSubject('Subscribe to multiple test subject');
|
||||||
|
|
||||||
|
$form_factory->withDefaultSuccessMessage();
|
||||||
|
|
||||||
//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
|
||||||
|
@ -5,7 +5,6 @@ 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;
|
use MailPoet\Test\DataFactories\Settings;
|
||||||
use MailPoet\Models\Form as FormModel;
|
|
||||||
|
|
||||||
require_once __DIR__ . '/../DataFactories/Settings.php';
|
require_once __DIR__ . '/../DataFactories/Settings.php';
|
||||||
require_once __DIR__ . '/../DataFactories/Form.php';
|
require_once __DIR__ . '/../DataFactories/Form.php';
|
||||||
@ -41,7 +40,7 @@ class SubscriptionFormCest {
|
|||||||
$I->amOnPage('/');
|
$I->amOnPage('/');
|
||||||
$I->fillField('[data-automation-id="form_email"]', $this->subscriber_email);
|
$I->fillField('[data-automation-id="form_email"]', $this->subscriber_email);
|
||||||
$I->click('.mailpoet_submit');
|
$I->click('.mailpoet_submit');
|
||||||
$I->waitForText(FormModel::MESSAGE_WHEN_CONFIRMATION_ENABLED, self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success');
|
$I->waitForText('Check your inbox or spam folder to confirm your subscription.', self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success');
|
||||||
$I->seeNoJSErrors();
|
$I->seeNoJSErrors();
|
||||||
|
|
||||||
$I->cli('widget reset sidebar-1 --allow-root');
|
$I->cli('widget reset sidebar-1 --allow-root');
|
||||||
@ -54,7 +53,7 @@ class SubscriptionFormCest {
|
|||||||
$I->fillField('[data-automation-id="form_email"]', $this->subscriber_email);
|
$I->fillField('[data-automation-id="form_email"]', $this->subscriber_email);
|
||||||
$I->scrollTo('.mailpoet_submit');
|
$I->scrollTo('.mailpoet_submit');
|
||||||
$I->click('.mailpoet_submit');
|
$I->click('.mailpoet_submit');
|
||||||
$I->waitForText(FormModel::MESSAGE_WHEN_CONFIRMATION_ENABLED, self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success');
|
$I->waitForText('Check your inbox or spam folder to confirm your subscription.', self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success');
|
||||||
$I->seeNoJSErrors();
|
$I->seeNoJSErrors();
|
||||||
$I->seeCurrentUrlEquals('/form-test/');
|
$I->seeCurrentUrlEquals('/form-test/');
|
||||||
}
|
}
|
||||||
@ -66,7 +65,7 @@ class SubscriptionFormCest {
|
|||||||
$I->switchToIframe('mailpoet_form_iframe');
|
$I->switchToIframe('mailpoet_form_iframe');
|
||||||
$I->fillField('[data-automation-id="form_email"]', $this->subscriber_email);
|
$I->fillField('[data-automation-id="form_email"]', $this->subscriber_email);
|
||||||
$I->click('.mailpoet_submit');
|
$I->click('.mailpoet_submit');
|
||||||
$I->waitForText(FormModel::MESSAGE_WHEN_CONFIRMATION_ENABLED, self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success');
|
$I->waitForText('Check your inbox or spam folder to confirm your subscription.', self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success');
|
||||||
$I->seeNoJSErrors();
|
$I->seeNoJSErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +103,7 @@ class SubscriptionFormCest {
|
|||||||
$I->switchToIframe('mailpoet_form_iframe');
|
$I->switchToIframe('mailpoet_form_iframe');
|
||||||
$I->fillField('[data-automation-id="form_email"]', $this->subscriber_email);
|
$I->fillField('[data-automation-id="form_email"]', $this->subscriber_email);
|
||||||
$I->click('.mailpoet_submit');
|
$I->click('.mailpoet_submit');
|
||||||
$I->waitForText(FormModel::MESSAGE_WHEN_CONFIRMATION_DISABLED, self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success');
|
$I->waitForText("You’ve been successfully subscribed to our newsletter!", self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success');
|
||||||
$I->seeNoJSErrors();
|
$I->seeNoJSErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user