Completed
Push — master ( a818cb...b1c6ca )
by Kamil
07:13 queued 10s
created

HomePage::getContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
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\Page\Shop;
15
16
use Behat\Mink\Element\NodeElement;
17
use Behat\Mink\Exception\UnsupportedDriverActionException;
18
use FriendsOfBehat\PageObjectExtension\Page\SymfonyPage;
19
20
class HomePage extends SymfonyPage implements HomePageInterface
21
{
22
    public function getRouteName(): string
23
    {
24
        return 'sylius_shop_homepage';
25
    }
26
27
    public function getContent(): string
28
    {
29
        return $this->getDocument()->getContent();
30
    }
31
32
    public function logOut(): void
33
    {
34
        $this->getElement('logout_button')->click();
35
    }
36
37
    public function hasLogoutButton(): bool
38
    {
39
        return $this->hasElement('logout_button');
40
    }
41
42
    public function getFullName(): string
43
    {
44
        return $this->getElement('full_name')->getText();
45
    }
46
47
    public function getActiveCurrency(): string
48
    {
49
        return $this->getElement('currency_selector')->find('css', '.sylius-active-currency')->getText();
50
    }
51
52
    public function getAvailableCurrencies(): array
53
    {
54
        return array_map(
55
            function (NodeElement $element) {
56
                return $element->getText();
57
            },
58
            $this->getElement('currency_selector')->findAll('css', '.sylius-available-currency')
59
        );
60
    }
61
62
    public function switchCurrency($currencyCode): void
63
    {
64
        try {
65
            $this->getElement('currency_selector')->click(); // Needed for javascript scenarios
66
        } catch (UnsupportedDriverActionException $exception) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
Bug introduced by
The class Behat\Mink\Exception\Uns...edDriverActionException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
67
        }
68
69
        $this->getElement('currency_selector')->clickLink($currencyCode);
70
    }
71
72
    public function getActiveLocale(): string
73
    {
74
        return $this->getElement('locale_selector')->find('css', '.sylius-active-locale')->getText();
75
    }
76
77
    public function getAvailableLocales(): array
78
    {
79
        return array_map(
80
            function (NodeElement $element) {
81
                return $element->getText();
82
            },
83
            $this->getElement('locale_selector')->findAll('css', '.sylius-available-locale')
84
        );
85
    }
86
87
    public function switchLocale($localeCode): void
88
    {
89
        $this->getElement('locale_selector')->clickLink($localeCode);
90
    }
91
92
    public function getLatestProductsNames(): array
93
    {
94
        return array_map(
95
            function (NodeElement $element) {
96
                return $element->getText();
97
            },
98
            $this->getElement('latest_products')->findAll('css', '.sylius-product-name')
99
        );
100
    }
101
102
    protected function getDefinedElements(): array
103
    {
104
        return array_merge(parent::getDefinedElements(), [
105
            'currency_selector' => '#sylius-currency-selector',
106
            'full_name' => '.right.menu .item',
107
            'latest_products' => '[data-test-latest-products]',
108
            'locale_selector' => '#sylius-locale-selector',
109
            'logout_button' => '[data-test-logout-button]',
110
        ]);
111
    }
112
}
113