|
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\Context\Ui\Shop\Checkout; |
|
15
|
|
|
|
|
16
|
|
|
use Behat\Behat\Context\Context; |
|
17
|
|
|
use Sylius\Behat\NotificationType; |
|
18
|
|
|
use Sylius\Behat\Page\Shop\Checkout\CompletePageInterface; |
|
19
|
|
|
use Sylius\Behat\Service\NotificationCheckerInterface; |
|
20
|
|
|
use Sylius\Behat\Service\SharedStorageInterface; |
|
21
|
|
|
use Sylius\Component\Core\Formatter\StringInflector; |
|
22
|
|
|
use Sylius\Component\Core\Model\PaymentMethodInterface; |
|
23
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
|
24
|
|
|
use Sylius\Component\Core\Model\PromotionInterface; |
|
25
|
|
|
use Sylius\Component\Core\Model\ShippingMethodInterface; |
|
26
|
|
|
use Webmozart\Assert\Assert; |
|
27
|
|
|
|
|
28
|
|
|
final class CheckoutCompleteContext implements Context |
|
29
|
|
|
{ |
|
30
|
|
|
/** @var SharedStorageInterface */ |
|
31
|
|
|
private $sharedStorage; |
|
32
|
|
|
|
|
33
|
|
|
/** @var CompletePageInterface */ |
|
34
|
|
|
private $completePage; |
|
35
|
|
|
|
|
36
|
|
|
/** @var NotificationCheckerInterface */ |
|
37
|
|
|
private $notificationChecker; |
|
38
|
|
|
|
|
39
|
|
|
public function __construct( |
|
40
|
|
|
SharedStorageInterface $sharedStorage, |
|
41
|
|
|
CompletePageInterface $completePage, |
|
42
|
|
|
NotificationCheckerInterface $notificationChecker |
|
43
|
|
|
) { |
|
44
|
|
|
$this->sharedStorage = $sharedStorage; |
|
45
|
|
|
$this->completePage = $completePage; |
|
46
|
|
|
$this->notificationChecker = $notificationChecker; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @When I try to open checkout complete page |
|
51
|
|
|
* @When I want to complete checkout |
|
52
|
|
|
*/ |
|
53
|
|
|
public function iTryToOpenCheckoutCompletePage() |
|
54
|
|
|
{ |
|
55
|
|
|
$this->completePage->tryToOpen(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @When I decide to change the payment method |
|
60
|
|
|
*/ |
|
61
|
|
|
public function iGoToThePaymentStep() |
|
62
|
|
|
{ |
|
63
|
|
|
$this->completePage->changePaymentMethod(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @When /^I provide additional note like "([^"]+)"$/ |
|
68
|
|
|
*/ |
|
69
|
|
|
public function iProvideAdditionalNotesLike($notes) |
|
70
|
|
|
{ |
|
71
|
|
|
$this->sharedStorage->set('additional_note', $notes); |
|
72
|
|
|
$this->completePage->addNotes($notes); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @When I return to the checkout summary step |
|
77
|
|
|
*/ |
|
78
|
|
|
public function iReturnToTheCheckoutSummaryStep() |
|
79
|
|
|
{ |
|
80
|
|
|
$this->completePage->open(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @Given I have confirmed order |
|
85
|
|
|
* @When I confirm my order |
|
86
|
|
|
*/ |
|
87
|
|
|
public function iConfirmMyOrder() |
|
88
|
|
|
{ |
|
89
|
|
|
$this->completePage->confirmOrder(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @Then I should be on the checkout complete step |
|
94
|
|
|
* @Then I should be on the checkout summary step |
|
95
|
|
|
*/ |
|
96
|
|
|
public function iShouldBeOnTheCheckoutCompleteStep() |
|
97
|
|
|
{ |
|
98
|
|
|
$this->completePage->verify(); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @Then my order's shipping address should be to :fullName |
|
103
|
|
|
*/ |
|
104
|
|
|
public function iShouldSeeThisShippingAddressAsShippingAddress($fullName) |
|
105
|
|
|
{ |
|
106
|
|
|
$address = $this->sharedStorage->get('shipping_address_' . StringInflector::nameToLowercaseCode($fullName)); |
|
107
|
|
|
|
|
108
|
|
|
Assert::true($this->completePage->hasShippingAddress($address)); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @Then my order's billing address should be to :fullName |
|
113
|
|
|
*/ |
|
114
|
|
|
public function iShouldSeeThisBillingAddressAsBillingAddress($fullName) |
|
115
|
|
|
{ |
|
116
|
|
|
$address = $this->sharedStorage->get('billing_address_' . StringInflector::nameToLowercaseCode($fullName)); |
|
117
|
|
|
|
|
118
|
|
|
Assert::true($this->completePage->hasBillingAddress($address)); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @Then address to :fullName should be used for both shipping and billing of my order |
|
123
|
|
|
*/ |
|
124
|
|
|
public function iShouldSeeThisShippingAddressAsShippingAndBillingAddress($fullName) |
|
125
|
|
|
{ |
|
126
|
|
|
$this->iShouldSeeThisShippingAddressAsShippingAddress($fullName); |
|
127
|
|
|
$this->iShouldSeeThisBillingAddressAsBillingAddress($fullName); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @Then I should have :quantity :productName products in the cart |
|
132
|
|
|
*/ |
|
133
|
|
|
public function iShouldHaveProductsInTheCart($quantity, $productName) |
|
134
|
|
|
{ |
|
135
|
|
|
Assert::true($this->completePage->hasItemWithProductAndQuantity($productName, $quantity)); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @Then my order shipping should be :price |
|
140
|
|
|
*/ |
|
141
|
|
|
public function myOrderShippingShouldBe($price) |
|
142
|
|
|
{ |
|
143
|
|
|
Assert::true($this->completePage->hasShippingTotal($price)); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @Then /^the ("[^"]+" product) should have unit price discounted by ("\$\d+")$/ |
|
148
|
|
|
*/ |
|
149
|
|
|
public function theShouldHaveUnitPriceDiscountedFor(ProductInterface $product, $amount) |
|
150
|
|
|
{ |
|
151
|
|
|
Assert::true($this->completePage->hasProductDiscountedUnitPriceBy($product, $amount)); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @Then /^my order total should be ("(?:\£|\$)\d+(?:\.\d+)?")$/ |
|
156
|
|
|
*/ |
|
157
|
|
|
public function myOrderTotalShouldBe($total) |
|
158
|
|
|
{ |
|
159
|
|
|
Assert::true($this->completePage->hasOrderTotal($total)); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @Then my order promotion total should be :promotionTotal |
|
164
|
|
|
*/ |
|
165
|
|
|
public function myOrderPromotionTotalShouldBe($promotionTotal) |
|
166
|
|
|
{ |
|
167
|
|
|
Assert::true($this->completePage->hasPromotionTotal($promotionTotal)); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @Then :promotionName should be applied to my order |
|
172
|
|
|
*/ |
|
173
|
|
|
public function shouldBeAppliedToMyOrder($promotionName) |
|
174
|
|
|
{ |
|
175
|
|
|
Assert::true($this->completePage->hasOrderPromotion($promotionName)); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* @Then :promotionName should be applied to my order shipping |
|
180
|
|
|
*/ |
|
181
|
|
|
public function shouldBeAppliedToMyOrderShipping($promotionName) |
|
182
|
|
|
{ |
|
183
|
|
|
Assert::true($this->completePage->hasShippingPromotion($promotionName)); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* @Given my tax total should be :taxTotal |
|
188
|
|
|
*/ |
|
189
|
|
|
public function myTaxTotalShouldBe($taxTotal) |
|
190
|
|
|
{ |
|
191
|
|
|
Assert::true($this->completePage->hasTaxTotal($taxTotal)); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* @Then my order's shipping method should be :shippingMethod |
|
196
|
|
|
*/ |
|
197
|
|
|
public function myOrdersShippingMethodShouldBe(ShippingMethodInterface $shippingMethod) |
|
198
|
|
|
{ |
|
199
|
|
|
Assert::true($this->completePage->hasShippingMethod($shippingMethod)); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* @Then my order's payment method should be :paymentMethod |
|
204
|
|
|
*/ |
|
205
|
|
|
public function myOrdersPaymentMethodShouldBe(PaymentMethodInterface $paymentMethod) |
|
206
|
|
|
{ |
|
207
|
|
|
Assert::same($this->completePage->getPaymentMethodName(), $paymentMethod->getName()); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* @Then the :product product should have unit price :price |
|
212
|
|
|
*/ |
|
213
|
|
|
public function theProductShouldHaveUnitPrice(ProductInterface $product, $price) |
|
214
|
|
|
{ |
|
215
|
|
|
Assert::true($this->completePage->hasProductUnitPrice($product, $price)); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* @Then /^I should be notified that (this product) does not have sufficient stock$/ |
|
220
|
|
|
*/ |
|
221
|
|
|
public function iShouldBeNotifiedThatThisProductDoesNotHaveSufficientStock(ProductInterface $product) |
|
222
|
|
|
{ |
|
223
|
|
|
Assert::true($this->completePage->hasProductOutOfStockValidationMessage($product)); |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* @Then /^I should not be notified that (this product) does not have sufficient stock$/ |
|
228
|
|
|
*/ |
|
229
|
|
|
public function iShouldNotBeNotifiedThatThisProductDoesNotHaveSufficientStock(ProductInterface $product) |
|
230
|
|
|
{ |
|
231
|
|
|
Assert::false($this->completePage->hasProductOutOfStockValidationMessage($product)); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* @Then my order's locale should be :locale |
|
236
|
|
|
*/ |
|
237
|
|
|
public function myOrderLocaleShouldBe($locale) |
|
238
|
|
|
{ |
|
239
|
|
|
Assert::true($this->completePage->hasLocale($locale)); |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
/** |
|
243
|
|
|
* @Then I should see :provinceName in the shipping address |
|
244
|
|
|
*/ |
|
245
|
|
|
public function iShouldSeeInTheShippingAddress($provinceName) |
|
246
|
|
|
{ |
|
247
|
|
|
Assert::true($this->completePage->hasShippingProvinceName($provinceName)); |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* @Then I should see :provinceName in the billing address |
|
252
|
|
|
*/ |
|
253
|
|
|
public function iShouldSeeInTheBillingAddress($provinceName) |
|
254
|
|
|
{ |
|
255
|
|
|
Assert::true($this->completePage->hasBillingProvinceName($provinceName)); |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
/** |
|
259
|
|
|
* @Then I should not see any information about payment method |
|
260
|
|
|
*/ |
|
261
|
|
|
public function iShouldNotSeeAnyInformationAboutPaymentMethod() |
|
262
|
|
|
{ |
|
263
|
|
|
Assert::false($this->completePage->hasPaymentMethod()); |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
/** |
|
267
|
|
|
* @Then I should not be able to confirm order because products does not fit :shippingMethod requirements |
|
268
|
|
|
*/ |
|
269
|
|
|
public function iShouldNotBeAbleToConfirmOrderBecauseDoesNotBelongsToShippingCategory(ShippingMethodInterface $shippingMethod) |
|
270
|
|
|
{ |
|
271
|
|
|
$this->completePage->confirmOrder(); |
|
272
|
|
|
|
|
273
|
|
|
Assert::same( |
|
274
|
|
|
$this->completePage->getValidationErrors(), |
|
275
|
|
|
sprintf( |
|
276
|
|
|
'Product does not fit requirements for %s shipping method. Please reselect your shipping method.', |
|
277
|
|
|
$shippingMethod->getName() |
|
278
|
|
|
) |
|
279
|
|
|
); |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* @Then /^I should be informed that (this promotion) is no longer applied$/ |
|
284
|
|
|
*/ |
|
285
|
|
|
public function iShouldBeInformedThatMyPromotionIsNoLongerApplied(PromotionInterface $promotion) |
|
286
|
|
|
{ |
|
287
|
|
|
$this->notificationChecker->checkNotification( |
|
288
|
|
|
sprintf('You are no longer eligible for this promotion %s.', $promotion->getName()), |
|
289
|
|
|
NotificationType::failure() |
|
290
|
|
|
); |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
/** |
|
294
|
|
|
* @Then /^I should be informed that (this payment method) has been disabled$/ |
|
295
|
|
|
*/ |
|
296
|
|
|
public function iShouldBeInformedThatThisPaymentMethodHasBeenDisabled(PaymentMethodInterface $paymentMethod) |
|
297
|
|
|
{ |
|
298
|
|
|
Assert::same( |
|
299
|
|
|
$this->completePage->getValidationErrors(), |
|
300
|
|
|
sprintf( |
|
301
|
|
|
'This payment method %s has been disabled. Please reselect your payment method.', |
|
302
|
|
|
$paymentMethod->getName() |
|
303
|
|
|
) |
|
304
|
|
|
); |
|
305
|
|
|
} |
|
306
|
|
|
|
|
307
|
|
|
/** |
|
308
|
|
|
* @Then /^I should be informed that (this product) has been disabled$/ |
|
309
|
|
|
*/ |
|
310
|
|
|
public function iShouldBeInformedThatThisProductHasBeenDisabled(ProductInterface $product) |
|
311
|
|
|
{ |
|
312
|
|
|
Assert::same( |
|
313
|
|
|
$this->completePage->getValidationErrors(), |
|
314
|
|
|
sprintf( |
|
315
|
|
|
'This product %s has been disabled.', |
|
316
|
|
|
$product->getName() |
|
317
|
|
|
) |
|
318
|
|
|
); |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
/** |
|
322
|
|
|
* @Then I should be informed that order total has been changed |
|
323
|
|
|
*/ |
|
324
|
|
|
public function iShouldBeInformedThatOrderTotalHasBeenChanged() |
|
325
|
|
|
{ |
|
326
|
|
|
$this->notificationChecker->checkNotification( |
|
327
|
|
|
'Your order total has been changed, check your order information and confirm it again.', |
|
328
|
|
|
NotificationType::failure() |
|
329
|
|
|
); |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
|
|
/** |
|
333
|
|
|
* @Then /^(this promotion) should give "([^"]+)" discount on shipping$/ |
|
334
|
|
|
*/ |
|
335
|
|
|
public function thisPromotionShouldGiveDiscountOnShipping(PromotionInterface $promotion, string $discount): void |
|
336
|
|
|
{ |
|
337
|
|
|
Assert::true($this->completePage->hasShippingPromotionWithDiscount($promotion->getName(), $discount)); |
|
338
|
|
|
} |
|
339
|
|
|
} |
|
340
|
|
|
|