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\Checkout; |
13
|
|
|
|
14
|
|
|
use Behat\Mink\Driver\Selenium2Driver; |
15
|
|
|
use Behat\Mink\Exception\ElementNotFoundException; |
16
|
|
|
use Sylius\Behat\Page\SymfonyPage; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Mateusz Zalewski <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class SelectShippingPage extends SymfonyPage implements SelectShippingPageInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* {@inheritdoc} |
25
|
|
|
*/ |
26
|
|
|
public function getRouteName() |
27
|
|
|
{ |
28
|
|
|
return 'sylius_shop_checkout_select_shipping'; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* {@inheritdoc} |
33
|
|
|
*/ |
34
|
|
|
public function selectShippingMethod($shippingMethod) |
35
|
|
|
{ |
36
|
|
|
if ($this->getDriver() instanceof Selenium2Driver) { |
37
|
|
|
$this->getElement('shipping_method_select', ['%shipping_method%' => $shippingMethod])->click(); |
38
|
|
|
|
39
|
|
|
return; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$shippingMethodOptionElement = $this->getElement('shipping_method_option', ['%shipping_method%' => $shippingMethod]); |
|
|
|
|
43
|
|
|
$shippingMethodOptionElement->selectOption($shippingMethodOptionElement->getAttribute('value')); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
public function getShippingMethods() |
50
|
|
|
{ |
51
|
|
|
$inputs = $this->getSession()->getPage()->findAll('css', '#shipping_methods .item .content label'); |
52
|
|
|
|
53
|
|
|
$shippingMethods = []; |
54
|
|
|
foreach ($inputs as $input) { |
55
|
|
|
$shippingMethods[] = trim($input->getText()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return $shippingMethods; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
|
|
public function hasNoShippingMethodsMessage() |
65
|
|
|
{ |
66
|
|
|
try { |
67
|
|
|
$this->getElement('order_cannot_be_shipped_message'); |
68
|
|
|
} catch (ElementNotFoundException $exception) { |
69
|
|
|
return false; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return true; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* {@inheritdoc} |
77
|
|
|
*/ |
78
|
|
|
public function hasShippingMethodFee($shippingMethodName, $fee) |
79
|
|
|
{ |
80
|
|
|
$feeElement = $this->getElement('shipping_method_fee', ['%shipping_method%' => $shippingMethodName])->getText(); |
81
|
|
|
|
82
|
|
|
return false !== strpos($feeElement, $fee); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritdoc} |
87
|
|
|
*/ |
88
|
|
|
public function getItemSubtotal($itemName) |
89
|
|
|
{ |
90
|
|
|
$itemSlug = strtolower(str_replace('\"', '', str_replace(' ', '-', $itemName))); |
91
|
|
|
|
92
|
|
|
$subtotalTable = $this->getElement('checkout_subtotal'); |
93
|
|
|
|
94
|
|
|
return $subtotalTable->find('css', sprintf('#item-%s-subtotal', $itemSlug))->getText(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function nextStep() |
98
|
|
|
{ |
99
|
|
|
$this->getElement('next_step')->press(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function changeAddress() |
103
|
|
|
{ |
104
|
|
|
$this->getDocument()->clickLink('Change address'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function changeAddressByStepLabel() |
108
|
|
|
{ |
109
|
|
|
$this->getElement('address')->click(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* {@inheritdoc} |
114
|
|
|
*/ |
115
|
|
|
public function getValidationMessageForShipment() |
116
|
|
|
{ |
117
|
|
|
$foundElement = $this->getElement('shipment'); |
118
|
|
|
if (null === $foundElement) { |
119
|
|
|
throw new ElementNotFoundException($this->getSession(), 'Items element'); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
$validationMessage = $foundElement->find('css', '.sylius-validation-error'); |
123
|
|
|
if (null === $validationMessage) { |
124
|
|
|
throw new ElementNotFoundException($this->getSession(), 'Validation message', 'css', '.sylius-validation-error'); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
return $validationMessage->getText(); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* {@inheritdoc} |
132
|
|
|
*/ |
133
|
|
|
public function hasNoAvailableShippingMethodsWarning() |
134
|
|
|
{ |
135
|
|
|
return $this->hasElement('warning_no_shipping_methods'); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* {@inheritdoc} |
140
|
|
|
*/ |
141
|
|
|
public function isNextStepButtonUnavailable() |
142
|
|
|
{ |
143
|
|
|
return $this->getElement('next_step')->hasClass('disabled'); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* {@inheritdoc} |
148
|
|
|
*/ |
149
|
|
|
public function hasShippingMethod($shippingMethodName) |
150
|
|
|
{ |
151
|
|
|
$inputs = $this->getSession()->getPage()->findAll('css', '#shipping_methods .item .content label'); |
152
|
|
|
|
153
|
|
|
$shippingMethods = []; |
154
|
|
|
foreach ($inputs as $input) { |
155
|
|
|
$shippingMethods[] = trim($input->getText()); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
return in_array($shippingMethodName, $shippingMethods); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* {@inheritdoc} |
163
|
|
|
*/ |
164
|
|
|
protected function getDefinedElements() |
165
|
|
|
{ |
166
|
|
|
return array_merge(parent::getDefinedElements(), [ |
167
|
|
|
'address' => '.steps a:contains("Address")', |
168
|
|
|
'checkout_subtotal' => '#checkout-subtotal', |
169
|
|
|
'next_step' => '#next-step', |
170
|
|
|
'order_cannot_be_shipped_message' => '#sylius-order-cannot-be-shipped', |
171
|
|
|
'shipment' => '.items', |
172
|
|
|
'shipping_method' => '[name="sylius_checkout_select_shipping[shipments][0][method]"]', |
173
|
|
|
'shipping_method_fee' => '.item:contains("%shipping_method%") .fee', |
174
|
|
|
'shipping_method_select' => '.item:contains("%shipping_method%") > .field > .ui.radio.checkbox', |
175
|
|
|
'shipping_method_option' => '.item:contains("%shipping_method%") input', |
176
|
|
|
'warning_no_shipping_methods' => '#sylius-order-cannot-be-shipped' |
177
|
|
|
]); |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.