Passed
Pull Request — master (#12)
by Robbie
02:20
created

FeatureContext::findThumbnailImage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
namespace SilverStripe\ElementalBannerBlock\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 DNADesign\Elemental\Tests\Behat\Context\FeatureContext as ElementalFeatureContext;
6
7
if (!class_exists(ElementalFeatureContext::class)) {
8
    return;
9
}
10
11
class FeatureContext extends ElementalFeatureContext
12
{
13
    /**
14
     * @Then /^I should( not |\s+)see the thumbnail image for block (\d+)$/i
15
     *
16
     * @param string $negative
17
     * @param int $position
18
     *
19
     */
20
    public function iShouldSeeTheThumbnailImageForBlock($negative, $position)
21
    {
22
        $iShouldNotSee = $negative === ' not ';
23
24
        $thumbnailImage = $this->findThumbnailImage($position);
25
26
        if ($iShouldNotSee) {
27
            assertNull($thumbnailImage, 'Thumbnail image displayed (but shouldn\'t)');
28
        } else {
29
            assertNotNull($thumbnailImage, 'Thumbnail image not displayed (but should be)');
30
        }
31
    }
32
33
34
    /**
35
     * Returns the thumbnail image for a specific block if it exists
36
     *
37
     * @param int $position
38
     * @return NodeElement|null
39
     */
40
    protected function findThumbnailImage($position)
41
    {
42
        $block = $this->getSpecificBlock($position);
43
        assertNotNull($block, 'Block ' . $position . ' was not found in the page.');
44
45
        $thumbnail = $block->find(
46
            'css',
47
            '.element-editor-content .element-editor-summary .element-editor-summary__thumbnail-image'
48
        );
49
50
        return $thumbnail;
51
    }
52
}
53