|
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
|
|
|
namespace Sylius\Behat\Page\Shop\Product; |
|
13
|
|
|
|
|
14
|
|
|
use Sylius\Behat\Page\SymfonyPage; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @author Anna Walasek <[email protected]> |
|
18
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
|
19
|
|
|
*/ |
|
20
|
|
|
class IndexPage extends SymfonyPage implements IndexPageInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritdoc} |
|
24
|
|
|
*/ |
|
25
|
|
|
public function getRouteName() |
|
26
|
|
|
{ |
|
27
|
|
|
return 'sylius_shop_product_index'; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* {@inheritdoc} |
|
32
|
|
|
*/ |
|
33
|
|
|
public function countProductsItems() |
|
34
|
|
|
{ |
|
35
|
|
|
$productsList = $this->getDocument()->find('css', '#products'); |
|
36
|
|
|
|
|
37
|
|
|
$products = $productsList->findAll('css', '.column > .card'); |
|
38
|
|
|
|
|
39
|
|
|
return count($products); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritdoc} |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getFirstProductNameFromList() |
|
46
|
|
|
{ |
|
47
|
|
|
$productsList = $this->getDocument()->find('css', '#products'); |
|
48
|
|
|
|
|
49
|
|
|
return $productsList->find('css', '.column:first-child .content > a')->getText(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* {@inheritdoc} |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getLastProductNameFromList() |
|
56
|
|
|
{ |
|
57
|
|
|
$productsList = $this->getDocument()->find('css', '#products'); |
|
58
|
|
|
|
|
59
|
|
|
return $productsList->find('css', '.column:last-child .content > a')->getText(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* {@inheritdoc} |
|
64
|
|
|
*/ |
|
65
|
|
|
public function search($name) |
|
66
|
|
|
{ |
|
67
|
|
|
$this->getDocument()->fillField('criteria_search_value', $name); |
|
68
|
|
|
$this->getDocument()->pressButton('Search'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* {@inheritdoc} |
|
73
|
|
|
*/ |
|
74
|
|
|
public function sort($order) |
|
75
|
|
|
{ |
|
76
|
|
|
$this->getDocument()->clickLink($order); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function clearFilter() |
|
80
|
|
|
{ |
|
81
|
|
|
$this->getDocument()->clickLink('Clear'); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* {@inheritdoc} |
|
86
|
|
|
*/ |
|
87
|
|
|
public function isProductOnList($productName) |
|
88
|
|
|
{ |
|
89
|
|
|
return null !== $this->getDocument()->find('css', sprintf('.sylius-product-name:contains("%s")', $productName)); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* {@inheritdoc} |
|
94
|
|
|
*/ |
|
95
|
|
|
public function isEmpty() |
|
96
|
|
|
{ |
|
97
|
|
|
return false !== strpos($this->getDocument()->find('css', '.message')->getText(), 'There are no results to display'); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* {@inheritdoc} |
|
102
|
|
|
*/ |
|
103
|
|
|
public function getProductPrice($productName) |
|
104
|
|
|
{ |
|
105
|
|
|
$container = $this->getDocument()->find('css', sprintf('.sylius-product-name:contains("%s")', $productName))->getParent(); |
|
106
|
|
|
|
|
107
|
|
|
return $container->find('css', '.sylius-product-price')->getText(); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* {@inheritdoc} |
|
112
|
|
|
*/ |
|
113
|
|
|
public function isProductOnPageWithName($name) |
|
114
|
|
|
{ |
|
115
|
|
|
return null !== $this->getDocument()->find('css', sprintf('.content > a:contains("%s")', $name)); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* {@inheritdoc} |
|
120
|
|
|
*/ |
|
121
|
|
|
public function hasProductsInOrder(array $productNames) |
|
122
|
|
|
{ |
|
123
|
|
|
$productsList = $this->getDocument()->find('css', '#products'); |
|
124
|
|
|
$products = $productsList->findAll('css', '.column .content > .sylius-product-name'); |
|
125
|
|
|
|
|
126
|
|
|
foreach ($productNames as $key => $value) { |
|
127
|
|
|
if ($products[$key]->getText() !== $value) { |
|
128
|
|
|
return false; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
return true; |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|