forked from ezsystems/repository-forms
/
SelectionFieldTypeFormContext.php
116 lines (106 loc) · 3.4 KB
/
SelectionFieldTypeFormContext.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace EzSystems\RepositoryForms\Features\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\MinkExtension\Context\RawMinkContext;
use PHPUnit\Framework\Assert as Assertion;
final class SelectionFieldTypeFormContext extends RawMinkContext implements SnippetAcceptingContext
{
private static $fieldIdentifier = 'field';
/**
* @var \EzSystems\RepositoryForms\Features\Context\FieldTypeFormContext
*/
private $fieldTypeFormContext;
/** @BeforeScenario */
public function gatherContexts(BeforeScenarioScope $scope)
{
$this->fieldTypeFormContext = $scope->getEnvironment()->getContext(
'EzSystems\RepositoryForms\Features\Context\FieldTypeFormContext'
);
}
/**
* @Given /^the field definition is set to single choice$/
*/
public function setFieldDefinitionToSingleChoice()
{
$this->fieldTypeFormContext->setFieldDefinitionOption('isMultiple', false);
}
/**
* @Given /^the field definition is set to multiple choice$/
*/
public function setFieldDefinitionToMultipleChoice()
{
$this->fieldTypeFormContext->setFieldDefinitionOption('isMultiple', true);
}
/**
* @Then it should contain a select field
*/
public function itShouldContainASelectField()
{
$this->assertSession()->elementExists(
'css',
sprintf(
'div.ezfield-identifier-%s fieldset select',
self::$fieldIdentifier
)
);
}
/**
* @Then the select field should be flagged as required
*/
public function theSelectFieldShouldBeFlaggedAsRequired()
{
$nodeElements = $this->getSession()->getPage()->findAll(
'css',
sprintf('div.ezfield-identifier-%s fieldset select', self::$fieldIdentifier)
);
Assertion::assertNotEmpty($nodeElements, 'The select field is not marked as required');
foreach ($nodeElements as $nodeElement) {
Assertion::assertEquals(
'required',
$nodeElement->getAttribute('required'),
sprintf(
'select with id %s is not flagged as required',
$nodeElement->getAttribute('id')
)
);
}
}
/**
* @Then the input is a single selection dropdown
*/
public function theInputIsASingleSelectionDropdown()
{
$this->assertSession()->elementExists(
'css',
sprintf(
'div.ezfield-identifier-%s fieldset select',
self::$fieldIdentifier
)
);
$this->assertSession()->elementNotContains(
'css',
sprintf(
'div.ezfield-identifier-%s fieldset select',
self::$fieldIdentifier
),
'multiple="multiple"'
);
}
/**
* @Then the input is a multiple selection dropdown
*/
public function theInputIsAMultipleSelectionDropdown()
{
$this->assertSession()->elementExists(
'css',
sprintf(
'div.ezfield-identifier-%s fieldset select[multiple=multiple]',
self::$fieldIdentifier
)
);
}
}