1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
namespace SilverStripe\VersionedAdmin\Tests\Behat\Context; |
4
|
|
|
|
5
|
|
|
use Behat\Mink\Element\NodeElement; |
|
|
|
|
6
|
|
|
use SilverStripe\BehatExtension\Context\SilverStripeContext; |
|
|
|
|
7
|
|
|
|
8
|
|
|
if (!class_exists(SilverStripeContext::class)) { |
9
|
|
|
return; |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
class FeatureContext extends SilverStripeContext |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @Then I should see a list of blocks |
16
|
|
|
*/ |
17
|
|
|
public function iShouldSeeAListOfBlocks() |
18
|
|
|
{ |
19
|
|
|
$this->getBlocks(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Example: I should see "font-icon-block-file" as the "font icon" for block 2 |
24
|
|
|
* Example: I should see "My File Block" as the "title" for block 1 |
25
|
|
|
* |
26
|
|
|
* @Then /^I should (not |)see :text as the :selector font icon for block :position/ |
27
|
|
|
* @param string $text |
28
|
|
|
* @param string $position |
29
|
|
|
*/ |
30
|
|
|
public function iShouldSeeAsTheFontIcon($text, $position) |
31
|
|
|
{ |
32
|
|
|
$block = $this->getSpecificBlock($position); |
|
|
|
|
33
|
|
|
|
34
|
|
|
switch ($text) { |
35
|
|
|
case 'font icon': { |
|
|
|
|
36
|
|
|
$fontIcon = $version->find('css', '.element-editor-header__icon-container .i'); |
|
|
|
|
37
|
|
|
assertTrue($fontIcon->hasClass($text)); |
38
|
|
|
} |
39
|
|
|
case 'title': { |
|
|
|
|
40
|
|
|
$title = $version->find('css', '.element-editor-header__title'); |
41
|
|
|
assertTrue($title->hasClass($text)); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Example: I should see "font-icon-block-layout" as the title in block 2 |
49
|
|
|
* |
50
|
|
|
* @Then /^I should (not |)see :text as the font icon in block :position/ |
51
|
|
|
* @param string $text |
52
|
|
|
* @param string $position |
53
|
|
|
*/ |
54
|
|
|
public function iShouldSeeAsTheFontIcon($text, $position) |
55
|
|
|
{ |
56
|
|
|
$block = $this->getSpecificBlock($position); |
|
|
|
|
57
|
|
|
$fontIcon = $version->find('css', '.element-editor-header__icon-container .i'); |
|
|
|
|
58
|
|
|
assertTrue($fontIcon->hasClass($text)); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Returns the blocks from the element editor |
63
|
|
|
* |
64
|
|
|
* @param string $modifier Optional CSS selector modifier |
65
|
|
|
* @return NodeElement[] |
66
|
|
|
*/ |
67
|
|
|
protected function getBlocks($modifier = '') |
68
|
|
|
{ |
69
|
|
|
// Wait for the list to be visible |
70
|
|
|
$this->getSession()->wait(3000, 'window.jQuery(".element-editor .elemental-editor__list").length > 0'); |
71
|
|
|
|
72
|
|
|
$versions = $this->getSession() |
73
|
|
|
->getPage() |
74
|
|
|
->findAll('css', '.elemental-editor__list .elemental-editor__element' . $modifier); |
75
|
|
|
return $versions; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Returns the selected element |
80
|
|
|
* |
81
|
|
|
* @param int $position |
82
|
|
|
* @return NodeElement |
83
|
|
|
*/ |
84
|
|
|
protected function getSpecificBlock($position) |
85
|
|
|
{ |
86
|
|
|
$blocks = $this->getBlocks(); |
87
|
|
|
/** @var NodeElement $block */ |
88
|
|
|
if ($blocks[$position] !== false) { |
|
|
|
|
89
|
|
|
return $blocks[$position]; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
|
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.