1
|
|
|
<?php |
2
|
|
|
namespace DNADesign\Elemental\Tests\Behat\Context; |
3
|
|
|
|
4
|
|
|
use Behat\Mink\Element\NodeElement; |
5
|
|
|
use SilverStripe\BehatExtension\Context\SilverStripeContext; |
6
|
|
|
|
7
|
|
|
if (!class_exists(SilverStripeContext::class)) { |
8
|
|
|
return; |
9
|
|
|
} |
10
|
|
|
|
11
|
|
|
class FeatureContext extends SilverStripeContext |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @Then /^I should( not |\s+)see the edit form for block (\d+)$/i |
15
|
|
|
*/ |
16
|
|
|
public function iShouldSeeTheEditFormForBlock($negative, $position) |
17
|
|
|
{ |
18
|
|
|
$iShouldNotSee = $negative === ' not '; |
19
|
|
|
|
20
|
|
|
$block = $this->getSpecificBlock($position); |
21
|
|
|
|
22
|
|
|
$form = $block->find('css', '.element-editor-editform'); |
23
|
|
|
|
24
|
|
|
if ($iShouldNotSee) { |
25
|
|
|
assertTrue(!$form || !$form->isVisible(), 'I see the form! Try again later.'); |
26
|
|
|
} else { |
27
|
|
|
assertNotNull($form, 'Edit form not found'); |
28
|
|
|
assertTrue($form->isVisible()); |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @Then /^I (?:should\s)?see a list of blocks$/i |
34
|
|
|
*/ |
35
|
|
|
public function iShouldSeeAListOfBlocks() |
36
|
|
|
{ |
37
|
|
|
assertNotEmpty($this->getBlocks()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @Then /^I (?:should\s)?see an empty list of blocks$/i |
42
|
|
|
*/ |
43
|
|
|
public function iShouldSeeAnEmptyListOfBlocks() |
44
|
|
|
{ |
45
|
|
|
assertEmpty($this->getBlocks()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @Then I should see block :position |
50
|
|
|
*/ |
51
|
|
|
public function iShouldSeeBlock($position) |
52
|
|
|
{ |
53
|
|
|
assertNotNull($this->getSpecificBlock($position)); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @When /^I click on block (\d+)(?:\sagain)?$/i |
58
|
|
|
*/ |
59
|
|
|
public function iClickOnBlock($position) |
60
|
|
|
{ |
61
|
|
|
$block = $this->getSpecificBlock($position); |
62
|
|
|
assertNotNull($block, 'Block ' . $position . ' was not found in the page.'); |
63
|
|
|
$block->click(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @When /^I click on the caret button for block (\d+)(?:\sagain)?$/i |
68
|
|
|
*/ |
69
|
|
|
public function iClickOnTheCaretButtonForBlock($position) |
70
|
|
|
{ |
71
|
|
|
$block = $this->getSpecificBlock($position); |
72
|
|
|
$button = $this->getCaretButton($block); |
73
|
|
|
assertNotNull($button, 'Caret button for block ' . $position . ' was not found in the page.'); |
74
|
|
|
$button->click(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @Then I should see :text as the title for block :position |
79
|
|
|
*/ |
80
|
|
|
public function iShouldSeeAsTheTitleForBlock($text, $position) |
81
|
|
|
{ |
82
|
|
|
$block = $this->getSpecificBlock($position); |
83
|
|
|
$title = $block->find('css', '.element-editor-header__title'); |
84
|
|
|
assertEquals($title->getText(), $text); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @Then I should see :text as the summary for block :position |
89
|
|
|
*/ |
90
|
|
|
public function iShouldSeeAsTheSummaryForBlock($text, $position) |
91
|
|
|
{ |
92
|
|
|
$block = $this->getSpecificBlock($position); |
93
|
|
|
$summary = $block->find('css', '.element-editor-summary__content'); |
94
|
|
|
assertEquals($summary->getText(), $text); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @Then I should see the archive button for block :position |
99
|
|
|
* |
100
|
|
|
* @param int $position |
101
|
|
|
*/ |
102
|
|
|
public function iShouldSeeArchiveButtonForBlock($position) |
103
|
|
|
{ |
104
|
|
|
$this->getArchiveButton($position); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @When I hover over block :position |
109
|
|
|
* |
110
|
|
|
* @param int $position |
111
|
|
|
*/ |
112
|
|
|
public function iHoverOverBlock($position) |
113
|
|
|
{ |
114
|
|
|
$block = $this->getSpecificBlock($position); |
115
|
|
|
assertNotNull($block, 'Block ' . $position . ' was not found in the page.'); |
116
|
|
|
$block->mouseOver(); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @When I hover over the icon of block :position |
121
|
|
|
* |
122
|
|
|
* @param int $position |
123
|
|
|
*/ |
124
|
|
|
public function iHoverOverTheIconOfBlock($position) |
125
|
|
|
{ |
126
|
|
|
$block = $this->getSpecificBlock($position); |
127
|
|
|
assertNotNull($block, 'Block ' . $position . ' was not found in the page.'); |
128
|
|
|
$icon = $block->find( |
129
|
|
|
'css', |
130
|
|
|
'.element-editor-header .element-editor-header__info .element-editor-header__icon-container' |
131
|
|
|
); |
132
|
|
|
$icon->mouseOver(); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Returns the blocks from the element editor |
137
|
|
|
* |
138
|
|
|
* @param string $modifier Optional CSS selector modifier |
139
|
|
|
* @return NodeElement[] |
140
|
|
|
*/ |
141
|
|
|
protected function getBlocks($modifier = '') |
142
|
|
|
{ |
143
|
|
|
// Wait for the list to be visible |
144
|
|
|
$this->getSession()->wait(3000, 'window.jQuery(".element-editor .elemental-editor__list").length > 0'); |
145
|
|
|
|
146
|
|
|
// Wait for blocks to be rendered |
147
|
|
|
$this->getSession()->wait(3000, 'window.jQuery(".element-editor__element").length > 0'); |
148
|
|
|
|
149
|
|
|
return $this->getSession() |
150
|
|
|
->getPage() |
151
|
|
|
->findAll('css', '.element-editor__element' . $modifier); |
152
|
|
|
} |
153
|
|
|
/** |
154
|
|
|
* Returns the selected element |
155
|
|
|
* |
156
|
|
|
* @param int $position |
157
|
|
|
* @return NodeElement |
158
|
|
|
*/ |
159
|
|
|
protected function getSpecificBlock($position) |
160
|
|
|
{ |
161
|
|
|
$blocks = $this->getBlocks(); |
162
|
|
|
/** @var NodeElement $block */ |
163
|
|
|
if ($blocks[$position - 1] !== false) { |
|
|
|
|
164
|
|
|
return $blocks[$position - 1]; |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Returns the archive button for a specific block |
170
|
|
|
* |
171
|
|
|
* @param $position |
172
|
|
|
* @return NodeElement |
173
|
|
|
*/ |
174
|
|
|
protected function getArchiveButton($position) |
175
|
|
|
{ |
176
|
|
|
$block = $this->getSpecificBlock($position); |
177
|
|
|
assertNotNull($block, 'Block ' . $position . ' was not found in the page.'); |
178
|
|
|
|
179
|
|
|
$button = $block->find('css', '.element-editor__actions-archive'); |
180
|
|
|
assertNotNull($button, 'Archive button not found'); |
181
|
|
|
|
182
|
|
|
return $button; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Returns the caret button for a specific block |
187
|
|
|
* |
188
|
|
|
* @param NodeElement $block |
189
|
|
|
* @return NodeElement |
190
|
|
|
*/ |
191
|
|
|
protected function getCaretButton($block) |
192
|
|
|
{ |
193
|
|
|
$button = $block->find('css', '.element-editor-header__expand'); |
194
|
|
|
assertNotNull($button, 'Caret button not found'); |
195
|
|
|
|
196
|
|
|
return $button; |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|