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\Component\Product\Model\OptionInterface; |
15
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
16
|
|
|
use Symfony\Component\Routing\RouterInterface; |
17
|
|
|
use Sylius\Behat\Page\SymfonyPage; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
21
|
|
|
* @author Anna Walasek <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class ShowPage extends SymfonyPage implements ShowPageInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
public function addToCart() |
29
|
|
|
{ |
30
|
|
|
$this->getDocument()->pressButton('Add to cart'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
public function addToCartWithQuantity($quantity) |
37
|
|
|
{ |
38
|
|
|
$this->getDocument()->fillField('Quantity', $quantity); |
39
|
|
|
$this->getDocument()->pressButton('Add to cart'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
|
|
public function addToCartWithVariant($variant) |
46
|
|
|
{ |
47
|
|
|
$item = $this->getDocument()->find('css', sprintf('#sylius-product-variants tbody tr:contains("%s")', $variant)); |
48
|
|
|
$radio = $item->find('css', 'input'); |
49
|
|
|
|
50
|
|
|
$this->getDocument()->fillField($radio->getAttribute('name'), $radio->getAttribute('value')); |
51
|
|
|
|
52
|
|
|
$this->getDocument()->pressButton('Add to cart'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
|
|
public function addToCartWithOption(OptionInterface $option, $optionValue) |
59
|
|
|
{ |
60
|
|
|
$select = $this->getDocument()->find('css', sprintf('select#sylius_cart_item_variant_%s', $option->getCode())); |
61
|
|
|
|
62
|
|
|
$this->getDocument()->selectFieldOption($select->getAttribute('name'), $optionValue); |
63
|
|
|
$this->getDocument()->pressButton('Add to cart'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritdoc} |
68
|
|
|
*/ |
69
|
|
|
public function visit($url) |
70
|
|
|
{ |
71
|
|
|
$absoluteUrl = $this->makePathAbsolute($url); |
72
|
|
|
$this->getDriver()->visit($absoluteUrl); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
|
|
public function getName() |
79
|
|
|
{ |
80
|
|
|
return $this->getElement('name')->getText(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* {@inheritdoc} |
85
|
|
|
*/ |
86
|
|
|
public function hasAttributeWithValue($name, $value) |
87
|
|
|
{ |
88
|
|
|
$tableWithAttributes = $this->getElement('attributes'); |
89
|
|
|
|
90
|
|
|
$nameTdSelector = sprintf('tr > td.sylius-product-attribute-name:contains("%s")', $name); |
91
|
|
|
$nameTd = $tableWithAttributes->find('css', $nameTdSelector); |
92
|
|
|
|
93
|
|
|
if (null === $nameTd) { |
94
|
|
|
return false; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$row = $nameTd->getParent(); |
98
|
|
|
|
99
|
|
|
return $value === $row->find('css', 'td.sylius-product-attribute-value')->getText(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* {@inheritdoc} |
104
|
|
|
*/ |
105
|
|
|
public function isOutOfStock() |
106
|
|
|
{ |
107
|
|
|
return $this->hasElement('out-of-stock'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* {@inheritdoc} |
112
|
|
|
*/ |
113
|
|
|
public function hasAddToCartButton() |
114
|
|
|
{ |
115
|
|
|
return $this->getDocument()->hasButton('Add to cart'); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* {@inheritdoc} |
120
|
|
|
*/ |
121
|
|
|
public function getRouteName() |
122
|
|
|
{ |
123
|
|
|
return 'sylius_shop_product_show'; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* {@inheritdoc} |
128
|
|
|
*/ |
129
|
|
|
protected function getDefinedElements() |
130
|
|
|
{ |
131
|
|
|
return array_merge(parent::getDefinedElements(), [ |
132
|
|
|
'name' => '#sylius-product-name', |
133
|
|
|
'attributes' => '#sylius-product-attributes', |
134
|
|
|
'out-of-stock' => '#sylius-product-out-of-stock', |
135
|
|
|
]); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|