From 447e01b0aa0e43b6a1175a5004d75cbe77c30008 Mon Sep 17 00:00:00 2001 From: Rostislav Wolny Date: Tue, 21 Jan 2020 09:54:46 +0100 Subject: [PATCH] Remove new form editor feature flag [MAILPOET-2549] --- lib/API/JSON/v1/Forms.php | 18 +-------- lib/AdminPages/Pages/FormEditor.php | 38 ++++++++----------- lib/Config/Menu.php | 17 +++------ lib/Config/Populator.php | 2 +- lib/Features/FeaturesController.php | 2 - lib/Form/Util/Styles.php | 32 ++-------------- tests/acceptance/FormEditorAddNamesCest.php | 2 - .../FormEditorCreateCustomFieldCest.php | 2 - .../FormEditorUpdateMandatoryFieldsCest.php | 2 - .../FormEditorUpdateNewFormCest.php | 2 - tests/integration/API/JSON/v1/FormsTest.php | 4 +- tests/integration/Config/MenuTest.php | 1 - tests/unit/Form/Util/StylesTest.php | 17 +-------- 13 files changed, 31 insertions(+), 108 deletions(-) diff --git a/lib/API/JSON/v1/Forms.php b/lib/API/JSON/v1/Forms.php index e5bf81b7ad..ea1d80ade8 100644 --- a/lib/API/JSON/v1/Forms.php +++ b/lib/API/JSON/v1/Forms.php @@ -5,7 +5,6 @@ namespace MailPoet\API\JSON\v1; use MailPoet\API\JSON\Endpoint as APIEndpoint; use MailPoet\API\JSON\Error as APIError; use MailPoet\Config\AccessControl; -use MailPoet\Features\FeaturesController; use MailPoet\Form\Renderer as FormRenderer; use MailPoet\Form\Util; use MailPoet\Listing; @@ -21,9 +20,6 @@ class Forms extends APIEndpoint { /** @var Listing\Handler */ private $listingHandler; - /** @var FeaturesController */ - private $featuresController; - /** @var Util\Styles */ private $formStylesUtils; @@ -34,12 +30,10 @@ class Forms extends APIEndpoint { public function __construct( Listing\BulkActionController $bulkAction, Listing\Handler $listingHandler, - FeaturesController $featuresController, Util\Styles $formStylesUtils ) { $this->bulkAction = $bulkAction; $this->listingHandler = $listingHandler; - $this->featuresController = $featuresController; $this->formStylesUtils = $formStylesUtils; } @@ -80,13 +74,9 @@ class Forms extends APIEndpoint { } public function create() { - $formName = WPFunctions::get()->__('New form', 'mailpoet'); - if ($this->featuresController->isSupported(FeaturesController::NEW_FORM_EDITOR)) { - $formName = ''; - } // create new form $formData = [ - 'name' => $formName, + 'name' => '', 'body' => [ [ 'id' => 'email', @@ -96,6 +86,7 @@ class Forms extends APIEndpoint { 'params' => [ 'label' => WPFunctions::get()->__('Email', 'mailpoet'), 'required' => true, + 'label_within' => true, ], ], [ @@ -115,11 +106,6 @@ class Forms extends APIEndpoint { 'segments_selected_by' => 'admin', ], ]; - - if ($this->featuresController->isSupported(FeaturesController::NEW_FORM_EDITOR)) { - $formData['body'][0]['params']['label_within'] = true; - } - return $this->save($formData); } diff --git a/lib/AdminPages/Pages/FormEditor.php b/lib/AdminPages/Pages/FormEditor.php index e55bd6648d..0d4b90f534 100644 --- a/lib/AdminPages/Pages/FormEditor.php +++ b/lib/AdminPages/Pages/FormEditor.php @@ -5,11 +5,9 @@ namespace MailPoet\AdminPages\Pages; use MailPoet\AdminPages\PageRenderer; use MailPoet\API\JSON\ResponseBuilders\CustomFieldsResponseBuilder; use MailPoet\CustomFields\CustomFieldsRepository; -use MailPoet\Features\FeaturesController; use MailPoet\Form\Block; use MailPoet\Form\Renderer as FormRenderer; use MailPoet\Form\Util\Export; -use MailPoet\Models\CustomField; use MailPoet\Models\Form; use MailPoet\Models\Segment; use MailPoet\Settings\Pages; @@ -18,9 +16,6 @@ class FormEditor { /** @var PageRenderer */ private $pageRenderer; - /** @var FeaturesController */ - private $featuresController; - /** @var CustomFieldsRepository */ private $customFieldsRepository; @@ -29,12 +24,10 @@ class FormEditor { public function __construct( PageRenderer $pageRenderer, - FeaturesController $featuresController, CustomFieldsRepository $customFieldsRepository, CustomFieldsResponseBuilder $customFieldsResponseBuilder ) { $this->pageRenderer = $pageRenderer; - $this->featuresController = $featuresController; $this->customFieldsRepository = $customFieldsRepository; $this->customFieldsResponseBuilder = $customFieldsResponseBuilder; } @@ -45,7 +38,9 @@ class FormEditor { if ($form instanceof Form) { $form = $form->asArray(); } - + $form['styles'] = FormRenderer::getStyles($form); + $customFields = $this->customFieldsRepository->findAll(); + $dateTypes = Block\Date::getDateTypes(); $data = [ 'form' => $form, 'form_exports' => [ @@ -56,25 +51,24 @@ class FormEditor { 'pages' => Pages::getAll(), 'segments' => Segment::getSegmentsWithSubscriberCount(), 'styles' => FormRenderer::getStyles($form), - 'date_types' => Block\Date::getDateTypes(), - 'date_formats' => Block\Date::getDateFormats(), - 'month_names' => Block\Date::getMonthNames(), - 'sub_menu' => 'mailpoet-forms', - ]; - - if ($this->featuresController->isSupported(FeaturesController::NEW_FORM_EDITOR)) { - $data['form']['styles'] = FormRenderer::getStyles($form); - $customFields = $this->customFieldsRepository->findAll(); - $data['custom_fields'] = $this->customFieldsResponseBuilder->buildBatch($customFields); - $data['date_types'] = array_map(function ($label, $value) { + 'date_types' => array_map(function ($label, $value) { return [ 'label' => $label, 'value' => $value, ]; - }, $data['date_types'], array_keys($data['date_types'])); - $this->pageRenderer->displayPage('form/editor.html', $data); - } else { + }, $dateTypes, array_keys($dateTypes)), + 'date_formats' => Block\Date::getDateFormats(), + 'month_names' => Block\Date::getMonthNames(), + 'sub_menu' => 'mailpoet-forms', + 'custom_fields' => $this->customFieldsResponseBuilder->buildBatch($customFields), + ]; + + if (isset($_GET['legacy']) && (int)$_GET['legacy']) { + $data['date_types'] = $dateTypes; $this->pageRenderer->displayPage('form/editor_legacy.html', $data); + } else { + $this->pageRenderer->displayPage('form/editor.html', $data); + } } } diff --git a/lib/Config/Menu.php b/lib/Config/Menu.php index 1d678dbd80..37301e1a2e 100644 --- a/lib/Config/Menu.php +++ b/lib/Config/Menu.php @@ -22,7 +22,6 @@ use MailPoet\AdminPages\Pages\Update; use MailPoet\AdminPages\Pages\WelcomeWizard; use MailPoet\AdminPages\Pages\WooCommerceListImport; use MailPoet\DI\ContainerWrapper; -use MailPoet\Features\FeaturesController; use MailPoet\Util\License\License; use MailPoet\WP\Functions as WPFunctions; @@ -44,20 +43,15 @@ class Menu { /** @var ContainerWrapper */ private $container; - /** @var FeaturesController */ - private $featuresController; - public function __construct( AccessControl $accessControl, WPFunctions $wp, ServicesChecker $servicesChecker, - FeaturesController $featuresController, ContainerWrapper $container ) { $this->accessControl = $accessControl; $this->wp = $wp; $this->servicesChecker = $servicesChecker; - $this->featuresController = $featuresController; $this->container = $container; } @@ -191,13 +185,12 @@ class Menu { ); // add body class for form editor page - if ($this->featuresController->isSupported(FeaturesController::NEW_FORM_EDITOR)) { - $this->wp->addAction('load-' . $formEditorPage, function() { - $this->wp->addAction('admin_body_class', function ($classes) { - return ltrim($classes . ' block-editor-page'); - }); + $this->wp->addAction('load-' . $formEditorPage, function() { + $this->wp->addAction('admin_body_class', function ($classes) { + return ltrim($classes . ' block-editor-page'); }); - } + }); + // Subscribers page $subscribersPage = $this->wp->addSubmenuPage( diff --git a/lib/Config/Populator.php b/lib/Config/Populator.php index af16726ffa..c504a776ef 100644 --- a/lib/Config/Populator.php +++ b/lib/Config/Populator.php @@ -355,7 +355,7 @@ class Populator { private function createDefaultForm($defaultSegment) { if (Form::count() === 0) { - $factory = new DefaultForm(new Styles($this->flagsController)); + $factory = new DefaultForm(new Styles()); if (!$defaultSegment) { $defaultSegment = Segment::where('type', 'default')->orderByAsc('id')->limit(1)->findOne(); } diff --git a/lib/Features/FeaturesController.php b/lib/Features/FeaturesController.php index 50ee83a2db..14ce3924b2 100644 --- a/lib/Features/FeaturesController.php +++ b/lib/Features/FeaturesController.php @@ -9,13 +9,11 @@ class FeaturesController { // Define features below in the following form: // const FEATURE_NAME_OF_FEATURE = 'name-of-feature'; const NEW_DEFAULT_LIST_NAME = 'new-default-list-name'; - const NEW_FORM_EDITOR = 'new-form-editor'; // Define feature defaults in the array below in the following form: // self::FEATURE_NAME_OF_FEATURE => true, private $defaults = [ self::NEW_DEFAULT_LIST_NAME => false, - self::NEW_FORM_EDITOR => false, ]; /** @var array */ diff --git a/lib/Form/Util/Styles.php b/lib/Form/Util/Styles.php index 3094e4baa7..8e97824b35 100644 --- a/lib/Form/Util/Styles.php +++ b/lib/Form/Util/Styles.php @@ -2,8 +2,6 @@ namespace MailPoet\Form\Util; -use MailPoet\DI\ContainerWrapper; -use MailPoet\Features\FeaturesController; use MailPoetVendor\Sabberworm\CSS\Parser as CSSParser; class Styles { @@ -28,7 +26,7 @@ class Styles { .mailpoet_list_label, .mailpoet_date_label { display:block; - [LABELS_FONT_WEIGHT_RULE] + font-weight: normal; } /* inputs */ @@ -44,7 +42,7 @@ class Styles { .mailpoet_text, .mailpoet_textarea { - [TEXT_INPUTS_WIDTH_RULE] + width: 100%; } .mailpoet_checkbox { @@ -81,32 +79,8 @@ class Styles { } EOL; - /** @var FeaturesController */ - private $featuresController; - - /** - * @param FeaturesController $featuresController - */ - public function __construct( - FeaturesController $featuresController = null - ) { - if ($featuresController === null) { - $featuresController = ContainerWrapper::getInstance()->get(FeaturesController::class); - } - $this->featuresController = $featuresController; - } - public function getDefaultStyles() { - if ($this->featuresController->isSupported(FeaturesController::NEW_FORM_EDITOR)) { - $textInputWidth = 'width: 100%;'; - $labelFontWeight = 'font-weight: normal;'; - } else { - $textInputWidth = 'width: 200px;'; - $labelFontWeight = 'font-weight: bold;'; - } - $styles = str_replace('[TEXT_INPUTS_WIDTH_RULE]', $textInputWidth, $this->defaultStyles); - $styles = str_replace('[LABELS_FONT_WEIGHT_RULE]', $labelFontWeight, $styles); - return $styles; + return $this->defaultStyles; } public function render($stylesheet, $prefix = '') { diff --git a/tests/acceptance/FormEditorAddNamesCest.php b/tests/acceptance/FormEditorAddNamesCest.php index c7615ee1aa..9d3c498dd7 100644 --- a/tests/acceptance/FormEditorAddNamesCest.php +++ b/tests/acceptance/FormEditorAddNamesCest.php @@ -16,8 +16,6 @@ class FormEditorAddNamesCest { $formName = 'My fancy form'; $form = new Form(); $form->withName($formName)->withSegments([$segment])->create(); - $features = new Features(); - $features->withFeatureEnabled(FeaturesController::NEW_FORM_EDITOR); $i->wantTo('Add first and last name to the editor'); $i->login(); $i->amOnMailPoetPage('Forms'); diff --git a/tests/acceptance/FormEditorCreateCustomFieldCest.php b/tests/acceptance/FormEditorCreateCustomFieldCest.php index 03ec1ed6b6..ccaa9f7cd7 100644 --- a/tests/acceptance/FormEditorCreateCustomFieldCest.php +++ b/tests/acceptance/FormEditorCreateCustomFieldCest.php @@ -16,8 +16,6 @@ class FormEditorCreateCustomFieldCest { $formName = 'My fancy form'; $form = new Form(); $form->withName($formName)->withSegments([$segment])->create(); - $features = new Features(); - $features->withFeatureEnabled(FeaturesController::NEW_FORM_EDITOR); $i->wantTo('Add first and last name to the editor'); $i->login(); $i->amOnMailPoetPage('Forms'); diff --git a/tests/acceptance/FormEditorUpdateMandatoryFieldsCest.php b/tests/acceptance/FormEditorUpdateMandatoryFieldsCest.php index b1bcd6b489..423aa77ae5 100644 --- a/tests/acceptance/FormEditorUpdateMandatoryFieldsCest.php +++ b/tests/acceptance/FormEditorUpdateMandatoryFieldsCest.php @@ -9,8 +9,6 @@ use MailPoet\Test\DataFactories\Segment; class FormEditorUpdateMandatoryFieldsCest { public function updateEmailAndSubmit(\AcceptanceTester $i) { - $features = new Features(); - $features->withFeatureEnabled(FeaturesController::NEW_FORM_EDITOR); $segmentFactory = new Segment(); $formName = 'Mandatory fields test'; $formFactory = new Form(); diff --git a/tests/acceptance/FormEditorUpdateNewFormCest.php b/tests/acceptance/FormEditorUpdateNewFormCest.php index ec4b1a8127..aacea85388 100644 --- a/tests/acceptance/FormEditorUpdateNewFormCest.php +++ b/tests/acceptance/FormEditorUpdateNewFormCest.php @@ -11,8 +11,6 @@ class FormEditorUpdateNewFormCest { $segmentFactory = new Segment(); $segmentName = 'Fancy List'; $segmentFactory->withName($segmentName)->create(); - $features = new Features(); - $features->withFeatureEnabled(FeaturesController::NEW_FORM_EDITOR); $i->wantTo('Create and update form'); $i->login(); $i->amOnMailPoetPage('Forms'); diff --git a/tests/integration/API/JSON/v1/FormsTest.php b/tests/integration/API/JSON/v1/FormsTest.php index d6d31dd83a..57f495fb1a 100644 --- a/tests/integration/API/JSON/v1/FormsTest.php +++ b/tests/integration/API/JSON/v1/FormsTest.php @@ -63,7 +63,7 @@ class FormsTest extends \MailPoetTest { expect($response->data)->equals( Form::findOne($response->data['id'])->asArray() ); - expect($response->data['name'])->equals('New form'); + expect($response->data['name'])->equals(''); } public function testItCanSaveAForm() { @@ -82,7 +82,7 @@ class FormsTest extends \MailPoetTest { $response = $this->endpoint->create(); expect($response->status)->equals(APIResponse::STATUS_OK); expect($response->data)->equals( - Form::where('name', 'New form')->findOne()->asArray() + Form::where('id', $response->data['id'])->findOne()->asArray() ); $response = $this->endpoint->previewEditor($response->data); diff --git a/tests/integration/Config/MenuTest.php b/tests/integration/Config/MenuTest.php index 7b370dd497..7f98edbab8 100644 --- a/tests/integration/Config/MenuTest.php +++ b/tests/integration/Config/MenuTest.php @@ -90,7 +90,6 @@ class MenuTest extends \MailPoetTest { new AccessControl(), $wp, new ServicesChecker, - new FeaturesController(new FeatureFlagsRepository(ContainerWrapper::getInstance()->get(EntityManager::class))), ContainerWrapper::getInstance() ); } diff --git a/tests/unit/Form/Util/StylesTest.php b/tests/unit/Form/Util/StylesTest.php index 098a25d3b3..e9248c5cc3 100644 --- a/tests/unit/Form/Util/StylesTest.php +++ b/tests/unit/Form/Util/StylesTest.php @@ -2,25 +2,12 @@ namespace MailPoet\Test\Form\Util; -use MailPoet\Features\FeaturesController; use MailPoet\Form\Util\Styles; class StylesTest extends \MailPoetUnitTest { - /** @var FeaturesController&\PHPUnit_Framework_MockObject_MockObject */ - private $featuresController; - - public function _before() { - parent::_before(); - $this->featuresController = $this->createMock(FeaturesController::class); - $this->featuresController - ->expects($this->any()) - ->method('isSupported') - ->willReturn(false); - } - public function testItSetsDefaultCSSStyles() { - $styles = new Styles($this->featuresController); + $styles = new Styles(); expect($styles->getDefaultStyles())->notEmpty(); } @@ -29,7 +16,7 @@ class StylesTest extends \MailPoetUnitTest { /* some comment */ input[name=first_name] , input.some_class, .some_class { color: red ; background: blue; } .another_style { fonT-siZe: 20px } '; - $styleProcesser = new Styles($this->featuresController); + $styleProcesser = new Styles(); $extractedAndPrefixedStyles = $styleProcesser->render($stylesheet, $prefix = 'mailpoet'); // 1. comments should be stripped // 2. each selector should be refixed