|
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) { |
|
|
|
|
|
|
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
|
|
|
|