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

FeatureContext::iShouldSeeAsTheIconForBlock()   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 2
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 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
        // 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);
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

80
        $block = $this->getSpecificBlock(/** @scrutinizer ignore-type */ $position);
Loading history...
81
        $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...
82
        assertTrue($icon->hasClass($text));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $icon seems to be never defined.
Loading history...
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);
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

94
        $block = $this->getSpecificBlock(/** @scrutinizer ignore-type */ $position);
Loading history...
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) {
0 ignored issues
show
introduced by
The condition $blocks[$position - 1] !== false is always true.
Loading history...
150
            return $blocks[$position - 1];
151
        }
152
    }
153
}
154