From 0cb2ec60edaaf422808259e33d966649ae108bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Noco=C5=84?= Date: Thu, 19 Apr 2018 15:01:21 +0200 Subject: [PATCH] EZP-28224: Fix repository-forms tests (#235) --- composer.json | 2 +- features/Context/ContentEdit.php | 2 +- features/Context/FieldTypeFormContext.php | 86 ++++++++++--------- features/Context/UserRegistrationContext.php | 2 +- .../checkbox_fieldtype_edit_form.feature | 4 +- .../selection_fieldtype_edit_form.feature | 2 +- .../textline_fieldtype_edit_form.feature | 4 +- .../user_fieldtype_edit_form.feature | 4 +- .../Registration/user_registration.feature | 8 +- 9 files changed, 61 insertions(+), 53 deletions(-) diff --git a/composer.json b/composer.json index d01347824..f1a893267 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ }, "extra": { "_ezplatform_branch_for_behat_tests_comment_": "ezplatform branch to use to run Behat tests", - "_ezplatform_branch_for_behat_tests": "2.0", + "_ezplatform_branch_for_behat_tests": "2.1", "branch-alias": { "dev-master": "2.1.x-dev", "dev-tmp_ci_branch": "2.1.x-dev" diff --git a/features/Context/ContentEdit.php b/features/Context/ContentEdit.php index 541ec4186..d0d953cbf 100644 --- a/features/Context/ContentEdit.php +++ b/features/Context/ContentEdit.php @@ -140,7 +140,7 @@ public function iAmShownTheContentCreationForm() public function thereIsARelevantErrorMessageLinkedToTheInvalidField() { $selector = sprintf( - '#ezrepoforms_content_edit_fieldsData_%s div.has-error ul li', + '#ezrepoforms_content_edit_fieldsData_%s div ul li', self::$constrainedFieldIdentifier ); diff --git a/features/Context/FieldTypeFormContext.php b/features/Context/FieldTypeFormContext.php index e4e25b29b..16da1759c 100644 --- a/features/Context/FieldTypeFormContext.php +++ b/features/Context/FieldTypeFormContext.php @@ -7,7 +7,6 @@ use Behat\Behat\Context\SnippetAcceptingContext; use Behat\Behat\Hook\Scope\BeforeScenarioScope; use Behat\Gherkin\Node\TableNode; -use Behat\Mink\Element\NodeElement; use Behat\MinkExtension\Context\RawMinkContext; use eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionCreateStruct; use eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionUpdateStruct; @@ -69,13 +68,13 @@ public function iEditOrCreateContentOfThisType() } /** - * @Then /^the edit form should contain an identifiable widget for that field definition$/ + * @Then the edit form should contain an identifiable widget for :fieldTypeIdentifier field definition */ - public function theEditFormShouldContainAFieldsetNamedAfterTheFieldDefinition() + public function theEditFormShouldContainAFieldsetNamedAfterTheFieldDefinition($fieldTypeIdentifier) { $this->assertSession()->elementTextContains( 'css', - 'form[name="ezrepoforms_content_edit"] label', + sprintf('form[name="ezrepoforms_%s"] label', $this->getFieldTypeSelector($fieldTypeIdentifier)), 'Field' ); } @@ -101,43 +100,26 @@ public function itShouldContainAGivenTypeInputField($inputType) */ public function itShouldContainTheFollowingSetOfLabelsAndInputFieldsTypes(TableNode $table) { - $fieldsExpectations = $table->getColumnsHash(); - $inputNodeElements = $this->getSession()->getPage()->findAll( 'css', sprintf( - 'form[name="ezrepoforms_content_edit"] ' - . 'div#ezrepoforms_content_edit_fieldsData_%s_value ' - . 'input', + 'form[name="ezrepoforms_user_create"] #ezrepoforms_user_create_fieldsData_%s_value input', self::$fieldIdentifier ) ); - /** @var NodeElement $nodeElement */ - foreach ($inputNodeElements as $nodeElement) { - foreach ($fieldsExpectations as $expectationId => $fieldExpectation) { - if ($fieldExpectation['type'] === $nodeElement->getAttribute('type')) { - $inputId = $nodeElement->getAttribute('id'); - - $this->assertSession()->elementExists('css', "label[for=$inputId]"); - $this->assertSession()->elementTextContains( - 'css', - "label[for=$inputId]", - $fieldExpectation['label'] - ); - - unset($fieldsExpectations[$expectationId]); - reset($fieldsExpectations); - break; - } - } + $actualInputFields = []; + foreach ($inputNodeElements as $inputElement) { + $type = $inputElement->getAttribute('type'); + $inputId = $inputElement->getAttribute('id'); + $label = $this->getSession()->getPage()->find('css', sprintf('label[for=%s]', $inputId))->getText(); + + $actualInputFields[] = ['type' => $type, 'label' => $label]; } - Assertion::assertEmpty( - $fieldsExpectations, - 'The following input fields were not found:' . - implode(', ', array_map(function ($v) {return $v['label'];}, $fieldsExpectations)) - ); + foreach ($expectedInputFields = $table->getColumnsHash() as $inputField) { + Assertion::assertContains($inputField, $actualInputFields); + } } /** @@ -153,24 +135,32 @@ public function theFieldDefinitionIsMarkedAsRequired() } /** - * @Then /^the value input fields should be flagged as required$/ + * @Then the value input fields for :fieldIdentifier field should be flagged as required */ - public function theInputFieldsShouldBeFlaggedAsRequired() + public function theInputFieldsShouldBeFlaggedAsRequired($fieldTypeIdentifier) { $inputNodeElements = $this->getSession()->getPage()->findAll( 'css', sprintf( - 'input#ezrepoforms_content_edit_fieldsData_%s_value, ' - . 'div#ezrepoforms_content_edit_fieldsData_%s_value input', - self::$fieldIdentifier, + 'form[name="ezrepoforms_%1$s"] #ezrepoforms_%1$s_fieldsData_%2$s input', + $this->getFieldTypeSelector($fieldTypeIdentifier), self::$fieldIdentifier ) ); + Assertion::assertNotEmpty($inputNodeElements, 'The input field is not marked as required'); + + $exceptions = $this->getRequiredFieldTypeExceptions($fieldTypeIdentifier); + foreach ($inputNodeElements as $inputNodeElement) { + $inputId = $inputNodeElement->getAttribute('id'); + $label = $this->getSession()->getPage()->find('css', sprintf('label[for=%s]', $inputId))->getText(); + + $expectedState = array_key_exists($label, $exceptions) ? $exceptions[$label] : true; + Assertion::assertEquals( - 'required', - $inputNodeElement->getAttribute('required'), + $expectedState, + $inputNodeElement->hasAttribute('required'), sprintf( '%s input with id %s is not flagged as required', $inputNodeElement->getAttribute('type'), @@ -193,4 +183,22 @@ public function setFieldDefinitionOption($option, $value) new FieldDefinitionUpdateStruct(['fieldSettings' => [$option => $value]]) ); } + + private function getFieldTypeSelector(string $fieldTypeIdentifier): string + { + if ($fieldTypeIdentifier === 'user') { + return 'user_create'; + } + + return 'content_edit'; + } + + private function getRequiredFieldTypeExceptions(string $fieldTypeIdentifier): array + { + if ($fieldTypeIdentifier === 'user') { + return ['Enabled' => false]; + } + + return []; + } } diff --git a/features/Context/UserRegistrationContext.php b/features/Context/UserRegistrationContext.php index 644b0980c..96b2b7681 100644 --- a/features/Context/UserRegistrationContext.php +++ b/features/Context/UserRegistrationContext.php @@ -223,7 +223,7 @@ public function iFillInTheFormWithValidValues() */ public function iClickOnTheRegisterButton() { - $this->getSession()->getPage()->pressButton('ezrepoforms_user_register[publish]'); + $this->getSession()->getPage()->pressButton('ezrepoforms_user_register[register]'); $this->assertSession()->statusCodeEquals(200); } diff --git a/features/FieldTypeForm/checkbox_fieldtype_edit_form.feature b/features/FieldTypeForm/checkbox_fieldtype_edit_form.feature index e1492fd85..53d3fde39 100644 --- a/features/FieldTypeForm/checkbox_fieldtype_edit_form.feature +++ b/features/FieldTypeForm/checkbox_fieldtype_edit_form.feature @@ -8,10 +8,10 @@ Background: Scenario: The attributes of the field have a form representation When I view the edit form for this field - Then the edit form should contain an identifiable widget for that field definition + Then the edit form should contain an identifiable widget for ezboolean field definition And it should contain a checkbox input field Scenario: The input fields are flagged as required when the field definition is required Given the field definition is required When I view the edit form for this field - Then the value input fields should be flagged as required + Then the value input fields for ezboolean field should be flagged as required diff --git a/features/FieldTypeForm/selection_fieldtype_edit_form.feature b/features/FieldTypeForm/selection_fieldtype_edit_form.feature index 343028c85..1058f3eff 100644 --- a/features/FieldTypeForm/selection_fieldtype_edit_form.feature +++ b/features/FieldTypeForm/selection_fieldtype_edit_form.feature @@ -8,7 +8,7 @@ Background: Scenario: The attributes of the field have a form representation Given I view the edit form for this field - Then the edit form should contain an identifiable widget for that field definition + Then the edit form should contain an identifiable widget for ezselection field definition And it should contain a select field Scenario: The options added to a field definition have a form representation diff --git a/features/FieldTypeForm/textline_fieldtype_edit_form.feature b/features/FieldTypeForm/textline_fieldtype_edit_form.feature index e0b67f9b7..9a9b02246 100644 --- a/features/FieldTypeForm/textline_fieldtype_edit_form.feature +++ b/features/FieldTypeForm/textline_fieldtype_edit_form.feature @@ -8,10 +8,10 @@ Background: Scenario: The attributes of a textline field have a form representation When I view the edit form for this field - Then the edit form should contain an identifiable widget for that field definition + Then the edit form should contain an identifiable widget for textline field definition And it should contain a text input field Scenario: The input fields are flagged as required when the field definition is required Given the field definition is required When I view the edit form for this field - Then the value input fields should be flagged as required + Then the value input fields for textline field should be flagged as required diff --git a/features/FieldTypeForm/user_fieldtype_edit_form.feature b/features/FieldTypeForm/user_fieldtype_edit_form.feature index 8c248b4c8..28c1e1557 100644 --- a/features/FieldTypeForm/user_fieldtype_edit_form.feature +++ b/features/FieldTypeForm/user_fieldtype_edit_form.feature @@ -8,7 +8,7 @@ Background: Scenario: The attributes of a user field have a form representation When I view the edit form for this field - Then the edit form should contain an identifiable widget for that field definition + Then the edit form should contain an identifiable widget for user field definition And it should contain the following set of labels, and input fields of the following types: | label | type | | Username | text | @@ -19,4 +19,4 @@ Scenario: The attributes of a user field have a form representation Scenario: The input fields are flagged as required when the field definition is required Given the field definition is marked as required When I view the edit form for this field - Then the value input fields should be flagged as required + Then the value input fields for user field should be flagged as required diff --git a/features/User/Registration/user_registration.feature b/features/User/Registration/user_registration.feature index 3efaebae0..25b223299 100644 --- a/features/User/Registration/user_registration.feature +++ b/features/User/Registration/user_registration.feature @@ -50,11 +50,11 @@ Scenario: The user registration templates can be customized {% extends noLayout is defined and noLayout == true ? viewbaseLayout : pagelayout %} {% block content %} - {% import "EzSystemsRepositoryFormsBundle:Content:content_form.html.twig" as contentForms %} -
- {{ contentForms.display_form(form) }} -
+ {{ form_start(form) }} + {{- form_widget(form.fieldsData) -}} + {{ form_end(form) }} + {% endblock %} """ And the following template in "src/AppBundle/Resources/views/user/registration_confirmation.html.twig":