diff --git a/lib/Form/Block/Text.php b/lib/Form/Block/Text.php index 8305c9bef8..53bc11bf70 100644 --- a/lib/Form/Block/Text.php +++ b/lib/Form/Block/Text.php @@ -16,7 +16,10 @@ class Text { $automationId = ' '; if ($block['id'] === 'email') { $type = 'email'; - $automationId = 'data-automation-id="form_email" '; + } + + if (in_array($block['id'], ['email', 'last_name', 'first_name'], true)) { + $automationId = 'data-automation-id="form_' . $block['id'] . '" '; } $html = '
'; diff --git a/tests/DataFactories/Form.php b/tests/DataFactories/Form.php index ede4420eb7..abde4514f9 100644 --- a/tests/DataFactories/Form.php +++ b/tests/DataFactories/Form.php @@ -54,6 +54,14 @@ class Form { return $this; } + /** + * @return $this + */ + public function withDisplayBelowPosts() { + $this->data['settings']['place_form_bellow_all_posts'] = '1'; + return $this; + } + /** @return \MailPoet\Models\Form */ public function create() { return FormModel::createOrUpdate($this->data); diff --git a/tests/_support/AcceptanceTester.php b/tests/_support/AcceptanceTester.php index a989be4f60..95883d61cd 100644 --- a/tests/_support/AcceptanceTester.php +++ b/tests/_support/AcceptanceTester.php @@ -409,4 +409,14 @@ class AcceptanceTester extends \Codeception\Actor { public function cliToString(array $userCommand) { return $this->_cliToString($userCommand); } + + /** + * Creates post and returns its URL + */ + public function createPost(string $title, string $body): string { + $post = $this->cliToArray(['post', 'create', '--format=json', '--porcelain', '--post_status=publish', '--post_type=post', '--post_title="' . $title . '"', '--post_content="' . $body . '"']); + $postData = $this->cliToArray(['post', 'get', $post[0], '--format=json']); + $postData = json_decode($postData[0], true); + return $postData['guid']; + } } diff --git a/tests/acceptance/FormWithColumnsCest.php b/tests/acceptance/FormWithColumnsCest.php new file mode 100644 index 0000000000..8b74fed979 --- /dev/null +++ b/tests/acceptance/FormWithColumnsCest.php @@ -0,0 +1,69 @@ +withName($segmentName)->create(); + $formName = 'My fancy form with columns'; + $form = new Form(); + $form->withName($formName) + ->withSegments([$segment]) + ->withDisplayBelowPosts() + ->create(); + $i->wantTo('Add columns with firs and last name'); + $i->login(); + $i->amOnMailPoetPage('Forms'); + $i->waitForText($formName); + $i->clickItemRowActionByItemName($formName, 'Edit'); + $i->waitForElement('[data-automation-id="form_title_input"]'); + + $i->click('.block-list-appender button');// CLICK the big button that adds new blocks + $i->waitForElement('.block-editor-inserter__results .components-panel__body-toggle'); + $i->click('.block-editor-inserter__results .components-panel__body:nth-child(3) .components-panel__body-toggle'); // toggle layout + $i->click('.editor-block-list-item-columns'); // columns block + $i->waitForElement('.block-editor-block-variation-picker__variations'); + $i->click('.block-editor-block-variation-picker__variations li:first-child button'); + $i->waitForElement('.block-editor-inner-blocks'); + $i->click('.block-editor-inner-blocks .block-list-appender button'); // CLICK the big button in column that adds new blocks + $i->click('.block-editor-inserter__results .components-panel__body:nth-child(2) .components-panel__body-toggle'); // toggle fields + $i->click('.editor-block-list-item-mailpoet-form-first-name-input'); // add first name block to the editor + $i->click('.block-editor-inner-blocks .block-list-appender button');// CLICK the big button in column that adds new blocks + $i->waitForElement('.block-editor-inserter__results .components-panel__body-toggle'); + $i->click('.block-editor-inserter__results .components-panel__body:nth-child(2) .components-panel__body-toggle'); // toggle fields, get the second field, first one is now "Most Used" + $i->click('.editor-block-list-item-mailpoet-form-last-name-input'); // add last name block to the editor + $i->seeNoJSErrors(); + $i->click('[data-automation-id="form_save_button"]'); + $i->waitForText('Form saved', 10, '.automation-dismissible-notices'); + // Reload page and check data were saved + $i->reloadPage(); + $i->waitForElement('[data-automation-id="form_title_input"]'); + $i->seeElement('[data-automation-id="editor_first_name_input"]'); + $i->seeElement('[data-automation-id="editor_last_name_input"]'); + + // Go to post page + $postUrl = $i->createPost('Title', 'Content'); + $i->amOnUrl($postUrl); + + // Subscribe using the form + $subscriberEmail = "subscriber_columns@example.com"; + $subscriberFirstName = "subscriber_columns_first_name"; + $subscriberLastName = "subscriber_columns_last_name"; + $i->fillField('[data-automation-id="form_email"]', $subscriberEmail); + $i->fillField('[data-automation-id="form_first_name"]', $subscriberFirstName); + $i->fillField('[data-automation-id="form_last_name"]', $subscriberLastName); + $i->click('[data-automation-id="subscribe-submit-button"]'); + $i->waitForText('Check your inbox or spam folder to confirm your subscription'); + + // Check subscriber data were saved + $i->amOnMailpoetPage('Subscribers'); + $i->waitForText($subscriberEmail); + $i->waitForText($subscriberFirstName); + $i->waitForText($subscriberLastName); + } +}