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
|
|
|
// assert it is actually rendered |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @When I click on block :position |
31
|
|
|
*/ |
32
|
|
|
public function iClickOnBlock($position) |
33
|
|
|
{ |
34
|
|
|
$block = $this->getSpecificBlock($position); |
35
|
|
|
assertNotNull($block, 'Block ' . $position . ' was not found in the page.'); |
36
|
|
|
$block->click(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @When I click on the delete button for block :position |
41
|
|
|
*/ |
42
|
|
|
public function iClickOnTheDeleteButtonForBlock($position) |
43
|
|
|
{ |
44
|
|
|
$block = $this->getSpecificBlock($position); |
45
|
|
|
assertNotNull($block, 'Block ' . $position . ' was not found in the page.'); |
46
|
|
|
|
47
|
|
|
$button = $block->find('css', '.font-icon-trash-bin'); |
48
|
|
|
assertNotNull($button, 'Delete button not found'); |
49
|
|
|
$button->click(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @Then I should see :text as the icon for block :position |
54
|
|
|
*/ |
55
|
|
|
public function iShouldSeeAsTheIconForBlock($text, $position) |
56
|
|
|
{ |
57
|
|
|
$block = $this->getSpecificBlock($position); |
58
|
|
|
$icon = $block->find('css', '.element-editor-header__icon-container .i'); |
59
|
|
|
assertTrue($icon->hasClass($text)); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @Then I should see :text as the title for block :position |
64
|
|
|
*/ |
65
|
|
|
public function iShouldSeeAsTheTitleForBlock($text, $position) |
66
|
|
|
{ |
67
|
|
|
$block = $this->getSpecificBlock($position); |
68
|
|
|
$title = $block->find('css', '.element-editor-header__title'); |
69
|
|
|
assertEquals($title->getText(), $text); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @Then /^I should (not |)see the edit link for block :position/ |
74
|
|
|
* |
75
|
|
|
* @param string $text |
76
|
|
|
* @param string $position |
77
|
|
|
*/ |
78
|
|
|
public function iShouldSeeEditLinkForBlock($text, $position) |
79
|
|
|
{ |
80
|
|
|
$block = $this->getSpecificBlock($position); |
|
|
|
|
81
|
|
|
$editLink = $block->find('css', '.element-editor-header__actions-container .a'); |
|
|
|
|
82
|
|
|
assertTrue($icon->hasClass($text)); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @Then I should see the delete button for block :position |
88
|
|
|
* |
89
|
|
|
* @param string $text |
90
|
|
|
* @param string $position |
91
|
|
|
*/ |
92
|
|
|
public function iShouldSeeDeleteButtonForBlock($position) |
93
|
|
|
{ |
94
|
|
|
$block = $this->getSpecificBlock($position); |
|
|
|
|
95
|
|
|
$button = $block->findAll('css', 'Delete'); |
96
|
|
|
assertNotNull($button, 'Delete button not found'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @When I hover over block :position |
101
|
|
|
* |
102
|
|
|
* @param int $position |
103
|
|
|
*/ |
104
|
|
|
public function iHoverOverBlock($position) |
105
|
|
|
{ |
106
|
|
|
$block = $this->getSpecificBlock($position); |
107
|
|
|
assertNotNull($block, 'Block ' . $position . ' was not found in the page.'); |
108
|
|
|
$block->mouseOver(); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @When I hover over the icon of block :position |
113
|
|
|
* |
114
|
|
|
* @param int $position |
115
|
|
|
*/ |
116
|
|
|
public function iHoverOverTheIconOfBlock($position) |
117
|
|
|
{ |
118
|
|
|
$block = $this->getSpecificBlock($position); |
119
|
|
|
assertNotNull($block, 'Block ' . $position . ' was not found in the page.'); |
120
|
|
|
$icon = $block->find('css', '.element-editor-header .element-editor-header__info .element-editor-header__icon-container'); |
121
|
|
|
$icon->mouseOver(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Returns the blocks from the element editor |
126
|
|
|
* |
127
|
|
|
* @param string $modifier Optional CSS selector modifier |
128
|
|
|
* @return NodeElement[] |
129
|
|
|
*/ |
130
|
|
|
protected function getBlocks($modifier = '') |
131
|
|
|
{ |
132
|
|
|
// Wait for the list to be visible |
133
|
|
|
$this->getSession()->wait(3000, 'window.jQuery(".element-editor .elemental-editor__list").length > 0'); |
134
|
|
|
$blocks = $this->getSession() |
135
|
|
|
->getPage() |
136
|
|
|
->findAll('css', '.elemental-editor__list .element-editor__element' . $modifier); |
137
|
|
|
return $blocks; |
138
|
|
|
} |
139
|
|
|
/** |
140
|
|
|
* Returns the selected element |
141
|
|
|
* |
142
|
|
|
* @param int $position |
143
|
|
|
* @return NodeElement |
144
|
|
|
*/ |
145
|
|
|
protected function getSpecificBlock($position) |
146
|
|
|
{ |
147
|
|
|
$blocks = $this->getBlocks(); |
148
|
|
|
/** @var NodeElement $block */ |
149
|
|
|
if ($blocks[$position - 1] !== false) { |
|
|
|
|
150
|
|
|
return $blocks[$position - 1]; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
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.