Skip to content

Commit

Permalink
Merge branch '2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Marek Nocon committed Apr 19, 2018
2 parents e193a88 + 0cb2ec6 commit 7e89228
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 53 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -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.2.x-dev",
"dev-tmp_ci_branch": "2.2.x-dev"
Expand Down
2 changes: 1 addition & 1 deletion features/Context/ContentEdit.php
Expand Up @@ -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
);

Expand Down
86 changes: 47 additions & 39 deletions features/Context/FieldTypeFormContext.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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'
);
}
Expand All @@ -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);
}
}

/**
Expand All @@ -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'),
Expand All @@ -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 [];
}
}
2 changes: 1 addition & 1 deletion features/Context/UserRegistrationContext.php
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions features/FieldTypeForm/checkbox_fieldtype_edit_form.feature
Expand Up @@ -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
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions features/FieldTypeForm/textline_fieldtype_edit_form.feature
Expand Up @@ -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
4 changes: 2 additions & 2 deletions features/FieldTypeForm/user_fieldtype_edit_form.feature
Expand Up @@ -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 |
Expand All @@ -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
8 changes: 4 additions & 4 deletions features/User/Registration/user_registration.feature
Expand Up @@ -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 %}
<section class="ez-content-edit">
{{ contentForms.display_form(form) }}
</section>
{{ form_start(form) }}
{{- form_widget(form.fieldsData) -}}
{{ form_end(form) }}
</section>
{% endblock %}
"""
And the following template in "src/AppBundle/Resources/views/user/registration_confirmation.html.twig":
Expand Down

0 comments on commit 7e89228

Please sign in to comment.