Completed
Push — master ( 273e76...e5ee2c )
by Robbie
12s
created

FeatureContext::getSpecificBlock()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 10 and the first side effect is on line 8.

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.

Loading history...
2
namespace DNADesign\Elemental\Tests\Behat\Context;
3
4
use Behat\Mink\Element\NodeElement;
0 ignored issues
show
Bug introduced by
The type Behat\Mink\Element\NodeElement was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
5
use SilverStripe\BehatExtension\Context\SilverStripeContext;
0 ignored issues
show
Bug introduced by
The type SilverStripe\BehatExtens...ext\SilverStripeContext was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

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