Completed
Push — master ( bcb54c...8151ca )
by Kamil
05:51 queued 19s
created

theOrdersPromotionDiscountShouldBeFromPromotion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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\Admin;
15
16
use Behat\Behat\Context\Context;
17
use Sylius\Behat\NotificationType;
18
use Sylius\Behat\Page\Admin\Order\HistoryPageInterface;
19
use Sylius\Behat\Page\Admin\Order\IndexPageInterface;
20
use Sylius\Behat\Page\Admin\Order\ShowPageInterface;
21
use Sylius\Behat\Page\Admin\Order\UpdatePageInterface;
22
use Sylius\Behat\Service\NotificationCheckerInterface;
23
use Sylius\Behat\Service\SharedSecurityServiceInterface;
24
use Sylius\Behat\Service\SharedStorageInterface;
25
use Sylius\Component\Addressing\Model\AddressInterface;
26
use Sylius\Component\Core\Model\AdminUserInterface;
27
use Sylius\Component\Core\Model\CustomerInterface;
28
use Sylius\Component\Core\Model\OrderInterface;
29
use Webmozart\Assert\Assert;
30
31
final class ManagingOrdersContext implements Context
32
{
33
    /** @var SharedStorageInterface */
34
    private $sharedStorage;
35
36
    /** @var IndexPageInterface */
37
    private $indexPage;
38
39
    /** @var ShowPageInterface */
40
    private $showPage;
41
42
    /** @var UpdatePageInterface */
43
    private $updatePage;
44
45
    /** @var HistoryPageInterface */
46
    private $historyPage;
47
48
    /** @var NotificationCheckerInterface */
49
    private $notificationChecker;
50
51
    /** @var SharedSecurityServiceInterface */
52
    private $sharedSecurityService;
53
54
    public function __construct(
55
        SharedStorageInterface $sharedStorage,
56
        IndexPageInterface $indexPage,
57
        ShowPageInterface $showPage,
58
        UpdatePageInterface $updatePage,
59
        HistoryPageInterface $historyPage,
60
        NotificationCheckerInterface $notificationChecker,
61
        SharedSecurityServiceInterface $sharedSecurityService
62
    ) {
63
        $this->sharedStorage = $sharedStorage;
64
        $this->indexPage = $indexPage;
65
        $this->showPage = $showPage;
66
        $this->updatePage = $updatePage;
67
        $this->historyPage = $historyPage;
68
        $this->notificationChecker = $notificationChecker;
69
        $this->sharedSecurityService = $sharedSecurityService;
70
    }
71
72
    /**
73
     * @Given I am browsing orders
74
     * @When I browse orders
75
     */
76
    public function iBrowseOrders()
77
    {
78
        $this->indexPage->open();
79
    }
80
81
    /**
82
     * @When I browse order's :order history
83
     */
84
    public function iBrowseOrderHistory(OrderInterface $order)
85
    {
86
        $this->historyPage->open(['id' => $order->getId()]);
87
    }
88
89
    /**
90
     * @Given /^I am viewing the summary of (this order)$/
91
     * @When I view the summary of the order :order
92
     */
93
    public function iSeeTheOrder(OrderInterface $order)
94
    {
95
        $this->showPage->open(['id' => $order->getId()]);
96
    }
97
98
    /**
99
     * @When /^I mark (this order) as paid$/
100
     */
101
    public function iMarkThisOrderAsAPaid(OrderInterface $order)
102
    {
103
        $this->showPage->completeOrderLastPayment($order);
104
    }
105
106
    /**
107
     * @When /^I mark (this order)'s payment as refunded$/
108
     */
109
    public function iMarkThisOrderSPaymentAsRefunded(OrderInterface $order)
110
    {
111
        $this->showPage->refundOrderLastPayment($order);
112
    }
113
114
    /**
115
     * @When specify its tracking code as :trackingCode
116
     */
117
    public function specifyItsTrackingCodeAs($trackingCode)
118
    {
119
        $this->showPage->specifyTrackingCode($trackingCode);
120
        $this->sharedStorage->set('tracking_code', $trackingCode);
121
    }
122
123
    /**
124
     * @When /^I ship (this order)$/
125
     */
126
    public function iShipThisOrder(OrderInterface $order)
127
    {
128
        $this->showPage->shipOrder($order);
129
    }
130
131
    /**
132
     * @When I switch the way orders are sorted by :fieldName
133
     */
134
    public function iSwitchSortingBy($fieldName)
135
    {
136
        $this->indexPage->sortBy($fieldName);
137
    }
138
139
    /**
140
     * @When I specify filter date from as :dateTime
141
     */
142
    public function iSpecifyFilterDateFromAs($dateTime)
143
    {
144
        $this->indexPage->specifyFilterDateFrom($dateTime);
145
    }
146
147
    /**
148
     * @When I specify filter date to as :dateTime
149
     */
150
    public function iSpecifyFilterDateToAs($dateTime)
151
    {
152
        $this->indexPage->specifyFilterDateTo($dateTime);
153
    }
154
155
    /**
156
     * @When I choose :channelName as a channel filter
157
     */
158
    public function iChooseChannelAsAChannelFilter($channelName)
159
    {
160
        $this->indexPage->chooseChannelFilter($channelName);
161
    }
162
163
    /**
164
     * @When I choose :currencyName as the filter currency
165
     */
166
    public function iChooseCurrencyAsTheFilterCurrency($currencyName)
167
    {
168
        $this->indexPage->chooseCurrencyFilter($currencyName);
169
    }
170
171
    /**
172
     * @When I specify filter total being greater than :total
173
     */
174
    public function iSpecifyFilterTotalBeingGreaterThan($total)
175
    {
176
        $this->indexPage->specifyFilterTotalGreaterThan($total);
177
    }
178
179
    /**
180
     * @When I specify filter total being less than :total
181
     */
182
    public function iSpecifyFilterTotalBeingLessThan($total)
183
    {
184
        $this->indexPage->specifyFilterTotalLessThan($total);
185
    }
186
187
    /**
188
     * @When I filter
189
     */
190
    public function iFilter()
191
    {
192
        $this->indexPage->filter();
193
    }
194
195
    /**
196
     * @Then I should see a single order from customer :customer
197
     */
198
    public function iShouldSeeASingleOrderFromCustomer(CustomerInterface $customer)
199
    {
200
        Assert::true($this->indexPage->isSingleResourceOnPage(['customer' => $customer->getEmail()]));
201
    }
202
203
    /**
204
     * @Then it should have been placed by the customer :customerEmail
205
     */
206
    public function itShouldBePlacedByCustomer($customerEmail)
207
    {
208
        Assert::true($this->showPage->hasCustomer($customerEmail));
209
    }
210
211
    /**
212
     * @Then it should be shipped to :customerName, :street, :postcode, :city, :countryName
213
     * @Then /^(this order) should (?:|still )be shipped to "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)"$/
214
     */
215
    public function itShouldBeShippedTo(
216
        OrderInterface $order = null,
217
        $customerName,
218
        $street,
219
        $postcode,
220
        $city,
221
        $countryName
222
    ) {
223
        if (null !== $order) {
224
            $this->iSeeTheOrder($order);
225
        }
226
227
        Assert::true($this->showPage->hasShippingAddress($customerName, $street, $postcode, $city, $countryName));
228
    }
229
230
    /**
231
     * @Then it should be billed to :customerName, :street, :postcode, :city, :countryName
232
     * @Then the order should be billed to :customerName, :street, :postcode, :city, :countryName
233
     * @Then /^(this order) bill should (?:|still )be shipped to "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)"$/
234
     */
235
    public function itShouldBeBilledTo(
236
        OrderInterface $order = null,
237
        $customerName,
238
        $street,
239
        $postcode,
240
        $city,
241
        $countryName
242
    ) {
243
        if (null !== $order) {
244
            $this->iSeeTheOrder($order);
245
        }
246
247
        Assert::true($this->showPage->hasBillingAddress($customerName, $street, $postcode, $city, $countryName));
248
    }
249
250
    /**
251
     * @Then it should have no shipping address set
252
     */
253
    public function itShouldHaveNoShippingAddressSet(): void
254
    {
255
        Assert::false($this->showPage->hasShippingAddressVisible());
256
    }
257
258
    /**
259
     * @Then it should be shipped via the :shippingMethodName shipping method
260
     */
261
    public function itShouldBeShippedViaShippingMethod($shippingMethodName)
262
    {
263
        Assert::true($this->showPage->hasShipment($shippingMethodName));
264
    }
265
266
    /**
267
     * @Then it should be paid with :paymentMethodName
268
     */
269
    public function itShouldBePaidWith($paymentMethodName)
270
    {
271
        Assert::true($this->showPage->hasPayment($paymentMethodName));
272
    }
273
274
    /**
275
     * @Then /^it should have (\d+) items$/
276
     * @Then I should see :amount orders in the list
277
     * @Then I should see a single order in the list
278
     */
279
    public function itShouldHaveAmountOfItems($amount = 1)
280
    {
281
        Assert::same($this->showPage->countItems(), (int) $amount);
282
    }
283
284
    /**
285
     * @Then the product named :productName should be in the items list
286
     */
287
    public function theProductShouldBeInTheItemsList($productName)
288
    {
289
        Assert::true($this->showPage->isProductInTheList($productName));
290
    }
291
292
    /**
293
     * @Then the order's items total should be :itemsTotal
294
     */
295
    public function theOrdersItemsTotalShouldBe($itemsTotal)
296
    {
297
        Assert::eq($this->showPage->getItemsTotal(), $itemsTotal);
298
    }
299
300
    /**
301
     * @Then /^the order's total should(?:| still) be "([^"]+)"$/
302
     */
303
    public function theOrdersTotalShouldBe($total)
304
    {
305
        Assert::eq($this->showPage->getTotal(), $total);
306
    }
307
308
    /**
309
     * @Then there should be a shipping charge :shippingCharge
310
     */
311
    public function theOrdersShippingChargesShouldBe($shippingCharge)
312
    {
313
        Assert::true($this->showPage->hasShippingCharge($shippingCharge));
314
    }
315
316
    /**
317
     * @Then the order's shipping total should be :shippingTotal
318
     */
319
    public function theOrdersShippingTotalShouldBe($shippingTotal)
320
    {
321
        Assert::eq($this->showPage->getShippingTotal(), $shippingTotal);
322
    }
323
324
    /**
325
     * @Then the order's payment should (also) be :paymentAmount
326
     */
327
    public function theOrdersPaymentShouldBe($paymentAmount)
328
    {
329
        Assert::eq($this->showPage->getPaymentAmount(), $paymentAmount);
330
    }
331
332
    /**
333
     * @Then the order should have tax :tax
334
     */
335
    public function theOrderShouldHaveTax($tax)
336
    {
337
        Assert::true($this->showPage->hasTax($tax));
338
    }
339
340
    /**
341
     * @Then /^the order's tax total should(?:| still) be "([^"]+)"$/
342
     */
343
    public function theOrdersTaxTotalShouldBe($taxTotal)
344
    {
345
        Assert::eq($this->showPage->getTaxTotal(), $taxTotal);
346
    }
347
348
    /**
349
     * @Then the order's promotion discount should be :promotionAmount from :promotionName promotion
350
     */
351
    public function theOrdersPromotionDiscountShouldBeFromPromotion(string $promotionAmount, string $promotionName): void
352
    {
353
        Assert::true($this->showPage->hasPromotionDiscount($promotionName, $promotionAmount));
354
    }
355
356
    /**
357
     * @Then the order's shipping promotion should be :promotion
358
     */
359
    public function theOrdersShippingPromotionDiscountShouldBe($promotionData)
360
    {
361
        Assert::same($this->showPage->getShippingPromotionData(), $promotionData);
362
    }
363
364
    /**
365
     * @Then /^the order's promotion total should(?:| still) be "([^"]+)"$/
366
     */
367
    public function theOrdersPromotionTotalShouldBe($promotionTotal)
368
    {
369
        Assert::same($this->showPage->getOrderPromotionTotal(), $promotionTotal);
370
    }
371
372
    /**
373
     * @When I check :itemName data
374
     */
375
    public function iCheckData($itemName)
376
    {
377
        $this->sharedStorage->set('item', $itemName);
378
    }
379
380
    /**
381
     * @Then /^(its) code should be "([^"]+)"$/
382
     */
383
    public function itemCodeShouldBe($itemName, $code)
384
    {
385
        Assert::same($this->showPage->getItemCode($itemName), $code);
386
    }
387
388
    /**
389
     * @Then /^(its) unit price should be ([^"]+)$/
390
     */
391
    public function itemUnitPriceShouldBe($itemName, $unitPrice)
392
    {
393
        Assert::eq($this->showPage->getItemUnitPrice($itemName), $unitPrice);
394
    }
395
396
    /**
397
     * @Then /^(its) discounted unit price should be ([^"]+)$/
398
     */
399
    public function itemDiscountedUnitPriceShouldBe($itemName, $discountedUnitPrice)
400
    {
401
        Assert::eq($this->showPage->getItemDiscountedUnitPrice($itemName), $discountedUnitPrice);
402
    }
403
404
    /**
405
     * @Then /^(its) quantity should be ([^"]+)$/
406
     */
407
    public function itemQuantityShouldBe($itemName, $quantity)
408
    {
409
        Assert::eq($this->showPage->getItemQuantity($itemName), $quantity);
410
    }
411
412
    /**
413
     * @Then /^(its) subtotal should be ([^"]+)$/
414
     */
415
    public function itemSubtotalShouldBe($itemName, $subtotal)
416
    {
417
        Assert::eq($this->showPage->getItemSubtotal($itemName), $subtotal);
418
    }
419
420
    /**
421
     * @Then /^(its) discount should be ([^"]+)$/
422
     */
423
    public function theItemShouldHaveDiscount($itemName, $discount)
424
    {
425
        Assert::eq($this->showPage->getItemDiscount($itemName), $discount);
426
    }
427
428
    /**
429
     * @Then /^(its) tax should be ([^"]+)$/
430
     */
431
    public function itemTaxShouldBe($itemName, $tax)
432
    {
433
        Assert::eq($this->showPage->getItemTax($itemName), $tax);
434
    }
435
436
    /**
437
     * @Then /^(its) tax included in price should be ([^"]+)$/
438
     */
439
    public function itsTaxIncludedInPriceShouldBe(string $itemName, string $tax): void
440
    {
441
        Assert::same($this->showPage->getItemTaxIncludedInPrice($itemName), $tax);
442
    }
443
444
    /**
445
     * @Then /^(its) total should be ([^"]+)$/
446
     */
447
    public function itemTotalShouldBe($itemName, $total)
448
    {
449
        Assert::eq($this->showPage->getItemTotal($itemName), $total);
450
    }
451
452
    /**
453
     * @Then I should be notified that the order's payment has been successfully completed
454
     */
455
    public function iShouldBeNotifiedThatTheOrderSPaymentHasBeenSuccessfullyCompleted()
456
    {
457
        $this->notificationChecker->checkNotification(
458
            'Payment has been successfully updated.',
459
            NotificationType::success()
460
        );
461
    }
462
463
    /**
464
     * @Then I should be notified that the order's payment has been successfully refunded
465
     */
466
    public function iShouldBeNotifiedThatTheOrderSPaymentHasBeenSuccessfullyRefunded()
467
    {
468
        $this->notificationChecker->checkNotification(
469
            'Payment has been successfully refunded.',
470
            NotificationType::success()
471
        );
472
    }
473
474
    /**
475
     * @Then it should have payment state :paymentState
476
     * @Then it should have payment with state :paymentState
477
     */
478
    public function itShouldHavePaymentState($paymentState)
479
    {
480
        Assert::true($this->showPage->hasPayment($paymentState));
481
    }
482
483
    /**
484
     * @Then it should have order's payment state :orderPaymentState
485
     */
486
    public function itShouldHaveOrderPaymentState($orderPaymentState)
487
    {
488
        Assert::same($this->showPage->getPaymentState(), $orderPaymentState);
489
    }
490
491
    /**
492
     * @Then it should have order's shipping state :orderShippingState
493
     */
494
    public function itShouldHaveOrderShippingState($orderShippingState)
495
    {
496
        Assert::same($this->showPage->getShippingState(), $orderShippingState);
497
    }
498
499
    /**
500
     * @Then it's payment state should be refunded
501
     */
502
    public function orderPaymentStateShouldBeRefunded()
503
    {
504
        Assert::same($this->showPage->getPaymentState(), 'Refunded');
505
    }
506
507
    /**
508
     * @Then /^I should not be able to mark (this order) as paid again$/
509
     */
510
    public function iShouldNotBeAbleToFinalizeItsPayment(OrderInterface $order)
511
    {
512
        Assert::false($this->showPage->canCompleteOrderLastPayment($order));
513
    }
514
515
    /**
516
     * @Then I should be notified that the order has been successfully shipped
517
     */
518
    public function iShouldBeNotifiedThatTheOrderHasBeenSuccessfullyShipped()
519
    {
520
        $this->notificationChecker->checkNotification(
521
            'Shipment has been successfully updated.',
522
            NotificationType::success()
523
        );
524
    }
525
526
    /**
527
     * @Then /^I should not be able to ship (this order)$/
528
     */
529
    public function iShouldNotBeAbleToShipThisOrder(OrderInterface $order)
530
    {
531
        Assert::false($this->showPage->canShipOrder($order));
532
    }
533
534
    /**
535
     * @When I cancel this order
536
     */
537
    public function iCancelThisOrder()
538
    {
539
        $this->showPage->cancelOrder();
540
    }
541
542
    /**
543
     * @Then I should be notified that it has been successfully updated
544
     */
545
    public function iShouldBeNotifiedAboutItHasBeenSuccessfullyCanceled()
546
    {
547
        $this->notificationChecker->checkNotification(
548
            'Order has been successfully updated.',
549
            NotificationType::success()
550
        );
551
    }
552
553
    /**
554
     * @Then I should not be able to cancel this order
555
     */
556
    public function iShouldNotBeAbleToCancelThisOrder()
557
    {
558
        Assert::false($this->showPage->hasCancelButton());
559
    }
560
561
    /**
562
     * @Then this order should have state :state
563
     * @Then its state should be :state
564
     */
565
    public function itsStateShouldBe($state)
566
    {
567
        Assert::same($this->showPage->getOrderState(), $state);
568
    }
569
570
    /**
571
     * @Then it should( still) have a :state state
572
     */
573
    public function itShouldHaveState($state)
574
    {
575
        Assert::true($this->indexPage->isSingleResourceOnPage(['state' => $state]));
576
    }
577
578
    /**
579
     * @Then /^(the administrator) should know about (this additional note) for (this order made by "[^"]+")$/
580
     */
581
    public function theCustomerServiceShouldKnowAboutThisAdditionalNotes(
582
        AdminUserInterface $user,
583
        $note,
584
        OrderInterface $order
585
    ) {
586
        $this->sharedSecurityService->performActionAsAdminUser(
587
            $user,
588
            function () use ($note, $order) {
589
                $this->showPage->open(['id' => $order->getId()]);
590
591
                Assert::true($this->showPage->hasNote($note));
592
            }
593
        );
594
    }
595
596
    /**
597
     * @Then I should see an order with :orderNumber number
598
     */
599
    public function iShouldSeeOrderWithNumber($orderNumber)
600
    {
601
        Assert::true($this->indexPage->isSingleResourceOnPage(['number' => $orderNumber]));
602
    }
603
604
    /**
605
     * @Then I should not see an order with :orderNumber number
606
     */
607
    public function iShouldNotSeeOrderWithNumber($orderNumber)
608
    {
609
        Assert::false($this->indexPage->isSingleResourceOnPage(['number' => $orderNumber]));
610
    }
611
612
    /**
613
     * @Then I should not see any orders with currency :currencyCode
614
     */
615
    public function iShouldNotSeeAnyOrderWithCurrency($currencyCode)
616
    {
617
        Assert::false($this->indexPage->isSingleResourceOnPage(['currencyCode' => $currencyCode]));
618
    }
619
620
    /**
621
     * @Then the first order should have number :number
622
     */
623
    public function theFirstOrderShouldHaveNumber($number)
624
    {
625
        Assert::eq($this->indexPage->getColumnFields('number')[0], $number);
626
    }
627
628
    /**
629
     * @Then it should have shipment in state :shipmentState
630
     */
631
    public function itShouldHaveShipmentState($shipmentState)
632
    {
633
        Assert::true($this->showPage->hasShipment($shipmentState));
634
    }
635
636
    /**
637
     * @Then order :orderNumber should have shipment state :shippingState
638
     */
639
    public function thisOrderShipmentStateShouldBe($shippingState)
640
    {
641
        Assert::true($this->indexPage->isSingleResourceOnPage(['shippingState' => $shippingState]));
642
    }
643
644
    /**
645
     * @Then the order :order should have order payment state :orderPaymentState
646
     * @Then /^(this order) should have order payment state "([^"]+)"$/
647
     */
648
    public function theOrderShouldHavePaymentState(OrderInterface $order, $orderPaymentState)
649
    {
650
        Assert::true($this->indexPage->isSingleResourceOnPage(['paymentState' => $orderPaymentState]));
651
    }
652
653
    /**
654
     * @Then the order :order should have order shipping state :orderShippingState
655
     * @Then /^(this order) should have order shipping state "([^"]+)"$/
656
     */
657
    public function theOrderShouldHaveShippingState(OrderInterface $order, $orderShippingState)
658
    {
659
        Assert::true($this->indexPage->isSingleResourceOnPage(['shippingState' => $orderShippingState]));
660
    }
661
662
    /**
663
     * @Then /^there should be(?:| only) (\d+) payments?$/
664
     */
665
    public function theOrderShouldHaveNumberOfPayments($number)
666
    {
667
        Assert::same($this->showPage->getPaymentsCount(), (int) $number);
668
    }
669
670
    /**
671
     * @Then I should see the order :orderNumber with total :total
672
     */
673
    public function iShouldSeeTheOrderWithTotal($orderNumber, $total)
674
    {
675
        Assert::true($this->indexPage->isSingleResourceOnPage(['total' => $total]));
676
    }
677
678
    /**
679
     * @When /^I want to modify a customer's (?:billing|shipping) address of (this order)$/
680
     */
681
    public function iWantToModifyACustomerSShippingAddress(OrderInterface $order)
682
    {
683
        $this->updatePage->open(['id' => $order->getId()]);
684
    }
685
686
    /**
687
     * @When I save my changes
688
     * @When I try to save my changes
689
     */
690
    public function iSaveMyChanges()
691
    {
692
        $this->updatePage->saveChanges();
693
    }
694
695
    /**
696
     * @When /^I specify their (?:|new )shipping (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/
697
     */
698
    public function iSpecifyTheirShippingAddressAsFor(AddressInterface $address)
699
    {
700
        $this->updatePage->specifyShippingAddress($address);
701
    }
702
703
    /**
704
     * @When /^I specify their (?:|new )billing (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/
705
     */
706
    public function iSpecifyTheirBillingAddressAsFor(AddressInterface $address)
707
    {
708
        $this->updatePage->specifyBillingAddress($address);
709
    }
710
711
    /**
712
     * @Then /^I should be notified that the "([^"]+)", the "([^"]+)", the "([^"]+)" and the "([^"]+)" in (shipping|billing) details are required$/
713
     */
714
    public function iShouldBeNotifiedThatTheAndTheInShippingDetailsAreRequired($firstElement, $secondElement, $thirdElement, $fourthElement, $type)
715
    {
716
        $this->assertElementValidationMessage($type, $firstElement, sprintf('Please enter %s.', $firstElement));
717
        $this->assertElementValidationMessage($type, $secondElement, sprintf('Please enter %s.', $secondElement));
718
        $this->assertElementValidationMessage($type, $thirdElement, sprintf('Please enter %s.', $thirdElement));
719
        $this->assertElementValidationMessage($type, $fourthElement, sprintf('Please enter %s.', $fourthElement));
720
    }
721
722
    /**
723
     * @Then I should see :provinceName as province in the shipping address
724
     */
725
    public function iShouldSeeAsProvinceInTheShippingAddress($provinceName)
726
    {
727
        Assert::true($this->showPage->hasShippingProvinceName($provinceName));
728
    }
729
730
    /**
731
     * @Then I should see :provinceName ad province in the billing address
732
     */
733
    public function iShouldSeeAdProvinceInTheBillingAddress($provinceName)
734
    {
735
        Assert::true($this->showPage->hasBillingProvinceName($provinceName));
736
    }
737
738
    /**
739
     * @Then /^(the administrator) should know about IP address of (this order made by "[^"]+")$/
740
     */
741
    public function theAdministratorShouldKnowAboutIPAddressOfThisOrderMadeBy(
742
        AdminUserInterface $user,
743
        OrderInterface $order
744
    ) {
745
        $this->sharedSecurityService->performActionAsAdminUser(
746
            $user,
747
            function () use ($order) {
748
                $this->showPage->open(['id' => $order->getId()]);
749
750
                Assert::notSame($this->showPage->getIpAddressAssigned(), '');
751
            }
752
        );
753
    }
754
755
    /**
756
     * @When /^I (clear old billing address) information$/
757
     */
758
    public function iSpecifyTheBillingAddressAs(AddressInterface $address)
759
    {
760
        $this->updatePage->specifyBillingAddress($address);
761
    }
762
763
    /**
764
     * @When /^I (clear old shipping address) information$/
765
     */
766
    public function iSpecifyTheShippingAddressAs(AddressInterface $address)
767
    {
768
        $this->updatePage->specifyShippingAddress($address);
769
    }
770
771
    /**
772
     * @When /^I do not specify new information$/
773
     */
774
    public function iDoNotSpecifyNewInformation()
775
    {
776
        // Intentionally left blank to fulfill context expectation
777
    }
778
779
    /**
780
     * @Then /^(the administrator) should see that (order placed by "[^"]+") has "([^"]+)" currency$/
781
     */
782
    public function theAdministratorShouldSeeThatThisOrderHasBeenPlacedIn(AdminUserInterface $user, OrderInterface $order, $currency)
783
    {
784
        $this->sharedSecurityService->performActionAsAdminUser($user, function () use ($order, $currency) {
785
            $this->showPage->open(['id' => $order->getId()]);
786
787
            Assert::same($this->showPage->getOrderCurrency(), $currency);
788
        });
789
    }
790
791
    /**
792
     * @Then /^(the administrator) should see the order with total "([^"]+)" in order list$/
793
     */
794
    public function theAdministratorShouldSeeTheOrderWithTotalInOrderList(AdminUserInterface $user, $total)
795
    {
796
        $this->sharedSecurityService->performActionAsAdminUser($user, function () use ($total) {
797
            $this->indexPage->open();
798
799
            Assert::true($this->indexPage->isSingleResourceOnPage(['total' => $total]));
800
        });
801
    }
802
803
    /**
804
     * @Then there should be :count changes in the registry
805
     */
806
    public function thereShouldBeCountChangesInTheRegistry($count)
807
    {
808
        Assert::same($this->historyPage->countShippingAddressChanges(), (int) $count);
809
    }
810
811
    /**
812
     * @Then I should not be able to refund this payment
813
     */
814
    public function iShouldNotBeAbleToRefundThisPayment()
815
    {
816
        Assert::false($this->showPage->hasRefundButton());
817
    }
818
819
    /**
820
     * @Then I should not see information about shipments
821
     */
822
    public function iShouldNotSeeInformationAboutShipments(): void
823
    {
824
        Assert::same($this->showPage->getShipmentsCount(), 0);
825
    }
826
827
    /**
828
     * @Then the :productName product's unit price should be :price
829
     */
830
    public function productUnitPriceShouldBe(string $productName, string $price): void
831
    {
832
        Assert::same($this->showPage->getItemUnitPrice($productName), $price);
833
    }
834
835
    /**
836
     * @Then the :productName product's item discount should be :price
837
     */
838
    public function productItemDiscountShouldBe(string $productName, string $price): void
839
    {
840
        Assert::same($this->showPage->getItemDiscount($productName), $price);
841
    }
842
843
    /**
844
     * @Then the :productName product's order discount should be :price
845
     */
846
    public function productOrderDiscountShouldBe(string $productName, string $price): void
847
    {
848
        Assert::same($this->showPage->getItemOrderDiscount($productName), $price);
849
    }
850
851
    /**
852
     * @Then the :productName product's quantity should be :quantity
853
     */
854
    public function productQuantityShouldBe(string $productName, string $quantity): void
855
    {
856
        Assert::same($this->showPage->getItemQuantity($productName), $quantity);
857
    }
858
859
    /**
860
     * @Then the :productName product's subtotal should be :subTotal
861
     */
862
    public function productSubtotalShouldBe(string $productName, string $subTotal): void
863
    {
864
        Assert::same($this->showPage->getItemSubtotal($productName), $subTotal);
865
    }
866
867
    /**
868
     * @Then the :productName product's discounted unit price should be :price
869
     */
870
    public function productDiscountedUnitPriceShouldBe(string $productName, string $price): void
871
    {
872
        Assert::same($this->showPage->getItemDiscountedUnitPrice($productName), $price);
873
    }
874
875
    /**
876
     * @Then I should be informed that there are no payments
877
     */
878
    public function iShouldSeeInformationAboutNoPayments(): void
879
    {
880
        Assert::same($this->showPage->getPaymentsCount(), 0);
881
        Assert::true($this->showPage->hasInformationAboutNoPayment());
882
    }
883
884
    /**
885
     * @param string $type
886
     * @param string $element
887
     * @param string $expectedMessage
888
     *
889
     * @throws \InvalidArgumentException
890
     */
891
    private function assertElementValidationMessage($type, $element, $expectedMessage)
892
    {
893
        $element = sprintf('%s_%s', $type, str_replace(' ', '_', $element));
894
        Assert::true($this->updatePage->checkValidationMessageFor($element, $expectedMessage));
895
    }
896
}
897