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
|
|
|
class FeatureContext extends SilverStripeContext |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @Then I should see a list of blocks |
14
|
|
|
*/ |
15
|
|
|
public function iShouldSeeAListOfBlocks() |
16
|
|
|
{ |
17
|
|
|
assertNotEmpty($this->getBlocks()); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @Then I should see block :position |
22
|
|
|
*/ |
23
|
|
|
public function iShouldSeeBlock($position) |
24
|
|
|
{ |
25
|
|
|
assertNotNull($this->getSpecificBlock($position)); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @When I click on block :position |
30
|
|
|
*/ |
31
|
|
|
public function iClickOnBlock($position) |
32
|
|
|
{ |
33
|
|
|
$block = $this->getSpecificBlock($position); |
34
|
|
|
assertNotNull($block, 'Block ' . $position . ' was not found in the page.'); |
35
|
|
|
$block->click(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @Then I should see :text as the title for block :position |
40
|
|
|
*/ |
41
|
|
|
public function iShouldSeeAsTheTitleForBlock($text, $position) |
42
|
|
|
{ |
43
|
|
|
$block = $this->getSpecificBlock($position); |
44
|
|
|
$title = $block->find('css', '.element-editor-header__title'); |
45
|
|
|
assertEquals($title->getText(), $text); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @Then I should see :text as the summary for block :position |
50
|
|
|
*/ |
51
|
|
|
public function iShouldSeeAsTheSummaryForBlock($text, $position) |
52
|
|
|
{ |
53
|
|
|
$block = $this->getSpecificBlock($position); |
54
|
|
|
$summary = $block->find('css', '.element-editor-summary__content'); |
55
|
|
|
assertEquals($summary->getText(), $text); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @Then I should see the archive button for block :position |
60
|
|
|
* |
61
|
|
|
* @param int $position |
62
|
|
|
*/ |
63
|
|
|
public function iShouldSeeArchiveButtonForBlock($position) |
64
|
|
|
{ |
65
|
|
|
$this->getArchiveButton($position); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @When I hover over block :position |
70
|
|
|
* |
71
|
|
|
* @param int $position |
72
|
|
|
*/ |
73
|
|
|
public function iHoverOverBlock($position) |
74
|
|
|
{ |
75
|
|
|
$block = $this->getSpecificBlock($position); |
76
|
|
|
assertNotNull($block, 'Block ' . $position . ' was not found in the page.'); |
77
|
|
|
$block->mouseOver(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @When I hover over the icon of block :position |
82
|
|
|
* |
83
|
|
|
* @param int $position |
84
|
|
|
*/ |
85
|
|
|
public function iHoverOverTheIconOfBlock($position) |
86
|
|
|
{ |
87
|
|
|
$block = $this->getSpecificBlock($position); |
88
|
|
|
assertNotNull($block, 'Block ' . $position . ' was not found in the page.'); |
89
|
|
|
$icon = $block->find( |
90
|
|
|
'css', |
91
|
|
|
'.element-editor-header .element-editor-header__info .element-editor-header__icon-container' |
92
|
|
|
); |
93
|
|
|
$icon->mouseOver(); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Returns the blocks from the element editor |
98
|
|
|
* |
99
|
|
|
* @param string $modifier Optional CSS selector modifier |
100
|
|
|
* @return NodeElement[] |
101
|
|
|
*/ |
102
|
|
|
protected function getBlocks($modifier = '') |
103
|
|
|
{ |
104
|
|
|
// Wait for the list to be visible |
105
|
|
|
$this->getSession()->wait(3000, 'window.jQuery(".element-editor .elemental-editor__list").length > 0'); |
106
|
|
|
$blocks = $this->getSession() |
107
|
|
|
->getPage() |
108
|
|
|
->findAll('css', '.elemental-editor__list .element-editor__element' . $modifier); |
109
|
|
|
return $blocks; |
110
|
|
|
} |
111
|
|
|
/** |
112
|
|
|
* Returns the selected element |
113
|
|
|
* |
114
|
|
|
* @param int $position |
115
|
|
|
* @return NodeElement |
116
|
|
|
*/ |
117
|
|
|
protected function getSpecificBlock($position) |
118
|
|
|
{ |
119
|
|
|
$blocks = $this->getBlocks(); |
120
|
|
|
/** @var NodeElement $block */ |
121
|
|
|
if ($blocks[$position - 1] !== false) { |
|
|
|
|
122
|
|
|
return $blocks[$position - 1]; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Returns the archive button for a specific block |
128
|
|
|
* |
129
|
|
|
* @param $position |
130
|
|
|
* @return NodeElement |
131
|
|
|
*/ |
132
|
|
|
protected function getArchiveButton($position) |
133
|
|
|
{ |
134
|
|
|
$block = $this->getSpecificBlock($position); |
135
|
|
|
assertNotNull($block, 'Block ' . $position . ' was not found in the page.'); |
136
|
|
|
|
137
|
|
|
$button = $block->find('css', '.element-editor__actions-archive'); |
138
|
|
|
assertNotNull($button, 'Archive button not found'); |
139
|
|
|
|
140
|
|
|
return $button; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.