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\Context\Ui; |
13
|
|
|
|
14
|
|
|
use Behat\Behat\Context\Context; |
15
|
|
|
use Sylius\Behat\Page\Shop\Checkout\AddressingPageInterface; |
16
|
|
|
use Sylius\Behat\Page\Shop\Checkout\PaymentPageInterface; |
17
|
|
|
use Sylius\Behat\Page\Shop\Checkout\ShippingPageInterface; |
18
|
|
|
use Sylius\Behat\Page\Shop\Checkout\SummaryPageInterface; |
19
|
|
|
use Sylius\Behat\Page\Shop\Order\OrderPaymentsPageInterface; |
20
|
|
|
use Sylius\Behat\Page\Shop\Checkout\AddressingStepInterface; |
21
|
|
|
use Sylius\Behat\Page\Shop\Checkout\FinalizeStepInterface; |
22
|
|
|
use Sylius\Behat\Page\Shop\Checkout\PaymentStepInterface; |
23
|
|
|
use Sylius\Behat\Page\Shop\Checkout\SecurityStepInterface; |
24
|
|
|
use Sylius\Behat\Page\Shop\Checkout\ShippingStepInterface; |
25
|
|
|
use Sylius\Behat\Page\Shop\Checkout\ThankYouPageInterface; |
26
|
|
|
use Sylius\Component\Core\Formatter\StringInflector; |
27
|
|
|
use Sylius\Behat\Service\SecurityServiceInterface; |
28
|
|
|
use Sylius\Component\Core\Model\AddressInterface; |
29
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
30
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
31
|
|
|
use Sylius\Component\Core\Model\ShippingMethodInterface; |
32
|
|
|
use Sylius\Component\Core\Model\UserInterface; |
33
|
|
|
use Sylius\Component\Core\Test\Services\SharedStorageInterface; |
34
|
|
|
use Sylius\Component\Order\Repository\OrderRepositoryInterface; |
35
|
|
|
use Sylius\Component\Payment\Model\PaymentInterface; |
36
|
|
|
use Sylius\Component\Payment\Model\PaymentMethodInterface; |
37
|
|
|
use Webmozart\Assert\Assert; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
41
|
|
|
*/ |
42
|
|
|
final class CheckoutContext implements Context |
43
|
|
|
{ |
44
|
|
|
/** |
45
|
|
|
* @var SharedStorageInterface |
46
|
|
|
*/ |
47
|
|
|
private $sharedStorage; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var SecurityStepInterface |
51
|
|
|
*/ |
52
|
|
|
private $checkoutSecurityStep; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var AddressingStepInterface |
56
|
|
|
*/ |
57
|
|
|
private $checkoutAddressingStep; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var AddressingPageInterface |
61
|
|
|
*/ |
62
|
|
|
private $addressingPage; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var ShippingStepInterface |
66
|
|
|
*/ |
67
|
|
|
private $checkoutShippingStep; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @var PaymentStepInterface |
71
|
|
|
*/ |
72
|
|
|
private $checkoutPaymentStep; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var PaymentPageInterface |
76
|
|
|
*/ |
77
|
|
|
private $paymentPage; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var FinalizeStepInterface |
81
|
|
|
*/ |
82
|
|
|
private $checkoutFinalizeStep; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @var ThankYouPageInterface |
86
|
|
|
*/ |
87
|
|
|
private $checkoutThankYouPage; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @var OrderPaymentsPageInterface |
91
|
|
|
*/ |
92
|
|
|
private $orderPaymentsPage; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @var ShippingPageInterface |
96
|
|
|
*/ |
97
|
|
|
private $shippingPage; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @var SummaryPageInterface |
101
|
|
|
*/ |
102
|
|
|
private $summaryPage; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @var OrderRepositoryInterface |
106
|
|
|
*/ |
107
|
|
|
private $orderRepository; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @var SecurityServiceInterface |
111
|
|
|
*/ |
112
|
|
|
private $securityService; |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param SharedStorageInterface $sharedStorage |
116
|
|
|
* @param SecurityStepInterface $checkoutSecurityStep |
117
|
|
|
* @param AddressingStepInterface $checkoutAddressingStep |
118
|
|
|
* @param AddressingPageInterface $addressingPage |
119
|
|
|
* @param ShippingStepInterface $checkoutShippingStep |
120
|
|
|
* @param ShippingPageInterface $shippingPage |
121
|
|
|
* @param PaymentStepInterface $checkoutPaymentStep |
122
|
|
|
* @param PaymentPageInterface $paymentPage |
123
|
|
|
* @param SummaryPageInterface $summaryPage |
124
|
|
|
* @param FinalizeStepInterface $checkoutFinalizeStep |
125
|
|
|
* @param ThankYouPageInterface $checkoutThankYouPage |
126
|
|
|
* @param OrderPaymentsPageInterface $orderPaymentsPage |
127
|
|
|
* @param OrderRepositoryInterface $orderRepository |
128
|
|
|
* @param SecurityServiceInterface $securityService |
129
|
|
|
*/ |
130
|
|
|
public function __construct( |
131
|
|
|
SharedStorageInterface $sharedStorage, |
132
|
|
|
SecurityStepInterface $checkoutSecurityStep, |
133
|
|
|
AddressingStepInterface $checkoutAddressingStep, |
134
|
|
|
AddressingPageInterface $addressingPage, |
135
|
|
|
ShippingStepInterface $checkoutShippingStep, |
136
|
|
|
ShippingPageInterface $shippingPage, |
137
|
|
|
PaymentStepInterface $checkoutPaymentStep, |
138
|
|
|
PaymentPageInterface $paymentPage, |
139
|
|
|
SummaryPageInterface $summaryPage, |
140
|
|
|
FinalizeStepInterface $checkoutFinalizeStep, |
141
|
|
|
ThankYouPageInterface $checkoutThankYouPage, |
142
|
|
|
OrderPaymentsPageInterface $orderPaymentsPage, |
143
|
|
|
OrderRepositoryInterface $orderRepository, |
144
|
|
|
SecurityServiceInterface $securityService |
145
|
|
|
) { |
146
|
|
|
$this->sharedStorage = $sharedStorage; |
147
|
|
|
$this->checkoutSecurityStep = $checkoutSecurityStep; |
148
|
|
|
$this->checkoutAddressingStep = $checkoutAddressingStep; |
149
|
|
|
$this->addressingPage = $addressingPage; |
150
|
|
|
$this->checkoutShippingStep = $checkoutShippingStep; |
151
|
|
|
$this->shippingPage = $shippingPage; |
152
|
|
|
$this->checkoutPaymentStep = $checkoutPaymentStep; |
153
|
|
|
$this->paymentPage = $paymentPage; |
154
|
|
|
$this->summaryPage = $summaryPage; |
155
|
|
|
$this->checkoutFinalizeStep = $checkoutFinalizeStep; |
156
|
|
|
$this->checkoutThankYouPage = $checkoutThankYouPage; |
157
|
|
|
$this->orderPaymentsPage = $orderPaymentsPage; |
158
|
|
|
$this->orderRepository = $orderRepository; |
159
|
|
|
$this->securityService = $securityService; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @Given /^I proceed without selecting shipping address$/ |
164
|
|
|
*/ |
165
|
|
|
public function iProceedWithoutSelectingShippingAddress() |
166
|
|
|
{ |
167
|
|
|
$this->checkoutAddressingStep->open(); |
168
|
|
|
$this->checkoutAddressingStep->continueCheckout(); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @Given I am at the checkout addressing step |
173
|
|
|
*/ |
174
|
|
|
public function iAmAtTheCheckoutAddressingStep() |
175
|
|
|
{ |
176
|
|
|
$this->addressingPage->open(); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @Given /^(this user) bought this product$/ |
181
|
|
|
*/ |
182
|
|
|
public function thisUserBought(UserInterface $user) |
183
|
|
|
{ |
184
|
|
|
$this->securityService->performActionAs($user, function () { |
185
|
|
|
$this->iProceedSelectingOfflinePaymentMethod(); |
186
|
|
|
$this->iConfirmMyOrder(); |
187
|
|
|
}); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @When /^I specify the shipping (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/ |
192
|
|
|
* @When /^I (do not specify any shipping address) information$/ |
193
|
|
|
*/ |
194
|
|
|
public function iSpecifyTheShippingAddressAs(AddressInterface $address) |
195
|
|
|
{ |
196
|
|
|
$key = sprintf( |
197
|
|
|
'shipping_address_%s_%s', |
198
|
|
|
strtolower($address->getFirstName()), |
199
|
|
|
strtolower($address->getLastName()) |
200
|
|
|
); |
201
|
|
|
$this->sharedStorage->set($key, $address); |
202
|
|
|
|
203
|
|
|
$this->addressingPage->specifyShippingAddress($address); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @When /^I specify the billing (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/ |
208
|
|
|
* @When /^I (do not specify any billing address) information$/ |
209
|
|
|
*/ |
210
|
|
|
public function iSpecifyTheBillingAddressAs(AddressInterface $address) |
211
|
|
|
{ |
212
|
|
|
$this->iChooseTheDifferentBillingAddress(); |
213
|
|
|
$key = sprintf( |
214
|
|
|
'billing_address_%s_%s', |
215
|
|
|
strtolower($address->getFirstName()), |
216
|
|
|
strtolower($address->getLastName()) |
217
|
|
|
); |
218
|
|
|
$this->sharedStorage->set($key, $address); |
219
|
|
|
|
220
|
|
|
$this->addressingPage->specifyBillingAddress($address); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* @When /^I specified the shipping (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/ |
225
|
|
|
*/ |
226
|
|
|
public function iSpecifiedTheShippingAddress(AddressInterface $address) |
227
|
|
|
{ |
228
|
|
|
$this->addressingPage->open(); |
229
|
|
|
$this->iSpecifyTheShippingAddressAs($address); |
230
|
|
|
|
231
|
|
|
$key = sprintf('billing_address_%s_%s', strtolower($address->getFirstName()), strtolower($address->getLastName())); |
232
|
|
|
$this->sharedStorage->set($key, $address); |
233
|
|
|
|
234
|
|
|
$this->iCompleteTheAddressingStep(); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @When I choose the different billing address |
239
|
|
|
*/ |
240
|
|
|
public function iChooseTheDifferentBillingAddress() |
241
|
|
|
{ |
242
|
|
|
$this->addressingPage->chooseDifferentBillingAddress(); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @When I specify the email as :email |
247
|
|
|
* @When I do not specify the email |
248
|
|
|
*/ |
249
|
|
|
public function iSpecifyTheEmail($email = null) |
250
|
|
|
{ |
251
|
|
|
$this->addressingPage->specifyEmail($email); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* @When I select :shippingMethod shipping method |
256
|
|
|
*/ |
257
|
|
|
public function iSelectShippingMethod($shippingMethod) |
258
|
|
|
{ |
259
|
|
|
$this->shippingPage->selectShippingMethod($shippingMethod); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* @Then I should not be able to select :shippingMethod shipping method |
264
|
|
|
*/ |
265
|
|
|
public function iShouldNotBeAbleToSelectShippingMethod($shippingMethod) |
266
|
|
|
{ |
267
|
|
|
Assert::false( |
268
|
|
|
$this->shippingPage->hasShippingMethod($shippingMethod), |
269
|
|
|
sprintf('Shipping method "%s" should not be available but it does.', $shippingMethod) |
270
|
|
|
); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* @When I complete the addressing step |
275
|
|
|
* @When I try to complete the addressing step |
276
|
|
|
*/ |
277
|
|
|
public function iCompleteTheAddressingStep() |
278
|
|
|
{ |
279
|
|
|
$this->addressingPage->nextStep(); |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* @When I complete the shipping step |
284
|
|
|
*/ |
285
|
|
|
public function iCompleteTheShippingStep() |
286
|
|
|
{ |
287
|
|
|
$this->shippingPage->nextStep(); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @When /^I proceed selecting "([^"]*)" as shipping country$/ |
292
|
|
|
*/ |
293
|
|
|
public function iProceedSelectingShippingCountry($shippingCountry) |
294
|
|
|
{ |
295
|
|
|
$this->checkoutAddressingStep->open(); |
296
|
|
|
$this->checkoutAddressingStep->fillAddressingDetails([ |
297
|
|
|
'firstName' => 'John', |
298
|
|
|
'lastName' => 'Doe', |
299
|
|
|
'country' => $shippingCountry ?: 'France', |
300
|
|
|
'street' => '0635 Myron Hollow Apt. 711', |
301
|
|
|
'city' => 'North Bridget', |
302
|
|
|
'postcode' => '93-554', |
303
|
|
|
'phoneNumber' => '321123456', |
304
|
|
|
]); |
305
|
|
|
$this->checkoutAddressingStep->continueCheckout(); |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* @When /^I proceed selecting "([^"]*)" as shipping country with "([^"]*)" method$/ |
310
|
|
|
*/ |
311
|
|
|
public function iProceedSelectingShippingCountryAndShippingMethod($shippingCountry, $shippingMethodName) |
312
|
|
|
{ |
313
|
|
|
$this->iProceedSelectingShippingCountry($shippingCountry); |
314
|
|
|
|
315
|
|
|
$this->checkoutShippingStep->selectShippingMethod($shippingMethodName ?: 'Free'); |
316
|
|
|
$this->checkoutShippingStep->continueCheckout(); |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
/** |
320
|
|
|
* @When /^I proceed selecting "([^"]+)" shipping method$/ |
321
|
|
|
* @Given /^I chose "([^"]*)" shipping method$/ |
322
|
|
|
*/ |
323
|
|
|
public function iProceedSelectingShippingMethod($shippingMethodName) |
324
|
|
|
{ |
325
|
|
|
$this->iProceedSelectingShippingCountryAndShippingMethod(null, $shippingMethodName); |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* @When /^I choose "([^"]*)" payment method$/ |
330
|
|
|
*/ |
331
|
|
|
public function iChoosePaymentMethod($paymentMethodName) |
332
|
|
|
{ |
333
|
|
|
$this->checkoutPaymentStep->verify([]); |
334
|
|
|
$this->checkoutPaymentStep->selectPaymentMethod($paymentMethodName ?: 'Offline'); |
335
|
|
|
$this->checkoutPaymentStep->continueCheckout(); |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* @When /^I proceed selecting "([^"]*)" as shipping country with "([^"]*)" payment method$/ |
340
|
|
|
*/ |
341
|
|
|
public function iProceedSelectingShippingCountryAndPaymentMethod($shippingCountry, $paymentMethodName) |
342
|
|
|
{ |
343
|
|
|
$this->iProceedSelectingShippingCountryAndShippingMethod($shippingCountry, null); |
344
|
|
|
|
345
|
|
|
$this->iChoosePaymentMethod($paymentMethodName); |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* @When I proceed selecting :paymentMethodName payment method |
350
|
|
|
*/ |
351
|
|
|
public function iProceedSelectingOfflinePaymentMethod($paymentMethodName = 'Offline') |
352
|
|
|
{ |
353
|
|
|
$this->iProceedSelectingShippingCountryAndPaymentMethod(null, $paymentMethodName); |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* @When /^I change shipping method to "([^"]*)"$/ |
358
|
|
|
*/ |
359
|
|
|
public function iChangeShippingMethod($shippingMethodName) |
360
|
|
|
{ |
361
|
|
|
$this->checkoutShippingStep->open(); |
362
|
|
|
$this->checkoutShippingStep->selectShippingMethod($shippingMethodName); |
363
|
|
|
$this->checkoutShippingStep->continueCheckout(); |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
/** |
367
|
|
|
* @When /^I provide additional note like "([^"]+)"$/ |
368
|
|
|
*/ |
369
|
|
|
public function iProvideAdditionalNotesLike($notes) |
370
|
|
|
{ |
371
|
|
|
$this->sharedStorage->set('additional_note', $notes); |
372
|
|
|
$this->summaryPage->addNotes($notes); |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
/** |
376
|
|
|
* @Given /^I proceed logging as "([^"]*)" with "([^"]*)" password$/ |
377
|
|
|
*/ |
378
|
|
|
public function iProceedLoggingAs($login, $password) |
379
|
|
|
{ |
380
|
|
|
$this->checkoutSecurityStep->open(); |
381
|
|
|
$this->checkoutSecurityStep->logInAsExistingUser($login, $password); |
382
|
|
|
|
383
|
|
|
$this->checkoutAddressingStep->continueCheckout(); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* @When /^I proceed as guest "([^"]*)" with "([^"]*)" as shipping country$/ |
388
|
|
|
*/ |
389
|
|
|
public function iProceedLoggingAsGuestWithAsShippingCountry($email, $shippingCountry) |
390
|
|
|
{ |
391
|
|
|
$this->checkoutSecurityStep->open(); |
392
|
|
|
$this->checkoutSecurityStep->proceedAsGuest($email); |
393
|
|
|
|
394
|
|
|
$this->iProceedSelectingShippingCountry($shippingCountry); |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
/** |
398
|
|
|
* @When I confirm my order |
399
|
|
|
*/ |
400
|
|
|
public function iConfirmMyOrder() |
401
|
|
|
{ |
402
|
|
|
$this->checkoutFinalizeStep->confirmOrder(); |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
/** |
406
|
|
|
* @When I specify the password as :password |
407
|
|
|
*/ |
408
|
|
|
public function iSpecifyThePasswordAs($password) |
409
|
|
|
{ |
410
|
|
|
$this->addressingPage->specifyPassword($password); |
411
|
|
|
} |
412
|
|
|
|
413
|
|
|
/** |
414
|
|
|
* @When I sign in |
415
|
|
|
*/ |
416
|
|
|
public function iSignIn() |
417
|
|
|
{ |
418
|
|
|
$this->addressingPage->signIn(); |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* @Then I should see the thank you page |
423
|
|
|
*/ |
424
|
|
|
public function iShouldSeeTheThankYouPage() |
425
|
|
|
{ |
426
|
|
|
/** @var UserInterface $user */ |
427
|
|
|
$user = $this->sharedStorage->get('user'); |
428
|
|
|
$customer = $user->getCustomer(); |
429
|
|
|
|
430
|
|
|
expect($this->checkoutThankYouPage->hasThankYouMessageFor($customer->getFullName()))->toBe(true); |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
/** |
434
|
|
|
* @Then I should be redirected back to the thank you page |
435
|
|
|
*/ |
436
|
|
|
public function iShouldBeRedirectedBackToTheThankYouPage() |
437
|
|
|
{ |
438
|
|
|
$this->checkoutThankYouPage->waitForResponse(5); |
439
|
|
|
|
440
|
|
|
expect($this->checkoutThankYouPage->isOpen())->toBe(true); |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
/** |
444
|
|
|
* @Then I should be redirected back to the order payment page |
445
|
|
|
*/ |
446
|
|
|
public function iShouldBeRedirectedBackToTheOrderPaymentPage() |
447
|
|
|
{ |
448
|
|
|
$this->orderPaymentsPage->waitForResponse(5, ['number' => $this->getLastOrder()->getNumber()]); |
449
|
|
|
|
450
|
|
|
expect($this->orderPaymentsPage->isOpen(['number' => $this->getLastOrder()->getNumber()]))->toBe(true); |
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
/** |
454
|
|
|
* @Then I should be on the checkout shipping step |
455
|
|
|
*/ |
456
|
|
|
public function iShouldBeOnTheCheckoutShippingStep() |
457
|
|
|
{ |
458
|
|
|
Assert::true( |
459
|
|
|
$this->shippingPage->isOpen(), |
460
|
|
|
'Checkout shipping page should be opened, but it is not.' |
461
|
|
|
); |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
/** |
465
|
|
|
* @Then I should be on the checkout summary step |
466
|
|
|
*/ |
467
|
|
|
public function iShouldBeOnTheCheckoutSummaryStep() |
468
|
|
|
{ |
469
|
|
|
Assert::true( |
470
|
|
|
$this->summaryPage->isOpen(), |
471
|
|
|
'Checkout summary page should be opened, but it is not.' |
472
|
|
|
); |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
/** |
476
|
|
|
* @Then I should see two cancelled payments and new one ready to be paid |
477
|
|
|
*/ |
478
|
|
|
public function iShouldSeeTwoCancelledPaymentsAndNewOneReadyToBePaid() |
479
|
|
|
{ |
480
|
|
|
expect($this->orderPaymentsPage->countPaymentWithSpecificState(PaymentInterface::STATE_CANCELLED))->toBe(2); |
481
|
|
|
expect($this->orderPaymentsPage->countPaymentWithSpecificState(PaymentInterface::STATE_NEW))->toBe(1); |
482
|
|
|
} |
483
|
|
|
|
484
|
|
|
/** |
485
|
|
|
* @Then /^I should(?:| also) be notified that the "([^"]+)" and the "([^"]+)" in (shipping|billing) details are required$/ |
486
|
|
|
*/ |
487
|
|
|
public function iShouldBeNotifiedThatTheAndTheInShippingDetailsAreRequired($firstElement, $secondElement, $type) |
488
|
|
|
{ |
489
|
|
|
$this->assertElementValidationMessage($type, $firstElement, sprintf('Please enter %s.', $firstElement)); |
490
|
|
|
$this->assertElementValidationMessage($type, $secondElement, sprintf('Please enter %s.', $secondElement)); |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
/** |
494
|
|
|
* @Then I should be informed that my order cannot be shipped to this address |
495
|
|
|
*/ |
496
|
|
|
public function iShouldBeInformedThatMyOrderCannotBeShippedToThisAddress() |
497
|
|
|
{ |
498
|
|
|
Assert::true( |
499
|
|
|
$this->shippingPage->hasNoShippingMethodsMessage(), |
500
|
|
|
'Shipping page should have no shipping methods message but it does not.' |
501
|
|
|
); |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
/** |
505
|
|
|
* @Then I should be able to log in |
506
|
|
|
*/ |
507
|
|
|
public function iShouldBeAbleToLogIn() |
508
|
|
|
{ |
509
|
|
|
Assert::true( |
510
|
|
|
$this->addressingPage->canSignIn(), |
511
|
|
|
'I should be able to login, but I am not.' |
512
|
|
|
); |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
/** |
516
|
|
|
* @Then the login form should no longer be accessible |
517
|
|
|
*/ |
518
|
|
|
public function theLoginFormShouldNoLongerBeAccessible() |
519
|
|
|
{ |
520
|
|
|
Assert::false( |
521
|
|
|
$this->addressingPage->canSignIn(), |
522
|
|
|
'I should not be able to login, but I am.' |
523
|
|
|
); |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
/** |
527
|
|
|
* @Then I should be notified about bad credentials |
528
|
|
|
*/ |
529
|
|
|
public function iShouldBeNotifiedAboutBadCredentials() |
530
|
|
|
{ |
531
|
|
|
Assert::true( |
532
|
|
|
$this->addressingPage->checkInvalidCredentialsValidation(), |
533
|
|
|
'I should see validation error, but I do not.' |
534
|
|
|
); |
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
/** |
538
|
|
|
* @Then my order's shipping address should be to :fullName |
539
|
|
|
*/ |
540
|
|
|
public function iShouldSeeThisShippingAddressAsShippingAddress($fullName) |
541
|
|
|
{ |
542
|
|
|
$address = $this->sharedStorage->get('shipping_address_'.StringInflector::nameToLowercaseCode($fullName)); |
543
|
|
|
Assert::true( |
544
|
|
|
$this->summaryPage->hasShippingAddress($address), |
545
|
|
|
'Shipping address is improper.' |
546
|
|
|
); |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
/** |
550
|
|
|
* @Then my order's billing address should be to :fullName |
551
|
|
|
*/ |
552
|
|
|
public function iShouldSeeThisBillingAddressAsBillingAddress($fullName) |
553
|
|
|
{ |
554
|
|
|
$address = $this->sharedStorage->get('billing_address_'.StringInflector::nameToLowercaseCode($fullName)); |
555
|
|
|
Assert::true( |
556
|
|
|
$this->summaryPage->hasBillingAddress($address), |
557
|
|
|
'Billing address is improper.' |
558
|
|
|
); |
559
|
|
|
} |
560
|
|
|
|
561
|
|
|
/** |
562
|
|
|
* @Then address to :fullName should be used for both shipping and billing of my order` |
563
|
|
|
*/ |
564
|
|
|
public function iShouldSeeThisShippingAddressAsShippingAndBillingAddress($fullName) |
565
|
|
|
{ |
566
|
|
|
$this->iShouldSeeThisShippingAddressAsShippingAddress($fullName); |
567
|
|
|
$this->iShouldSeeThisBillingAddressAsBillingAddress($fullName); |
568
|
|
|
} |
569
|
|
|
|
570
|
|
|
/** |
571
|
|
|
* @Given I am at the checkout payment step |
572
|
|
|
*/ |
573
|
|
|
public function iAmAtTheCheckoutPaymentStep() |
574
|
|
|
{ |
575
|
|
|
$this->paymentPage->open(); |
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
/** |
579
|
|
|
* @When I complete the payment step |
580
|
|
|
*/ |
581
|
|
|
public function iCompleteThePaymentStep() |
582
|
|
|
{ |
583
|
|
|
$this->paymentPage->nextStep(); |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
/** |
587
|
|
|
* @When I select :paymentMethodName payment method |
588
|
|
|
*/ |
589
|
|
|
public function iSelectPaymentMethod($paymentMethodName) |
590
|
|
|
{ |
591
|
|
|
$this->paymentPage->selectPaymentMethod($paymentMethodName); |
592
|
|
|
} |
593
|
|
|
|
594
|
|
|
/** |
595
|
|
|
* @Then I should not be able to select :paymentMethodName payment method |
596
|
|
|
*/ |
597
|
|
|
public function iShouldNotBeAbleToSelectPaymentMethod($paymentMethodName) |
598
|
|
|
{ |
599
|
|
|
Assert::false( |
600
|
|
|
$this->paymentPage->hasPaymentMethod($paymentMethodName), |
601
|
|
|
sprintf('Payment method "%s" should not be available but it does.', $paymentMethodName) |
602
|
|
|
); |
603
|
|
|
} |
604
|
|
|
|
605
|
|
|
/** |
606
|
|
|
* @When I proceed order with :shippingMethod shipping method and :paymentMethod payment |
607
|
|
|
*/ |
608
|
|
|
public function iProceedOrderWithShippingMethodAndPayment($shippingMethod, $paymentMethod) |
609
|
|
|
{ |
610
|
|
|
$this->iSelectShippingMethod($shippingMethod); |
611
|
|
|
$this->iCompleteTheShippingStep(); |
612
|
|
|
$this->iSelectPaymentMethod($paymentMethod); |
613
|
|
|
$this->iCompleteThePaymentStep(); |
614
|
|
|
} |
615
|
|
|
|
616
|
|
|
/** |
617
|
|
|
* @Given I should have :quantity :productName products in the cart |
618
|
|
|
*/ |
619
|
|
|
public function iShouldHaveProductsInTheCart($quantity, $productName) |
620
|
|
|
{ |
621
|
|
|
Assert::true( |
622
|
|
|
$this->summaryPage->hasItemWithProductAndQuantity($productName, $quantity), |
623
|
|
|
sprintf('There is no "%s" with quantity %s on order summary page, but it should.', $productName, $quantity) |
624
|
|
|
); |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
/** |
628
|
|
|
* @Given I should see the shipping total with price :price |
629
|
|
|
*/ |
630
|
|
|
public function iShouldSeeTheShippingTotalWithPrice($price) |
631
|
|
|
{ |
632
|
|
|
Assert::true( |
633
|
|
|
$this->summaryPage->hasShippingTotal($price), |
634
|
|
|
sprintf('The shipping total should be %s, but it is not.',$price) |
635
|
|
|
); |
636
|
|
|
} |
637
|
|
|
|
638
|
|
|
/** |
639
|
|
|
* @Then /^the ("[^"]+" product) should have unit price discounted by ("\$\d+")$/ |
640
|
|
|
*/ |
641
|
|
|
public function theShouldHaveUnitPriceDiscountedFor(ProductInterface $product, $amount) |
642
|
|
|
{ |
643
|
|
|
Assert::true( |
644
|
|
|
$this->summaryPage->hasProductDiscountedUnitPriceBy($product, $amount), |
645
|
|
|
sprintf('Product %s should have discounted price by %s, but it does not have.', $product->getName(), $amount) |
646
|
|
|
); |
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
/** |
650
|
|
|
* @Then /^my order total should be ("\$\d+")$/ |
651
|
|
|
*/ |
652
|
|
|
public function myOrderTotalShouldBe($total) |
653
|
|
|
{ |
654
|
|
|
Assert::true( |
655
|
|
|
$this->summaryPage->hasOrderTotal($total), |
656
|
|
|
sprintf('Order total should have %s total, but it does not have.', $total) |
657
|
|
|
); |
658
|
|
|
} |
659
|
|
|
|
660
|
|
|
/** |
661
|
|
|
* @Given I should see promotion total :promotionTotal |
662
|
|
|
*/ |
663
|
|
|
public function iShouldSeeDiscountTotal($promotionTotal) |
664
|
|
|
{ |
665
|
|
|
Assert::true( |
666
|
|
|
$this->summaryPage->hasPromotionTotal($promotionTotal), |
667
|
|
|
sprintf('The total discount should be %s, but it does not.', $promotionTotal) |
668
|
|
|
); |
669
|
|
|
} |
670
|
|
|
|
671
|
|
|
/** |
672
|
|
|
* @Given I should see promotion :promotionName |
673
|
|
|
*/ |
674
|
|
|
public function iShouldSeePromotion($promotionName) |
675
|
|
|
{ |
676
|
|
|
Assert::true( |
677
|
|
|
$this->summaryPage->hasPromotion($promotionName), |
678
|
|
|
sprintf('The promotion %s should appear on the page, but it does not.', $promotionName) |
679
|
|
|
); |
680
|
|
|
} |
681
|
|
|
|
682
|
|
|
/** |
683
|
|
|
* @Given my tax total should be :taxTotal |
684
|
|
|
*/ |
685
|
|
|
public function myTaxTotalShouldBe($taxTotal) |
686
|
|
|
{ |
687
|
|
|
Assert::true( |
688
|
|
|
$this->summaryPage->hasTaxTotal($taxTotal), |
689
|
|
|
sprintf('The tax total should be %s, but it does not.', $taxTotal) |
690
|
|
|
); |
691
|
|
|
} |
692
|
|
|
|
693
|
|
|
/** |
694
|
|
|
* @Then I should see :shippingMethod shipping method |
695
|
|
|
*/ |
696
|
|
|
public function iShouldSeeThisShippingMethod(ShippingMethodInterface $shippingMethod) |
697
|
|
|
{ |
698
|
|
|
Assert::true( |
699
|
|
|
$this->summaryPage->hasShippingMethod($shippingMethod), |
700
|
|
|
sprintf('I should see %s shipping method, but I do not.', $shippingMethod->getName()) |
701
|
|
|
); |
702
|
|
|
} |
703
|
|
|
|
704
|
|
|
/** |
705
|
|
|
* @Then I should see :paymentMethod payment method |
706
|
|
|
*/ |
707
|
|
|
public function iShouldSeeThisPaymentMethod(PaymentMethodInterface $paymentMethod) |
708
|
|
|
{ |
709
|
|
|
Assert::true( |
710
|
|
|
$this->summaryPage->hasPaymentMethod($paymentMethod), |
711
|
|
|
sprintf('I should see %s payment method, but i do not.', $paymentMethod->getName()) |
712
|
|
|
); |
713
|
|
|
} |
714
|
|
|
|
715
|
|
|
/** |
716
|
|
|
* @param string $type |
717
|
|
|
* @param string $element |
718
|
|
|
* @param string $expectedMessage |
719
|
|
|
* |
720
|
|
|
* @throws \InvalidArgumentException |
721
|
|
|
*/ |
722
|
|
|
private function assertElementValidationMessage($type, $element, $expectedMessage) |
723
|
|
|
{ |
724
|
|
|
$element = sprintf('%s_%s', $type, implode('_', explode(' ', $element))); |
725
|
|
|
Assert::true( |
726
|
|
|
$this->addressingPage->checkValidationMessageFor($element, $expectedMessage), |
727
|
|
|
sprintf('The %s should be required.', $element) |
728
|
|
|
); |
729
|
|
|
} |
730
|
|
|
|
731
|
|
|
/** |
732
|
|
|
* @return OrderInterface |
733
|
|
|
* |
734
|
|
|
* @throws \RuntimeException |
735
|
|
|
*/ |
736
|
|
|
private function getLastOrder() |
737
|
|
|
{ |
738
|
|
|
$customer = $this->sharedStorage->get('user')->getCustomer(); |
739
|
|
|
$orders = $this->orderRepository->findByCustomer($customer); |
|
|
|
|
740
|
|
|
$lastOrder = end($orders); |
741
|
|
|
|
742
|
|
|
if (false === $lastOrder) { |
743
|
|
|
throw new \RuntimeException(sprintf('There is no last order for %s', $customer->getFullName())); |
744
|
|
|
} |
745
|
|
|
|
746
|
|
|
return $lastOrder; |
747
|
|
|
} |
748
|
|
|
} |
749
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.