1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* (c) FSi sp. z o.o. <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace FSi\Bundle\AdminBundle\Behat\Context; |
13
|
|
|
|
14
|
|
|
use Behat\Gherkin\Node\TableNode; |
15
|
|
|
use Behat\Mink\Element\NodeElement; |
16
|
|
|
use FSi\Bundle\AdminBundle\Behat\Element\Form; |
17
|
|
|
use FSi\Bundle\AdminBundle\Behat\Page\DefaultPage; |
18
|
|
|
|
19
|
|
|
class FormContext extends AbstractContext |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var DefaultPage |
23
|
|
|
*/ |
24
|
|
|
private $defaultPage; |
25
|
|
|
|
26
|
|
|
public function __construct(DefaultPage $defaultPage) |
27
|
|
|
{ |
28
|
|
|
$this->defaultPage = $defaultPage; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @When I change form field :field to value :value |
33
|
|
|
*/ |
34
|
|
|
public function iChangeFormFieldWithValue($field, $value) |
35
|
|
|
{ |
36
|
|
|
expect($this->getFormElement()->findField($field)->getValue())->toNotBe($value); |
37
|
|
|
$this->getFormElement()->fillField($field, $value); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @Given /^I should see form with following fields$/ |
42
|
|
|
*/ |
43
|
|
|
public function iShouldSeeFormWithFollowingFields(TableNode $table) |
44
|
|
|
{ |
45
|
|
|
$form = $this->getFormElement(); |
46
|
|
|
foreach($table->getHash() as $fieldRow) { |
47
|
|
|
expect($form->hasField($fieldRow['Field name']))->toBe(true); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @Given /^I press form "([^"]*)" button$/ |
53
|
|
|
*/ |
54
|
|
|
public function iPressFormButton($button) |
55
|
|
|
{ |
56
|
|
|
$this->getFormElement()->pressButton($button); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @Given I fill the form with values: |
61
|
|
|
*/ |
62
|
|
|
public function iFillFormFields(TableNode $table) |
63
|
|
|
{ |
64
|
|
|
$form = $this->getFormElement(); |
65
|
|
|
foreach($table->getHash() as $fieldRow) { |
66
|
|
|
$fieldName = $fieldRow['Field name']; |
67
|
|
|
$fieldValue = $fieldRow['Field value']; |
68
|
|
|
expect($form->hasField($fieldName))->toBe(true); |
69
|
|
|
$field = $form->findField($fieldName); |
70
|
|
|
if ($field->getAttribute('type') === 'checkbox') { |
71
|
|
|
$this->parseScenarioValue($fieldValue) ? $field->check() : $field->uncheck(); |
72
|
|
|
} else { |
73
|
|
|
$field->setValue($fieldValue); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @Transform /"([^"]*)" non-editable collection/ |
80
|
|
|
* @Transform /non-editable collection "([^"]*)"/ |
81
|
|
|
* @Transform /removable-only collection "([^"]*)"/ |
82
|
|
|
*/ |
83
|
|
|
public function transformToNoneditableCollection($collectionNames) |
84
|
|
|
{ |
85
|
|
|
return $this->defaultPage->getNonEditableCollection($collectionNames); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @Transform /^"([^"]*)" collection/ |
90
|
|
|
* @Transform /collection "([^"]*)"/ |
91
|
|
|
*/ |
92
|
|
|
public function transformToCollection($collectionNames) |
93
|
|
|
{ |
94
|
|
|
return $this->defaultPage->getCollection($collectionNames); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @Given /^("[^"]*" collection) has (\d+) (element|elements)$/ |
99
|
|
|
* @Then /^("[^"]*" collection) should have (\d+) (element|elements)$/ |
100
|
|
|
* @Given /^(non-editable collection "[^"]*") has (\d+) (element|elements)$/ |
101
|
|
|
* @Then /^(non-editable collection "[^"]*") should have (\d+) (element|elements)$/ |
102
|
|
|
* @Then /^(removable-only collection "[^"]*") should have (\d+) (element|elements)$/ |
103
|
|
|
*/ |
104
|
|
|
public function collectionShouldHaveElements(NodeElement $collection, $elementsCount) |
105
|
|
|
{ |
106
|
|
|
$elements = $collection->findAll('xpath', '/*/*[@class = "form-group"]'); |
107
|
|
|
expect(count($elements))->toBe($elementsCount); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @Given /^(collection "[^"]*") should have "([^"]*)" button$/ |
112
|
|
|
*/ |
113
|
|
|
public function collectionShouldHaveButton(NodeElement $collection, $buttonName) |
114
|
|
|
{ |
115
|
|
|
expect($collection->findButton($buttonName))->toNotBeNull(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @Then /^all buttons for adding and removing items in (non-editable collection "[^"]*") should be disabled$/ |
120
|
|
|
*/ |
121
|
|
|
public function allCollectionButtonsDisabled(NodeElement $collection) |
122
|
|
|
{ |
123
|
|
|
$removeButtons = $collection->findAll('css', '.collection-remove'); |
124
|
|
|
expect(count($removeButtons))->notToBe(0); |
125
|
|
|
foreach ($removeButtons as $removeButton) { |
126
|
|
|
expect($removeButton->hasClass('disabled'))->toBe(true); |
127
|
|
|
} |
128
|
|
|
$addButtons = $collection->findAll('css', '.collection-add'); |
129
|
|
|
expect(count($addButtons))->notToBe(0); |
130
|
|
|
foreach ($addButtons as $addButton) { |
131
|
|
|
expect($addButton->hasClass('disabled'))->toBe(true); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @Then /^button for adding item in (removable-only collection "[^"]*") should be disabled$/ |
137
|
|
|
*/ |
138
|
|
|
public function collectionAddButtonIsDisabled(NodeElement $collection) |
139
|
|
|
{ |
140
|
|
|
$addButtons = $collection->findAll('css', '.collection-add'); |
141
|
|
|
expect(count($addButtons))->notToBe(0); |
142
|
|
|
foreach ($addButtons as $addButton) { |
143
|
|
|
expect($addButton->hasClass('disabled'))->toBe(true); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @Then /^buttons for removing items in (removable-only collection "[^"]*") should be enabled/ |
149
|
|
|
*/ |
150
|
|
|
public function collectionRemoveButtonsAreEnabled(NodeElement $collection) |
151
|
|
|
{ |
152
|
|
|
$addButtons = $collection->findAll('css', '.collection-remove'); |
153
|
|
|
expect(count($addButtons))->notToBe(0); |
154
|
|
|
foreach ($addButtons as $addButton) { |
155
|
|
|
expect($addButton->hasClass('disabled'))->toBe(false); |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @When /^I press "([^"]*)" in (collection "[^"]*")$/ |
161
|
|
|
*/ |
162
|
|
|
public function iPressInCollection($buttonName, NodeElement $collection) |
163
|
|
|
{ |
164
|
|
|
$collection |
165
|
|
|
->find('xpath', '/*[contains(concat(" ",normalize-space(@class)," ")," collection-add ")]') |
166
|
|
|
->press(); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @Given /^I fill "([^"]*)" with "([^"]*)" in (collection "[^"]*") at position (\d+)$/ |
171
|
|
|
*/ |
172
|
|
|
public function iFillWithInCollectionAtPosition($fieldName, $fieldValue, NodeElement $collection, $position) |
173
|
|
|
{ |
174
|
|
|
$collectionRow = $collection->find('xpath', sprintf('/*/*[@class = "form-group"][%d]', $position)); |
175
|
|
|
$collectionRow->fillField($fieldName, $fieldValue); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @Given /^I remove (\w+) element in (collection "[^"]*")$/ |
180
|
|
|
* @Given /^I remove (\w+) element in (removable-only collection "[^"]*")$/ |
181
|
|
|
*/ |
182
|
|
|
public function iRemoveElementInCollection($index, NodeElement $collection) |
183
|
|
|
{ |
184
|
|
|
$collection->find('xpath', sprintf('/*/*[@class = "form-group"][%d]', $index)) |
185
|
|
|
->find('css', '.collection-remove')->click(); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
private function getFormElement(): Form |
189
|
|
|
{ |
190
|
|
|
return $this->defaultPage->getElement('Form'); |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|