Completed
Push — checkout-context-cleanup ( c82d5d...3b30b9 )
by Kamil
20:03
created

CheckoutContext::createDefaultAddress()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
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\Context\Ui\Shop\Checkout\AddressingContext;
16
use Sylius\Behat\Page\Shop\Checkout\AddressPageInterface;
17
use Sylius\Behat\Page\Shop\Checkout\CompletePageInterface;
18
use Sylius\Behat\Page\Shop\Checkout\SelectPaymentPageInterface;
19
use Sylius\Behat\Page\Shop\Checkout\SelectShippingPageInterface;
20
use Sylius\Behat\Page\SymfonyPageInterface;
21
use Sylius\Behat\Page\UnexpectedPageException;
22
use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface;
23
use Sylius\Behat\Service\SharedStorageInterface;
24
use Sylius\Component\Addressing\Model\CountryInterface;
25
use Sylius\Component\Core\Formatter\StringInflector;
26
use Sylius\Component\Core\Model\ProductInterface;
27
use Sylius\Component\Core\Model\ShippingMethodInterface;
28
use Sylius\Component\Payment\Model\PaymentMethodInterface;
29
use Sylius\Component\Promotion\Model\PromotionInterface;
30
use Webmozart\Assert\Assert;
31
32
/**
33
 * @author Arkadiusz Krakowiak <[email protected]>
34
 */
35
final class CheckoutContext implements Context
36
{
37
    /**
38
     * @var SharedStorageInterface
39
     */
40
    private $sharedStorage;
41
42
    /**
43
     * @var AddressPageInterface
44
     */
45
    private $addressPage;
46
47
    /**
48
     * @var SelectPaymentPageInterface
49
     */
50
    private $selectPaymentPage;
51
52
    /**
53
     * @var SelectShippingPageInterface
54
     */
55
    private $selectShippingPage;
56
57
    /**
58
     * @var CompletePageInterface
59
     */
60
    private $completePage;
61
62
    /**
63
     * @var CurrentPageResolverInterface
64
     */
65
    private $currentPageResolver;
66
67
    /**
68
     * @var AddressingContext
69
     */
70
    private $addressingContext;
71
72
    /**
73
     * @param SharedStorageInterface $sharedStorage
74
     * @param AddressPageInterface $addressPage
75
     * @param SelectPaymentPageInterface $selectPaymentPage
76
     * @param SelectShippingPageInterface $selectShippingPage
77
     * @param CompletePageInterface $completePage
78
     * @param CurrentPageResolverInterface $currentPageResolver
79
     * @param AddressingContext $addressingContext
80
     */
81
    public function __construct(
82
        SharedStorageInterface $sharedStorage,
83
        AddressPageInterface $addressPage,
84
        SelectPaymentPageInterface $selectPaymentPage,
85
        SelectShippingPageInterface $selectShippingPage,
86
        CompletePageInterface $completePage,
87
        CurrentPageResolverInterface $currentPageResolver,
88
        AddressingContext $addressingContext
89
    ) {
90
        $this->sharedStorage = $sharedStorage;
91
        $this->addressPage = $addressPage;
92
        $this->selectPaymentPage = $selectPaymentPage;
93
        $this->selectShippingPage = $selectShippingPage;
94
        $this->completePage = $completePage;
95
        $this->currentPageResolver = $currentPageResolver;
96
        $this->addressingContext = $addressingContext;
97
    }
98
99
    /**
100
     * @Given I was at the checkout summary step
101
     */
102
    public function iWasAtTheCheckoutSummaryStep()
103
    {
104
        $this->addressingContext->iSpecifiedTheShippingAddress($this->createDefaultAddress());
0 ignored issues
show
Bug introduced by
The method createDefaultAddress() does not seem to exist on object<Sylius\Behat\Context\Ui\CheckoutContext>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
105
        $this->iProceedOrderWithShippingMethodAndPayment('Free', 'Offline');
106
    }
107
108
    /**
109
     * @Given I have proceeded selecting :shippingMethodName shipping method
110
     */
111
    public function iHaveProceededSelectingShippingMethod($shippingMethodName)
112
    {
113
        $this->iSelectShippingMethod($shippingMethodName);
114
        $this->selectShippingPage->nextStep();
115
    }
116
117
    /**
118
     * @When I try to open checkout shipping page
119
     */
120
    public function iTryToOpenCheckoutShippingPage()
121
    {
122
        $this->selectShippingPage->tryToOpen();
123
    }
124
125
    /**
126
     * @When I try to open checkout payment page
127
     */
128
    public function iTryToOpenCheckoutPaymentPage()
129
    {
130
        $this->selectPaymentPage->tryToOpen();
131
    }
132
133
    /**
134
     * @When I try to open checkout complete page
135
     */
136
    public function iTryToOpenCheckoutCompletePage()
137
    {
138
        $this->completePage->tryToOpen();
139
    }
140
141
    /**
142
     * @Given I have selected :shippingMethod shipping method
143
     * @When I select :shippingMethod shipping method
144
     */
145
    public function iSelectShippingMethod($shippingMethod)
146
    {
147
        $this->selectShippingPage->selectShippingMethod($shippingMethod);
148
    }
149
150
    /**
151
     * @Then I should not be able to select :shippingMethodName shipping method
152
     */
153
    public function iShouldNotBeAbleToSelectShippingMethod($shippingMethodName)
154
    {
155
        Assert::false(
156
            in_array($shippingMethodName, $this->selectShippingPage->getShippingMethods(), true),
157
            sprintf('Shipping method "%s" should not be available but it does.', $shippingMethodName)
158
        );
159
    }
160
161
    /**
162
     * @Then I should have :shippingMethodName shipping method available as the first choice
163
     */
164
    public function iShouldHaveShippingMethodAvailableAsFirstChoice($shippingMethodName)
165
    {
166
        $shippingMethods = $this->selectShippingPage->getShippingMethods();
167
        $firstShippingMethod = reset($shippingMethods);
168
169
        Assert::same($shippingMethodName, $firstShippingMethod);
170
    }
171
172
    /**
173
     * @Then I should have :shippingMethodName shipping method available as the last choice
174
     */
175
    public function iShouldHaveShippingMethodAvailableAsLastChoice($shippingMethodName)
176
    {
177
        $shippingMethods = $this->selectShippingPage->getShippingMethods();
178
        $lastShippingMethod = end($shippingMethods);
179
180
        Assert::same($shippingMethodName, $lastShippingMethod);
181
    }
182
183
    /**
184
     * @When /^I(?:| try to) complete the shipping step$/
185
     */
186
    public function iCompleteTheShippingStep()
187
    {
188
        $this->selectShippingPage->nextStep();
189
    }
190
191
    /**
192
     * @When I decide to change my address
193
     */
194
    public function iDecideToChangeMyAddress()
195
    {
196
        $this->selectShippingPage->changeAddress();
197
    }
198
199
    /**
200
     * @When I decide to change order shipping method
201
     */
202
    public function iDecideToChangeMyShippingMethod()
203
    {
204
        $this->selectPaymentPage->changeShippingMethod();
205
    }
206
207
    /**
208
     * @When I go to the addressing step
209
     */
210
    public function iGoToTheAddressingStep()
211
    {
212
        if ($this->selectShippingPage->isOpen()) {
213
            $this->selectShippingPage->changeAddressByStepLabel();
214
215
            return;
216
        }
217
218
        if ($this->selectPaymentPage->isOpen()) {
219
            $this->selectPaymentPage->changeAddressByStepLabel();
220
221
            return;
222
        }
223
224
        if ($this->completePage->isOpen()) {
225
            $this->completePage->changeAddress();
226
227
            return;
228
        }
229
230
        throw new UnexpectedPageException('It is impossible to go to addressing step from current page.');
231
    }
232
233
    /**
234
     * @When I go to the shipping step
235
     */
236
    public function iGoToTheShippingStep()
237
    {
238
        if ($this->selectPaymentPage->isOpen()) {
239
            $this->selectPaymentPage->changeShippingMethodByStepLabel();
240
241
            return;
242
        }
243
244
        if ($this->completePage->isOpen()) {
245
            $this->completePage->changeShippingMethod();
246
247
            return;
248
        }
249
250
        throw new UnexpectedPageException('It is impossible to go to shipping step from current page.');
251
    }
252
253
    /**
254
     * @When I decide to change the payment method
255
     */
256
    public function iGoToThePaymentStep()
257
    {
258
        $this->completePage->changePaymentMethod();
259
    }
260
261
    /**
262
     * @When /^I proceed selecting ("[^"]+" as shipping country) with "([^"]+)" method$/
263
     */
264
    public function iProceedSelectingShippingCountryAndShippingMethod(CountryInterface $shippingCountry = null, $shippingMethodName = null)
265
    {
266
        $this->addressingContext->iProceedSelectingShippingCountry($shippingCountry);
267
268
        $this->selectShippingPage->selectShippingMethod($shippingMethodName ?: 'Free');
269
        $this->selectShippingPage->nextStep();
270
    }
271
272
    /**
273
     * @When /^I proceed selecting "([^"]+)" shipping method$/
274
     * @Given /^I chose "([^"]*)" shipping method$/
275
     */
276
    public function iProceedSelectingShippingMethod($shippingMethodName)
277
    {
278
        $this->iProceedSelectingShippingCountryAndShippingMethod(null, $shippingMethodName);
279
    }
280
281
    /**
282
     * @When /^I choose "([^"]*)" payment method$/
283
     */
284
    public function iChoosePaymentMethod($paymentMethodName)
285
    {
286
        $this->selectPaymentPage->selectPaymentMethod($paymentMethodName ?: 'Offline');
287
        $this->selectPaymentPage->nextStep();
288
    }
289
290
    /**
291
     * @When I go back to shipping step of the checkout
292
     */
293
    public function iGoBackToShippingStepOfTheCheckout()
294
    {
295
        $this->selectShippingPage->open();
296
    }
297
298
    /**
299
     * @Given I have proceeded selecting :paymentMethodName payment method
300
     * @When /^I (?:proceed|proceeded) selecting "([^"]+)" payment method$/
301
     */
302
    public function iProceedSelectingPaymentMethod($paymentMethodName = 'Offline')
303
    {
304
        $this->iProceedSelectingShippingCountryAndShippingMethod();
305
        $this->iChoosePaymentMethod($paymentMethodName);
306
    }
307
308
    /**
309
     * @When /^I change shipping method to "([^"]*)"$/
310
     */
311
    public function iChangeShippingMethod($shippingMethodName)
312
    {
313
        $this->selectPaymentPage->changeShippingMethod();
314
        $this->selectShippingPage->selectShippingMethod($shippingMethodName);
315
        $this->selectShippingPage->nextStep();
316
    }
317
318
    /**
319
     * @When /^I provide additional note like "([^"]+)"$/
320
     */
321
    public function iProvideAdditionalNotesLike($notes)
322
    {
323
        $this->sharedStorage->set('additional_note', $notes);
324
        $this->completePage->addNotes($notes);
325
    }
326
327
    /**
328
     * @When I return to the checkout summary step
329
     */
330
    public function iReturnToTheCheckoutSummaryStep()
331
    {
332
        $this->completePage->open();
333
    }
334
335
    /**
336
     * @When I want to complete checkout
337
     */
338
    public function iWantToCompleteCheckout()
339
    {
340
        $this->completePage->tryToOpen();
341
    }
342
343
    /**
344
     * @When I want to pay for order
345
     */
346
    public function iWantToPayForOrder()
347
    {
348
        $this->selectPaymentPage->tryToOpen();
349
    }
350
351
    /**
352
     * @When I confirm my order
353
     */
354
    public function iConfirmMyOrder()
355
    {
356
        $this->completePage->confirmOrder();
357
    }
358
359
    /**
360
     * @Then I should be on the checkout shipping step
361
     */
362
    public function iShouldBeOnTheCheckoutShippingStep()
363
    {
364
        Assert::true(
365
            $this->selectShippingPage->isOpen(),
366
            'Checkout shipping page should be opened, but it is not.'
367
        );
368
    }
369
370
    /**
371
     * @Then I should be on the checkout complete step
372
     */
373
    public function iShouldBeOnTheCheckoutCompleteStep()
374
    {
375
        Assert::true($this->completePage->isOpen());
376
    }
377
378
    /**
379
     * @Then I should be on the checkout payment step
380
     */
381
    public function iShouldBeOnTheCheckoutPaymentStep()
382
    {
383
        Assert::true(
384
            $this->selectPaymentPage->isOpen(),
385
            'Checkout payment page should be opened, but it is not.'
386
        );
387
    }
388
389
    /**
390
     * @Then I should be on the checkout summary step
391
     */
392
    public function iShouldBeOnTheCheckoutSummaryStep()
393
    {
394
        Assert::true(
395
            $this->completePage->isOpen(),
396
            'Checkout summary page should be opened, but it is not.'
397
        );
398
    }
399
400
    /**
401
     * @Then I should be informed that my order cannot be shipped to this address
402
     */
403
    public function iShouldBeInformedThatMyOrderCannotBeShippedToThisAddress()
404
    {
405
        Assert::true(
406
            $this->selectShippingPage->hasNoShippingMethodsMessage(),
407
            'Shipping page should have no shipping methods message but it does not.'
408
        );
409
    }
410
411
    /**
412
     * @Then my order's shipping address should be to :fullName
413
     */
414
    public function iShouldSeeThisShippingAddressAsShippingAddress($fullName)
415
    {
416
        $address = $this->sharedStorage->get('shipping_address_'.StringInflector::nameToLowercaseCode($fullName));
417
        Assert::true(
418
            $this->completePage->hasShippingAddress($address),
419
            'Shipping address is improper.'
420
        );
421
    }
422
423
    /**
424
     * @Then my order's billing address should be to :fullName
425
     */
426
    public function iShouldSeeThisBillingAddressAsBillingAddress($fullName)
427
    {
428
        $address = $this->sharedStorage->get('billing_address_'.StringInflector::nameToLowercaseCode($fullName));
429
        Assert::true(
430
            $this->completePage->hasBillingAddress($address),
431
            'Billing address is improper.'
432
        );
433
    }
434
435
    /**
436
     * @Then address to :fullName should be used for both shipping and billing of my order
437
     */
438
    public function iShouldSeeThisShippingAddressAsShippingAndBillingAddress($fullName)
439
    {
440
        $this->iShouldSeeThisShippingAddressAsShippingAddress($fullName);
441
        $this->iShouldSeeThisBillingAddressAsBillingAddress($fullName);
442
    }
443
444
    /**
445
     * @When I go back to payment step of the checkout
446
     */
447
    public function iAmAtTheCheckoutPaymentStep()
448
    {
449
        $this->selectPaymentPage->open();
450
    }
451
452
    /**
453
     * @When I complete the payment step
454
     */
455
    public function iCompleteThePaymentStep()
456
    {
457
        $this->selectPaymentPage->nextStep();
458
    }
459
460
    /**
461
     * @When I select :name payment method
462
     */
463
    public function iSelectPaymentMethod($name)
464
    {
465
        $this->selectPaymentPage->selectPaymentMethod($name);
466
    }
467
468
    /**
469
     * @When /^I do not modify anything$/
470
     */
471
    public function iDoNotModifyAnything()
472
    {
473
        // Intentionally left blank to fulfill context expectation
474
    }
475
476
    /**
477
     * @Then I should not be able to select :paymentMethodName payment method
478
     */
479
    public function iShouldNotBeAbleToSelectPaymentMethod($paymentMethodName)
480
    {
481
        Assert::false(
482
            $this->selectPaymentPage->hasPaymentMethod($paymentMethodName),
483
            sprintf('Payment method "%s" should not be available, but it does.', $paymentMethodName)
484
        );
485
    }
486
487
    /**
488
     * @Then I should be able to select :paymentMethodName payment method
489
     */
490
    public function iShouldBeAbleToSelectPaymentMethod($paymentMethodName)
491
    {
492
        Assert::true(
493
            $this->selectPaymentPage->hasPaymentMethod($paymentMethodName),
494
            sprintf('Payment method "%s" should be available, but it does not.', $paymentMethodName)
495
        );
496
    }
497
498
    /**
499
     * @Given I have proceeded order with :shippingMethod shipping method and :paymentMethod payment
500
     * @When I proceed with :shippingMethod shipping method and :paymentMethod payment
501
     */
502
    public function iProceedOrderWithShippingMethodAndPayment($shippingMethod, $paymentMethod)
503
    {
504
        $this->iSelectShippingMethod($shippingMethod);
505
        $this->iCompleteTheShippingStep();
506
        $this->iSelectPaymentMethod($paymentMethod);
507
        $this->iCompleteThePaymentStep();
508
    }
509
510
    /**
511
     * @When I proceed with :shippingMethod shipping method
512
     */
513
    public function iProceedOrderWithShippingMethod($shippingMethod)
514
    {
515
        $this->iSelectShippingMethod($shippingMethod);
516
        $this->iCompleteTheShippingStep();
517
    }
518
519
    /**
520
     * @Given I should have :quantity :productName products in the cart
521
     */
522
    public function iShouldHaveProductsInTheCart($quantity, $productName)
523
    {
524
        Assert::true(
525
            $this->completePage->hasItemWithProductAndQuantity($productName, $quantity),
526
            sprintf('There is no "%s" with quantity %s on order summary page, but it should.', $productName, $quantity)
527
        );
528
    }
529
530
    /**
531
     * @Then my order shipping should be :price
532
     */
533
    public function myOrderShippingShouldBe($price)
534
    {
535
        Assert::true(
536
            $this->completePage->hasShippingTotal($price),
537
            sprintf('The shipping total should be %s, but it is not.', $price)
538
        );
539
    }
540
541
    /**
542
     * @Then /^the ("[^"]+" product) should have unit price discounted by ("\$\d+")$/
543
     */
544
    public function theShouldHaveUnitPriceDiscountedFor(ProductInterface $product, $amount)
545
    {
546
        Assert::true(
547
            $this->completePage->hasProductDiscountedUnitPriceBy($product, $amount),
548
            sprintf('Product %s should have discounted price by %s, but it does not have.', $product->getName(), $amount)
549
        );
550
    }
551
552
    /**
553
     * @Then /^my order total should be ("(?:\£|\$)\d+(?:\.\d+)?")$/
554
     */
555
    public function myOrderTotalShouldBe($total)
556
    {
557
        Assert::true(
558
            $this->completePage->hasOrderTotal($total),
559
            sprintf('Order total should have %s total, but it does not have.', $total)
560
        );
561
    }
562
563
    /**
564
     * @Then my order promotion total should be :promotionTotal
565
     */
566
    public function myOrderPromotionTotalShouldBe($promotionTotal)
567
    {
568
        Assert::true(
569
            $this->completePage->hasPromotionTotal($promotionTotal),
570
            sprintf('The total discount should be %s, but it does not.', $promotionTotal)
571
        );
572
    }
573
574
    /**
575
     * @Then :promotionName should be applied to my order
576
     */
577
    public function shouldBeAppliedToMyOrder($promotionName)
578
    {
579
        Assert::true(
580
            $this->completePage->hasPromotion($promotionName),
581
            sprintf('The promotion %s should appear on the page, but it does not.', $promotionName)
582
        );
583
    }
584
585
    /**
586
     * @Then :promotionName should be applied to my order shipping
587
     */
588
    public function shouldBeAppliedToMyOrderShipping($promotionName)
589
    {
590
        Assert::true($this->completePage->hasShippingPromotion($promotionName));
591
    }
592
593
    /**
594
     * @Given my tax total should be :taxTotal
595
     */
596
    public function myTaxTotalShouldBe($taxTotal)
597
    {
598
        Assert::true(
599
            $this->completePage->hasTaxTotal($taxTotal),
600
            sprintf('The tax total should be %s, but it does not.', $taxTotal)
601
        );
602
    }
603
604
    /**
605
     * @Then my order's shipping method should be :shippingMethod
606
     */
607
    public function myOrderSShippingMethodShouldBe(ShippingMethodInterface $shippingMethod)
608
    {
609
        Assert::true(
610
            $this->completePage->hasShippingMethod($shippingMethod),
611
            sprintf('I should see %s shipping method, but I do not.', $shippingMethod->getName())
612
        );
613
    }
614
615
    /**
616
     * @Then my order's payment method should be :paymentMethod
617
     */
618
    public function myOrderSPaymentMethodShouldBe(PaymentMethodInterface $paymentMethod)
619
    {
620
        Assert::same(
621
            $this->completePage->getPaymentMethodName(),
622
            $paymentMethod->getName()
623
        );
624
    }
625
626
    /**
627
     * @Then I should be able to go to the complete step again
628
     */
629
    public function iShouldBeAbleToGoToTheCompleteStepAgain()
630
    {
631
        $this->selectShippingPage->nextStep();
632
633
        Assert::true($this->completePage->isOpen());
634
    }
635
636
    /**
637
     * @Then I should be redirected to the shipping step
638
     */
639
    public function iShouldBeRedirectedToTheShippingStep()
640
    {
641
        Assert::true(
642
            $this->selectShippingPage->isOpen(),
643
            'Checkout shipping step should be opened, but it is not.'
644
        );
645
    }
646
647
    /**
648
     * @Given I should be able to go to the payment step again
649
     */
650
    public function iShouldBeAbleToGoToThePaymentStepAgain()
651
    {
652
        $this->selectShippingPage->nextStep();
653
654
        Assert::true(
655
            $this->selectPaymentPage->isOpen(),
656
            'Checkout payment step should be opened, but it is not.'
657
        );
658
    }
659
660
    /**
661
     * @Then I should be redirected to the payment step
662
     */
663
    public function iShouldBeRedirectedToThePaymentStep()
664
    {
665
        Assert::true(
666
            $this->selectPaymentPage->isOpen(),
667
            'Checkout payment step should be opened, but it is not.'
668
        );
669
    }
670
671
    /**
672
     * @Given I should be able to go to the summary page again
673
     */
674
    public function iShouldBeAbleToGoToTheSummaryPageAgain()
675
    {
676
        $this->selectPaymentPage->nextStep();
677
678
        Assert::true(
679
            $this->completePage->isOpen(),
680
            'Checkout summary page should be opened, but it is not.'
681
        );
682
    }
683
684
    /**
685
     * @Given I should see shipping method :shippingMethodName with fee :fee
686
     */
687
    public function iShouldSeeShippingFee($shippingMethodName, $fee)
688
    {
689
        Assert::true(
690
            $this->selectShippingPage->hasShippingMethodFee($shippingMethodName, $fee),
691
            sprintf('The shipping fee should be %s, but it does not.', $fee)
692
        );
693
    }
694
695
    /**
696
     * @Then the subtotal of :item item should be :price
697
     */
698
    public function theSubtotalOfItemShouldBe($item, $price)
699
    {
700
        $currentPage = $this->resolveCurrentStepPage();
701
        $actualPrice = $currentPage->getItemSubtotal($item);
702
703
        Assert::eq(
704
            $actualPrice,
705
            $price,
706
            sprintf('The %s subtotal should be %s, but is %s', $item, $price, $actualPrice)
707
        );
708
    }
709
710
    /**
711
     * @Then the :product product should have unit price :price
712
     */
713
    public function theProductShouldHaveUnitPrice(ProductInterface $product, $price)
714
    {
715
        Assert::true(
716
            $this->completePage->hasProductUnitPrice($product, $price),
717
            sprintf('Product %s should have unit price %s, but it does not have.', $product->getName(), $price)
718
        );
719
    }
720
721
    /**
722
     * @Given /^I should be notified that (this product) does not have sufficient stock$/
723
     */
724
    public function iShouldBeNotifiedThatThisProductDoesNotHaveSufficientStock(ProductInterface $product)
725
    {
726
        Assert::true(
727
            $this->completePage->hasProductOutOfStockValidationMessage($product),
728
            sprintf('I should see validation message for %s product', $product->getName())
729
        );
730
    }
731
732
    /**
733
     * @Then my order's locale should be :localeName
734
     */
735
    public function myOrderSLocaleShouldBe($localeName)
736
    {
737
        Assert::true(
738
            $this->completePage->hasLocale($localeName),
739
            'Order locale code is improper.'
740
        );
741
    }
742
743
    /**
744
     * @Then /^I should not be notified that (this product) does not have sufficient stock$/
745
     */
746
    public function iShouldNotBeNotifiedThatThisProductDoesNotHaveSufficientStock(ProductInterface $product)
747
    {
748
        Assert::false(
749
            $this->completePage->hasProductOutOfStockValidationMessage($product),
750
            sprintf('I should see validation message for %s product', $product->getName())
751
        );
752
    }
753
754
    /**
755
     * @Then I should see :provinceName in the shipping address
756
     */
757
    public function iShouldSeeInTheShippingAddress($provinceName)
758
    {
759
        Assert::true(
760
            $this->completePage->hasShippingProvinceName($provinceName),
761
            sprintf('Cannot find shipping address with province %s', $provinceName)
762
        );
763
    }
764
765
    /**
766
     * @Then I should see :provinceName in the billing address
767
     */
768
    public function iShouldSeeInTheBillingAddress($provinceName)
769
    {
770
        Assert::true(
771
            $this->completePage->hasBillingProvinceName($provinceName),
772
            sprintf('Cannot find billing address with province %s', $provinceName)
773
        );
774
    }
775
776
    /**
777
     * @Then there should be information about no available shipping methods
778
     */
779
    public function thereShouldBeInformationAboutNoShippingMethodsAvailableForMyShippingAddress()
780
    {
781
        Assert::true(
782
            $this->selectShippingPage->hasNoAvailableShippingMethodsWarning(),
783
            'There should be warning about no available shipping methods, but it does not.'
784
        );
785
    }
786
787
    /**
788
     * @Then I should have :paymentMethodName payment method available as the first choice
789
     */
790
    public function iShouldHavePaymentMethodAvailableAsFirstChoice($paymentMethodName)
791
    {
792
        $paymentMethods = $this->selectPaymentPage->getPaymentMethods();
793
        $firstPaymentMethod = reset($paymentMethods);
794
795
        Assert::same($paymentMethodName, $firstPaymentMethod);
796
    }
797
798
    /**
799
     * @Then I should have :paymentMethodName payment method available as the last choice
800
     */
801
    public function iShouldHavePaymentMethodAvailableAsLastChoice($paymentMethodName)
802
    {
803
        $paymentMethods = $this->selectPaymentPage->getPaymentMethods();
804
        $lastPaymentMethod = end($paymentMethods);
805
806
        Assert::same($paymentMethodName, $lastPaymentMethod);
807
    }
808
809
    /**
810
     * @Then I should see :shippingMethodName shipping method
811
     */
812
    public function iShouldSeeShippingMethod($shippingMethodName)
813
    {
814
        Assert::true(
815
            $this->selectShippingPage->hasShippingMethod($shippingMethodName),
816
            sprintf('There should be %s shipping method, but it is not.', $shippingMethodName)
817
        );
818
    }
819
820
    /**
821
     * @Then I should not see :shippingMethodName shipping method
822
     */
823
    public function iShouldNotSeeShippingMethod($shippingMethodName)
824
    {
825
        Assert::false(
826
            $this->selectShippingPage->hasShippingMethod($shippingMethodName),
827
            sprintf('There should not be %s shipping method, but it is.', $shippingMethodName)
828
        );
829
    }
830
831
    /**
832
     * @Then I should be checking out as :email
833
     */
834
    public function iShouldBeCheckingOutAs($email)
835
    {
836
        Assert::same(
837
            'Checking out as '.$email.'.',
838
            $this->selectShippingPage->getPurchaserEmail()
839
        );
840
    }
841
842
    /**
843
     * @Then I should not see any information about payment method
844
     */
845
    public function iShouldNotSeeAnyInformationAboutPaymentMethod()
846
    {
847
        Assert::false(
848
            $this->completePage->hasPaymentMethod(),
849
            'There should be no information about payment method, but it is.'
850
        );
851
    }
852
853
    /**
854
     * @Then /^(this promotion) should give "([^"]+)" discount$/
855
     */
856
    public function thisPromotionShouldGiveDiscount(PromotionInterface $promotion, $discount)
857
    {
858
        Assert::same(
859
            $discount,
860
            $this->completePage->getShippingPromotionDiscount($promotion->getName())
861
        );
862
    }
863
864
    /**
865
     * @return SymfonyPageInterface
866
     */
867
    private function resolveCurrentStepPage()
868
    {
869
        $possiblePages = [
870
            $this->addressPage,
871
            $this->selectPaymentPage,
872
            $this->selectShippingPage,
873
            $this->completePage,
874
        ];
875
876
        return $this->currentPageResolver->getCurrentPageWithForm($possiblePages);
877
    }
878
}
879