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->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());
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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 = "You’ve 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,4 +59,7 @@ class Form {
|
||||
return FormModel::createOrUpdate($this->data);
|
||||
}
|
||||
|
||||
public function withDefaultSuccessMessage() {
|
||||
FormModel::updateSuccessMessages();
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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');
|
||||
|
@ -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
|
||||
|
@ -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("You’ve been successfully subscribed to our newsletter!", self::CONFIRMATION_MESSAGE_TIMEOUT, '.mailpoet_validate_success');
|
||||
$I->seeNoJSErrors();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user