Completed
Push — checkout-consistent-prices ( af49ca )
by Kamil
13:24
created

MediaElement::isImageDisplayed()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Behat\Element\Product\ShowPage;
15
16
use FriendsOfBehat\PageObjectExtension\Element\Element;
17
18
final class MediaElement extends Element implements MediaElementInterface
19
{
20
    public function isImageDisplayed(): bool
21
    {
22
        $imageElement = $this->getDocument()->find('css', '#media a img');
23
        if ($imageElement === null) {
24
            return false;
25
        }
26
        $imageUrl = $imageElement->getAttribute('src');
27
        $this->getDriver()->visit($imageUrl);
28
        $pageText = $this->getDocument()->getText();
29
        $this->getDriver()->back();
30
31
        return false === stripos($pageText, '404 Not Found');
32
    }
33
}
34