Passed
Pull Request — master (#321)
by
unknown
02:14
created

FeatureContext::iHoverOverBlock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
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 8 and the first side effect is on line 6.

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
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...
4
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...
5
if (!class_exists(SilverStripeContext::class)) {
6
    return;
7
}
8
class FeatureContext extends SilverStripeContext
9
{
10
    /**
11
     * @Then I should see a list of blocks
12
     */
13
    public function iShouldSeeAListOfBlocks()
14
    {
15
        assertNotEmpty($this->getBlocks());
16
    }
17
18
    /**
19
     * @Then I should see block :position
20
     */
21
    public function iShouldSeeBlock($position)
22
    {
23
        assertNotNull($this->getSpecificBlock($position));
24
        // assert it is actually rendered
25
    }
26
27
    /**
28
     * @When I click on block :position
29
     */
30
    public function iClickOnBlock($position)
31
    {
32
        $block = $this->getSpecificBlock($position);
33
        assertNotNull($block, 'Block ' . $position . ' was not found in the page.');
34
        $block->click();
35
    }
36
37
    /**
38
     * @When I click on the delete button for block :position
39
     */
40
    public function iClickOnTheDeleteButtonForBlock($position)
41
    {
42
        $block = $this->getSpecificBlock($position);
43
        assertNotNull($block, 'Block ' . $position . ' was not found in the page.');
44
45
        $button = $block->find('css', '.font-icon-trash-bin');
46
        assertNotNull($button,'Delete button not found');
47
        $button->click();
48
    }
49
50
    /**
51
     * @Then I should see :text as the icon for block :position
52
     */
53
    public function iShouldSeeAsTheIconForBlock($text, $position)
54
    {
55
        $block = $this->getSpecificBlock($position);
56
        $icon = $block->find('css', '.element-editor-header__icon-container .i');
57
        assertTrue($icon->hasClass($text));
58
    }
59
60
    /**
61
     * @Then I should see :text as the title for block :position
62
     */
63
    public function iShouldSeeAsTheTitleForBlock($text, $position)
64
    {
65
        $block = $this->getSpecificBlock($position);
66
        $title = $block->find('css', '.element-editor-header__title');
67
        assertEquals($title->getText(), $text);
68
    }
69
70
    /**
71
     * @Then /^I should (not |)see the edit link for block :position/
72
     *
73
     * @param string $text
74
     * @param string $position
75
     */
76
    public function iShouldSeeEditLinkForBlock($text, $position)
77
    {
78
        $block = $this->getSpecificBlock($position);
0 ignored issues
show
Bug introduced by
$position of type string is incompatible with the type integer expected by parameter $position of DNADesign\Elemental\Test...ext::getSpecificBlock(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

78
        $block = $this->getSpecificBlock(/** @scrutinizer ignore-type */ $position);
Loading history...
79
        $editLink = $block->find('css', '.element-editor-header__actions-container .a');
0 ignored issues
show
Unused Code introduced by
The assignment to $editLink is dead and can be removed.
Loading history...
80
        assertTrue($icon->hasClass($text));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $icon seems to be never defined.
Loading history...
81
    }
82
83
84
    /**
85
     * @Then I should see the delete button for block :position
86
     *
87
     * @param string $text
88
     * @param string $position
89
     */
90
    public function iShouldSeeDeleteButtonForBlock($position)
91
    {
92
        $block = $this->getSpecificBlock($position);
0 ignored issues
show
Bug introduced by
$position of type string is incompatible with the type integer expected by parameter $position of DNADesign\Elemental\Test...ext::getSpecificBlock(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

92
        $block = $this->getSpecificBlock(/** @scrutinizer ignore-type */ $position);
Loading history...
93
        $button = $block->findAll('css', 'Delete');
94
        assertNotNull($button, 'Delete button not found');
95
    }
96
97
    /**
98
     * @When I hover over block :position
99
     *
100
     * @param int $position
101
     */
102
    public function iHoverOverBlock($position)
103
    {
104
        $block = $this->getSpecificBlock($position);
105
        assertNotNull($block, 'Block ' . $position . ' was not found in the page.');
106
        $block->mouseOver();
107
    }
108
109
    /**
110
     * @When I hover over the icon of block :position
111
     *
112
     * @param int $position
113
     */
114
    public function iHoverOverTheIconOfBlock($position)
115
    {
116
        $block = $this->getSpecificBlock($position);
117
        assertNotNull($block, 'Block ' . $position . ' was not found in the page.');
118
        $icon = $block->find('css', '.element-editor-header .element-editor-header__info .element-editor-header__icon-container');
119
        $icon->mouseOver();
120
    }
121
122
    /**
123
     * Returns the blocks from the element editor
124
     *
125
     * @param string $modifier Optional CSS selector modifier
126
     * @return NodeElement[]
127
     */
128
    protected function getBlocks($modifier = '')
129
    {
130
        // Wait for the list to be visible
131
        $this->getSession()->wait(3000, 'window.jQuery(".element-editor .elemental-editor__list").length > 0');
132
        $blocks = $this->getSession()
133
            ->getPage()
134
            ->findAll('css', '.elemental-editor__list .element-editor__element' . $modifier);
135
        return $blocks;
136
    }
137
    /**
138
     * Returns the selected element
139
     *
140
     * @param int $position
141
     * @return NodeElement
142
     */
143
    protected function getSpecificBlock($position)
144
    {
145
        $blocks = $this->getBlocks();
146
        /** @var NodeElement $block */
147
        if ($blocks[$position - 1] !== false) {
0 ignored issues
show
introduced by
The condition $blocks[$position - 1] !== false is always true.
Loading history...
148
            return $blocks[$position - 1];
149
        }
150
    }
151
152
}
153