Improve migration and tests

This commit is contained in:
Amine Ben hammou
2019-04-10 15:47:31 +02:00
committed by M. Shull
parent 6608621ea8
commit 8da9a5f887
8 changed files with 35 additions and 22 deletions

View File

@ -52,7 +52,7 @@ class Settings extends APIEndpoint {
}
$bridge = new Bridge();
$bridge->onSettingsSave($settings);
if ($signup_confirmation != $this->settings->get('signup_confirmation.enabled')) {
if ($signup_confirmation !== $this->settings->get('signup_confirmation.enabled')) {
Form::updateSuccessMessages();
}
return $this->successResponse($this->settings->getAll());

View File

@ -134,7 +134,7 @@ class Populator {
$this->createSourceForSubscribers();
$this->updateNewsletterCategories();
$this->scheduleInitialInactiveSubscribersCheck();
Form::updateSuccessMessages();
$this->updateFormsSuccessMessages();
}
private function createMailPoetPage() {
@ -526,4 +526,11 @@ class Populator {
$task->scheduled_at = $datetime->addHour();
$task->save();
}
private function updateFormsSuccessMessages() {
if (version_compare($this->settings->get('db_version', '3.23.2'), '3.23.1', '>')) {
return;
}
Form::updateSuccessMessages();
}
}

View File

@ -16,13 +16,13 @@ class Form extends Model {
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_DISABLED = "You've been successfully subscribed to our newsletter!";
const MESSAGE_WHEN_CONFIRMATION_DISABLED = "Youve been successfully subscribed to our newsletter!";
function __construct() {
parent::__construct();
$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(
array(
'name' => 'all',
'label' => WPFunctions::get()->__('All', 'mailpoet'),
'label' => __('All', 'mailpoet'),
'count' => Form::getPublished()->count()
),
array(
'name' => 'trash',
'label' => WPFunctions::get()->__('Trash', 'mailpoet'),
'label' => __('Trash', 'mailpoet'),
'count' => Form::getTrashed()->count()
)
);
@ -127,9 +127,9 @@ class Form extends Model {
static function getDefaultSuccessMessage() {
$settings = new SettingsController;
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() {
@ -141,10 +141,11 @@ class Form extends Model {
);
$forms = self::findMany();
foreach ($forms as $form) {
$data = $form->asArray();
if (isset($data['settings']['success_message']) && $data['settings']['success_message'] === $wrong_message) {
$data['settings']['success_message'] = $right_message;
self::createOrUpdate($data);
$settings = $form->getSettings();
if (isset($settings['success_message']) && $settings['success_message'] === $wrong_message) {
$settings['success_message'] = $right_message;
$form->set('settings', serialize($settings));
$form->save();
}
}
}

View File

@ -59,4 +59,7 @@ class Form {
return FormModel::createOrUpdate($this->data);
}
public function withDefaultSuccessMessage() {
FormModel::updateSuccessMessages();
}
}

View File

@ -4,7 +4,6 @@ namespace MailPoet\Test\DataFactories;
use MailPoet\Mailer\Mailer;
use MailPoet\Settings\SettingsController;
use MailPoet\Models\Form as FormModel;
class Settings {
/** @var SettingsController */
@ -33,7 +32,6 @@ class Settings {
function withConfirmationEmailEnabled() {
$this->settings->set('signup_confirmation.enabled', '1');
FormModel::updateSuccessMessages();
return $this;
}
@ -44,7 +42,6 @@ class Settings {
function withConfirmationEmailDisabled() {
$this->settings->set('signup_confirmation.enabled', '');
FormModel::updateSuccessMessages();
return $this;
}

View File

@ -4,8 +4,10 @@ namespace MailPoet\Test\Acceptance;
use Codeception\Util\Locator;
use MailPoet\Test\DataFactories\Settings;
use MailPoet\Test\DataFactories\Form;
require_once __DIR__ . '/../DataFactories/Settings.php';
require_once __DIR__ . '/../DataFactories/Form.php';
class EditSignUpConfirmationEmailCest {
@ -14,8 +16,10 @@ class EditSignUpConfirmationEmailCest {
// make sure sign up confirmation is enabled
$settings = new Settings();
$settings
->withConfirmationEmailEnabled();
$settings->withConfirmationEmailEnabled();
$forms = new Form();
$forms->withDefaultSuccessMessage();
$I->login();
$I->amOnMailPoetPage('Settings');

View File

@ -37,6 +37,8 @@ class SubscribeToMultipleListsCest {
->withConfirmationEmailBody()
->withConfirmationEmailSubject('Subscribe to multiple test subject');
$form_factory->withDefaultSuccessMessage();
//Add this form to a widget
$I->createFormAndSubscribe($form);
//Subscribe via that form

View File

@ -5,7 +5,6 @@ namespace MailPoet\Test\Acceptance;
use Codeception\Util\Locator;
use MailPoet\Test\DataFactories\Form;
use MailPoet\Test\DataFactories\Settings;
use MailPoet\Models\Form as FormModel;
require_once __DIR__ . '/../DataFactories/Settings.php';
require_once __DIR__ . '/../DataFactories/Form.php';
@ -41,7 +40,7 @@ class SubscriptionFormCest {
$I->amOnPage('/');
$I->fillField('[data-automation-id="form_email"]', $this->subscriber_email);
$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->cli('widget reset sidebar-1 --allow-root');
@ -54,7 +53,7 @@ class SubscriptionFormCest {
$I->fillField('[data-automation-id="form_email"]', $this->subscriber_email);
$I->scrollTo('.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->seeCurrentUrlEquals('/form-test/');
}
@ -66,7 +65,7 @@ class SubscriptionFormCest {
$I->switchToIframe('mailpoet_form_iframe');
$I->fillField('[data-automation-id="form_email"]', $this->subscriber_email);
$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();
}
@ -104,7 +103,7 @@ class SubscriptionFormCest {
$I->switchToIframe('mailpoet_form_iframe');
$I->fillField('[data-automation-id="form_email"]', $this->subscriber_email);
$I->click('.mailpoet_submit');
$I->waitForText(FormModel::MESSAGE_WHEN_CONFIRMATION_DISABLED, self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success');
$I->waitForText("Youve been successfully subscribed to our newsletter!", self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success');
$I->seeNoJSErrors();
}