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\Product; |
15
|
|
|
|
16
|
|
|
use Behat\Mink\Exception\ElementNotFoundException; |
17
|
|
|
use FriendsOfBehat\PageObjectExtension\Page\SymfonyPage; |
18
|
|
|
|
19
|
|
|
class IndexPage extends SymfonyPage implements IndexPageInterface |
20
|
|
|
{ |
21
|
|
|
public function getRouteName(): string |
22
|
|
|
{ |
23
|
|
|
return 'sylius_shop_product_index'; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function countProductsItems(): int |
27
|
|
|
{ |
28
|
|
|
$productsList = $this->getElement('products'); |
29
|
|
|
|
30
|
|
|
$products = $productsList->findAll('css', '[data-test-product]'); |
31
|
|
|
|
32
|
|
|
return count($products); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function getFirstProductNameFromList(): string |
36
|
|
|
{ |
37
|
|
|
$productsList = $this->getElement('products'); |
38
|
|
|
|
39
|
|
|
return $productsList->find('css', '[data-test-product]:first-child [data-test-product-content] [data-test-product-name]')->getText(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getLastProductNameFromList(): string |
43
|
|
|
{ |
44
|
|
|
$productsList = $this->getElement('products'); |
45
|
|
|
|
46
|
|
|
return $productsList->find('css', '[data-test-product]:last-child [data-test-product-content] > a')->getText(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function search(string $name): void |
50
|
|
|
{ |
51
|
|
|
$this->getDocument()->fillField('criteria_search_value', $name); |
52
|
|
|
$this->getElement('search_button')->submit(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function sort(string $orderNumber): void |
56
|
|
|
{ |
57
|
|
|
$this->getDocument()->clickLink($orderNumber); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function clearFilter(): void |
61
|
|
|
{ |
62
|
|
|
$this->getElement('clear')->click(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function isProductOnList(string $productName): bool |
66
|
|
|
{ |
67
|
|
|
try{ |
68
|
|
|
$this->getElement('product_name', ['%productName%' => $productName]); |
69
|
|
|
} catch (ElementNotFoundException $e) { |
70
|
|
|
return false; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return true; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function isEmpty(): bool |
77
|
|
|
{ |
78
|
|
|
return false !== strpos($this->getElement('validation_message')->getText(), 'There are no results to display'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function getProductPrice(string $productName): string |
82
|
|
|
{ |
83
|
|
|
$element = $this->getElement('product_name', ['%productName%' => $productName]); |
84
|
|
|
|
85
|
|
|
return $element->getParent()->find('css', '[data-test-product-price]')->getText(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function isProductOnPageWithName(string $productName): bool |
89
|
|
|
{ |
90
|
|
|
return $this->hasElement('product_name', ['%productName%' => $productName]); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function hasProductsInOrder(array $productNames): bool |
94
|
|
|
{ |
95
|
|
|
$productsList = $this->getElement('products'); |
96
|
|
|
$products = $productsList->findAll('css', '[data-test-product-content] > [data-test-product-name]'); |
97
|
|
|
|
98
|
|
|
foreach ($productNames as $key => $value) { |
99
|
|
|
if ($products[$key]->getText() !== $value) { |
100
|
|
|
return false; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return true; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
protected function getDefinedElements(): array |
108
|
|
|
{ |
109
|
|
|
return array_merge(parent::getDefinedElements(), [ |
110
|
|
|
'clear' => '[data-test-clear]', |
111
|
|
|
'product_name' => '[data-test-product-name="%productName%"]', |
112
|
|
|
'products' => '[data-test-products]', |
113
|
|
|
'search_button' => '[data-test-search]', |
114
|
|
|
'validation_message' => '[data-test-flash-message]', |
115
|
|
|
]); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|