Completed
Push — assert-overflow ( 0688b3...fbf83a )
by Kamil
66:00 queued 44:43
created

theOrdersShippingPromotionDiscountShouldBe()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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\Admin;
13
14
use Behat\Behat\Context\Context;
15
use Sylius\Behat\NotificationType;
16
use Sylius\Behat\Page\Admin\Order\HistoryPageInterface;
17
use Sylius\Behat\Page\Admin\Order\IndexPageInterface;
18
use Sylius\Behat\Page\Admin\Order\ShowPageInterface;
19
use Sylius\Behat\Page\Admin\Order\UpdatePageInterface;
20
use Sylius\Behat\Service\NotificationCheckerInterface;
21
use Sylius\Behat\Service\SharedSecurityServiceInterface;
22
use Sylius\Behat\Service\SharedStorageInterface;
23
use Sylius\Component\Addressing\Model\AddressInterface;
24
use Sylius\Component\Core\Model\AdminUserInterface;
25
use Sylius\Component\Core\Model\CustomerInterface;
26
use Sylius\Component\Core\Model\OrderInterface;
27
use Webmozart\Assert\Assert;
28
29
/**
30
 * @author Paweł Jędrzejewski <[email protected]>
31
 * @author Grzegorz Sadowski <[email protected]>
32
 */
33
final class ManagingOrdersContext implements Context
34
{
35
    /**
36
     * @var SharedStorageInterface
37
     */
38
    private $sharedStorage;
39
40
    /**
41
     * @var IndexPageInterface
42
     */
43
    private $indexPage;
44
45
    /**
46
     * @var ShowPageInterface
47
     */
48
    private $showPage;
49
50
    /**
51
     * @var UpdatePageInterface
52
     */
53
    private $updatePage;
54
55
    /**
56
     * @var HistoryPageInterface
57
     */
58
    private $historyPage;
59
60
    /**
61
     * @var NotificationCheckerInterface
62
     */
63
    private $notificationChecker;
64
65
    /**
66
     * @var SharedSecurityServiceInterface
67
     */
68
    private $sharedSecurityService;
69
70
    /**
71
     * @param SharedStorageInterface $sharedStorage
72
     * @param IndexPageInterface $indexPage
73
     * @param ShowPageInterface $showPage
74
     * @param UpdatePageInterface $updatePage
75
     * @param HistoryPageInterface $historyPage
76
     * @param NotificationCheckerInterface $notificationChecker
77
     * @param SharedSecurityServiceInterface $sharedSecurityService
78
     */
79
    public function __construct(
80
        SharedStorageInterface $sharedStorage,
81
        IndexPageInterface $indexPage,
82
        ShowPageInterface $showPage,
83
        UpdatePageInterface $updatePage,
84
        HistoryPageInterface $historyPage,
85
        NotificationCheckerInterface $notificationChecker,
86
        SharedSecurityServiceInterface $sharedSecurityService
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $sharedSecurityService exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
87
    ) {
88
        $this->sharedStorage = $sharedStorage;
89
        $this->indexPage = $indexPage;
90
        $this->showPage = $showPage;
91
        $this->updatePage = $updatePage;
92
        $this->historyPage = $historyPage;
93
        $this->notificationChecker = $notificationChecker;
94
        $this->sharedSecurityService = $sharedSecurityService;
95
    }
96
97
    /**
98
     * @Given I am browsing orders
99
     * @When I browse orders
100
     */
101
    public function iBrowseOrders()
102
    {
103
        $this->indexPage->open();
104
    }
105
106
    /**
107
     * @When I browse order's :order history
108
     */
109
    public function iBrowseOrderHistory(OrderInterface $order)
110
    {
111
        $this->historyPage->open(['id' => $order->getId()]);
112
    }
113
114
    /**
115
     * @Given /^I am viewing the summary of (this order)$/
116
     * @When I view the summary of the order :order
117
     */
118
    public function iSeeTheOrder(OrderInterface $order)
119
    {
120
        $this->showPage->open(['id' => $order->getId()]);
121
    }
122
123
    /**
124
     * @When /^I mark (this order) as paid$/
125
     */
126
    public function iMarkThisOrderAsAPaid(OrderInterface $order)
127
    {
128
        $this->showPage->completeOrderLastPayment($order);
129
    }
130
131
    /**
132
     * @When /^I mark (this order)'s payment as refunded$/
133
     */
134
    public function iMarkThisOrderSPaymentAsRefunded(OrderInterface $order)
135
    {
136
        $this->showPage->refundOrderLastPayment($order);
137
    }
138
139
    /**
140
     * @When specify its tracking code as :trackingCode
141
     */
142
    public function specifyItsTrackingCodeAs($trackingCode)
143
    {
144
        $this->showPage->specifyTrackingCode($trackingCode);
145
        $this->sharedStorage->set('tracking_code', $trackingCode);
146
    }
147
148
    /**
149
     * @When /^I ship (this order)$/
150
     */
151
    public function iShipThisOrder(OrderInterface $order)
152
    {
153
        $this->showPage->shipOrder($order);
154
    }
155
156
    /**
157
     * @When I switch the way orders are sorted by :fieldName
158
     */
159
    public function iSwitchSortingBy($fieldName)
160
    {
161
        $this->indexPage->sortBy($fieldName);
162
    }
163
164
    /**
165
     * @When I specify filter date from as :dateTime
166
     */
167
    public function iSpecifyFilterDateFromAs($dateTime)
168
    {
169
        $this->indexPage->specifyFilterDateFrom(new \DateTime($dateTime));
170
    }
171
172
    /**
173
     * @When I specify filter date to as :dateTime
174
     */
175
    public function iSpecifyFilterDateToAs($dateTime)
176
    {
177
        $this->indexPage->specifyFilterDateTo(new \DateTime($dateTime));
178
    }
179
180
    /**
181
     * @When I choose :channelName as a channel filter
182
     */
183
    public function iChooseChannelAsAChannelFilter($channelName)
184
    {
185
        $this->indexPage->chooseChannelFilter($channelName);
186
    }
187
188
    /**
189
     * @When I choose :currencyName as the filter currency
190
     */
191
    public function iChooseCurrencyAsTheFilterCurrency($currencyName)
192
    {
193
        $this->indexPage->chooseCurrencyFilter($currencyName);
194
    }
195
196
    /**
197
     * @When I specify filter total being greater than :total
198
     */
199
    public function iSpecifyFilterTotalBeingGreaterThan($total)
200
    {
201
        $this->indexPage->specifyFilterTotalGreaterThan($total);
202
    }
203
204
    /**
205
     * @When I specify filter total being less than :total
206
     */
207
    public function iSpecifyFilterTotalBeingLessThan($total)
208
    {
209
        $this->indexPage->specifyFilterTotalLessThan($total);
210
    }
211
212
    /**
213
     * @When I filter
214
     */
215
    public function iFilter()
216
    {
217
        $this->indexPage->filter();
218
    }
219
220
    /**
221
     * @Then I should see a single order from customer :customer
222
     */
223
    public function iShouldSeeASingleOrderFromCustomer(CustomerInterface $customer)
224
    {
225
        Assert::true($this->indexPage->isSingleResourceOnPage(['customer' => $customer->getEmail()]));
226
    }
227
228
    /**
229
     * @Then it should have been placed by the customer :customerEmail
230
     */
231
    public function itShouldBePlacedByCustomer($customerEmail)
232
    {
233
        Assert::true($this->showPage->hasCustomer($customerEmail));
234
    }
235
236
    /**
237
     * @Then it should be shipped to :customerName, :street, :postcode, :city, :countryName
238
     * @Then /^(this order) should (?:|still )be shipped to "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)"$/
239
     */
240
    public function itShouldBeShippedTo(
241
        OrderInterface $order = null,
242
        $customerName,
0 ignored issues
show
Coding Style introduced by
Parameters which have default values should be placed at the end.

If you place a parameter with a default value before a parameter with a default value, the default value of the first parameter will never be used as it will always need to be passed anyway:

// $a must always be passed; it's default value is never used.
function someFunction($a = 5, $b) { }
Loading history...
243
        $street,
244
        $postcode,
245
        $city,
246
        $countryName
247
    ) {
248
        if (null !== $order) {
249
            $this->iSeeTheOrder($order);
250
        }
251
252
        Assert::true($this->showPage->hasShippingAddress($customerName, $street, $postcode, $city, $countryName));
253
    }
254
255
    /**
256
     * @Then it should be billed to :customerName, :street, :postcode, :city, :countryName
257
     * @Then the order should be billed to :customerName, :street, :postcode, :city, :countryName
258
     * @Then /^(this order) bill should (?:|still )be shipped to "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)"$/
259
     */
260
    public function itShouldBeBilledTo(
261
        OrderInterface $order = null,
262
        $customerName,
0 ignored issues
show
Coding Style introduced by
Parameters which have default values should be placed at the end.

If you place a parameter with a default value before a parameter with a default value, the default value of the first parameter will never be used as it will always need to be passed anyway:

// $a must always be passed; it's default value is never used.
function someFunction($a = 5, $b) { }
Loading history...
263
        $street,
264
        $postcode,
265
        $city,
266
        $countryName
267
    ) {
268
        if (null !== $order) {
269
            $this->iSeeTheOrder($order);
270
        }
271
272
        Assert::true($this->showPage->hasBillingAddress($customerName, $street, $postcode, $city, $countryName));
273
    }
274
275
    /**
276
     * @Then it should be shipped via the :shippingMethodName shipping method
277
     */
278
    public function itShouldBeShippedViaShippingMethod($shippingMethodName)
279
    {
280
        Assert::true($this->showPage->hasShipment($shippingMethodName));
281
    }
282
283
    /**
284
     * @Then it should be paid with :paymentMethodName
285
     */
286
    public function itShouldBePaidWith($paymentMethodName)
287
    {
288
        Assert::true($this->showPage->hasPayment($paymentMethodName));
289
    }
290
291
    /**
292
     * @Then /^it should have (\d+) items$/
293
     * @Then I should see :amount orders in the list
294
     * @Then I should see a single order in the list
295
     */
296
    public function itShouldHaveAmountOfItems($amount = 1)
297
    {
298
        Assert::same($this->showPage->countItems(), (int) $amount);
299
    }
300
301
    /**
302
     * @Then the product named :productName should be in the items list
303
     */
304
    public function theProductShouldBeInTheItemsList($productName)
305
    {
306
        Assert::true($this->showPage->isProductInTheList($productName));
307
    }
308
309
    /**
310
     * @Then the order's items total should be :itemsTotal
311
     */
312
    public function theOrdersItemsTotalShouldBe($itemsTotal)
313
    {
314
        Assert::eq($this->showPage->getItemsTotal(), $itemsTotal);
315
    }
316
317
    /**
318
     * @Then /^the order's total should(?:| still) be "([^"]+)"$/
319
     */
320
    public function theOrdersTotalShouldBe($total)
321
    {
322
        Assert::eq($this->showPage->getTotal(), $total);
323
    }
324
325
    /**
326
     * @Then there should be a shipping charge :shippingCharge
327
     */
328
    public function theOrdersShippingChargesShouldBe($shippingCharge)
329
    {
330
        Assert::true($this->showPage->hasShippingCharge($shippingCharge));
331
    }
332
333
    /**
334
     * @Then the order's shipping total should be :shippingTotal
335
     */
336
    public function theOrdersShippingTotalShouldBe($shippingTotal)
337
    {
338
        Assert::eq($this->showPage->getShippingTotal(), $shippingTotal);
339
    }
340
341
    /**
342
     * @Then the order's payment should (also) be :paymentAmount
343
     */
344
    public function theOrdersPaymentShouldBe($paymentAmount)
345
    {
346
        Assert::eq($this->showPage->getPaymentAmount(), $paymentAmount);
347
    }
348
349
    /**
350
     * @Then the order should have tax :tax
351
     */
352
    public function theOrderShouldHaveTax($tax)
353
    {
354
        Assert::true($this->showPage->hasTax($tax));
355
    }
356
357
    /**
358
     * @Then /^the order's tax total should(?:| still) be "([^"]+)"$/
359
     */
360
    public function theOrdersTaxTotalShouldBe($taxTotal)
361
    {
362
        Assert::eq($this->showPage->getTaxTotal(), $taxTotal);
363
    }
364
365
    /**
366
     * @Then the order's promotion discount should be :promotionDiscount
367
     */
368
    public function theOrdersPromotionDiscountShouldBe($promotionDiscount)
369
    {
370
        Assert::true($this->showPage->hasPromotionDiscount($promotionDiscount));
371
    }
372
373
    /**
374
     * @Then the order's shipping promotion should be :promotion
375
     */
376
    public function theOrdersShippingPromotionDiscountShouldBe($promotionData)
377
    {
378
        Assert::same($this->showPage->getShippingPromotionData(), $promotionData);
379
    }
380
381
    /**
382
     * @Then /^the order's promotion total should(?:| still) be "([^"]+)"$/
383
     */
384
    public function theOrdersPromotionTotalShouldBe($promotionTotal)
385
    {
386
        Assert::eq($this->showPage->getPromotionTotal(), $promotionTotal);
387
    }
388
389
    /**
390
     * @When I check :itemName data
391
     */
392
    public function iCheckData($itemName)
393
    {
394
        $this->sharedStorage->set('item', $itemName);
395
    }
396
397
    /**
398
     * @Then /^(its) code should be "([^"]+)"$/
399
     */
400
    public function itemCodeShouldBe($itemName, $code)
401
    {
402
        Assert::same($this->showPage->getItemCode($itemName), $code);
403
    }
404
405
    /**
406
     * @Then /^(its) unit price should be ([^"]+)$/
407
     */
408
    public function itemUnitPriceShouldBe($itemName, $unitPrice)
409
    {
410
        Assert::eq($this->showPage->getItemUnitPrice($itemName), $unitPrice);
411
    }
412
413
    /**
414
     * @Then /^(its) discounted unit price should be ([^"]+)$/
415
     */
416
    public function itemDiscountedUnitPriceShouldBe($itemName, $discountedUnitPrice)
417
    {
418
        Assert::eq($this->showPage->getItemDiscountedUnitPrice($itemName), $discountedUnitPrice);
419
    }
420
421
    /**
422
     * @Then /^(its) quantity should be ([^"]+)$/
423
     */
424
    public function itemQuantityShouldBe($itemName, $quantity)
425
    {
426
        Assert::eq($this->showPage->getItemQuantity($itemName), $quantity);
427
    }
428
429
    /**
430
     * @Then /^(its) subtotal should be ([^"]+)$/
431
     */
432
    public function itemSubtotalShouldBe($itemName, $subtotal)
433
    {
434
        Assert::eq($this->showPage->getItemSubtotal($itemName), $subtotal);
435
    }
436
437
    /**
438
     * @Then /^(its) discount should be ([^"]+)$/
439
     */
440
    public function theItemShouldHaveDiscount($itemName, $discount)
441
    {
442
        Assert::eq($this->showPage->getItemDiscount($itemName), $discount);
443
    }
444
445
    /**
446
     * @Then /^(its) tax should be ([^"]+)$/
447
     */
448
    public function itemTaxShouldBe($itemName, $tax)
449
    {
450
        Assert::eq($this->showPage->getItemTax($itemName), $tax);
451
    }
452
453
    /**
454
     * @Then /^(its) total should be ([^"]+)$/
455
     */
456
    public function itemTotalShouldBe($itemName, $total)
457
    {
458
        Assert::eq($this->showPage->getItemTotal($itemName), $total);
459
    }
460
461
    /**
462
     * @Then I should be notified that the order's payment has been successfully completed
463
     */
464
    public function iShouldBeNotifiedThatTheOrderSPaymentHasBeenSuccessfullyCompleted()
465
    {
466
        $this->notificationChecker->checkNotification(
467
            'Payment has been successfully updated.',
468
            NotificationType::success()
469
        );
470
    }
471
472
    /**
473
     * @Then I should be notified that the order's payment has been successfully refunded
474
     */
475
    public function iShouldBeNotifiedThatTheOrderSPaymentHasBeenSuccessfullyRefunded()
476
    {
477
        $this->notificationChecker->checkNotification(
478
            'Payment has been successfully refunded.',
479
            NotificationType::success()
480
        );
481
    }
482
483
    /**
484
     * @Then it should have payment state :paymentState
485
     * @Then it should have payment with state :paymentState
486
     */
487
    public function itShouldHavePaymentState($paymentState)
488
    {
489
        Assert::true($this->showPage->hasPayment($paymentState));
490
    }
491
492
    /**
493
     * @Then it should have order's payment state :orderPaymentState
494
     */
495
    public function itShouldHaveOrderPaymentState($orderPaymentState)
496
    {
497
        Assert::same($this->showPage->getPaymentState(), $orderPaymentState);
498
    }
499
500
    /**
501
     * @Then it's payment state should be refunded
502
     */
503
    public function orderPaymentStateShouldBeRefunded()
504
    {
505
        Assert::same($this->showPage->getPaymentState(), 'Refunded');
506
    }
507
508
    /**
509
     * @Then /^I should not be able to mark (this order) as paid again$/
510
     */
511
    public function iShouldNotBeAbleToFinalizeItsPayment(OrderInterface $order)
512
    {
513
        Assert::false($this->showPage->canCompleteOrderLastPayment($order));
514
    }
515
516
    /**
517
     * @Then I should be notified that the order has been successfully shipped
518
     */
519
    public function iShouldBeNotifiedThatTheOrderHasBeenSuccessfullyShipped()
520
    {
521
        $this->notificationChecker->checkNotification(
522
            'Shipment has been successfully updated.',
523
            NotificationType::success()
524
        );
525
    }
526
527
    /**
528
     * @Then /^I should not be able to ship (this order)$/
529
     */
530
    public function iShouldNotBeAbleToShipThisOrder(OrderInterface $order)
531
    {
532
        Assert::false($this->showPage->canShipOrder($order));
533
    }
534
535
    /**
536
     * @When I cancel this order
537
     */
538
    public function iCancelThisOrder()
539
    {
540
        $this->showPage->cancelOrder();
541
    }
542
543
    /**
544
     * @Then I should be notified that it has been successfully updated
545
     */
546
    public function iShouldBeNotifiedAboutItHasBeenSuccessfullyCanceled()
547
    {
548
        $this->notificationChecker->checkNotification(
549
            'Order has been successfully updated.',
550
            NotificationType::success()
551
        );
552
    }
553
554
    /**
555
     * @Then I should not be able to cancel this order
556
     */
557
    public function iShouldNotBeAbleToCancelThisOrder()
558
    {
559
        Assert::false($this->showPage->hasCancelButton());
560
    }
561
562
    /**
563
     * @Then this order should have state :state
564
     * @Then its state should be :state
565
     */
566
    public function itsStateShouldBe($state)
567
    {
568
        Assert::same($this->showPage->getOrderState(), $state);
569
    }
570
571
    /**
572
     * @Then it should( still) have a :state state
573
     */
574
    public function itShouldHaveState($state)
575
    {
576
        Assert::true($this->indexPage->isSingleResourceOnPage(['state' => $state]));
577
    }
578
579
    /**
580
     * @Then /^(the administrator) should know about (this additional note) for (this order made by "[^"]+")$/
581
     */
582
    public function theCustomerServiceShouldKnowAboutThisAdditionalNotes(
583
        AdminUserInterface $user,
584
        $note,
585
        OrderInterface $order
586
    ) {
587
        $this->sharedSecurityService->performActionAsAdminUser(
588
            $user,
589
            function () use ($note, $order) {
590
                $this->showPage->open(['id' => $order->getId()]);
591
592
                Assert::true($this->showPage->hasNote($note));
593
            }
594
        );
595
    }
596
597
    /**
598
     * @Then I should see an order with :orderNumber number
599
     */
600
    public function iShouldSeeOrderWithNumber($orderNumber)
601
    {
602
        Assert::true($this->indexPage->isSingleResourceOnPage(['number' => $orderNumber]));
603
    }
604
605
    /**
606
     * @Then I should not see an order with :orderNumber number
607
     */
608
    public function iShouldNotSeeOrderWithNumber($orderNumber)
609
    {
610
        Assert::false($this->indexPage->isSingleResourceOnPage(['number' => $orderNumber]));
611
    }
612
613
    /**
614
     * @Then I should not see any orders with currency :currencyCode
615
     */
616
    public function iShouldNotSeeAnyOrderWithCurrency($currencyCode)
617
    {
618
        Assert::false($this->indexPage->isSingleResourceOnPage(['currencyCode' => $currencyCode]));
619
    }
620
621
    /**
622
     * @Then the first order should have number :number
623
     */
624
    public function theFirstOrderShouldHaveNumber($number)
625
    {
626
        Assert::eq($this->indexPage->getColumnFields('number')[0], $number);
627
    }
628
629
    /**
630
     * @Then it should have shipment in state :shipmentState
631
     */
632
    public function itShouldHaveShipmentState($shipmentState)
633
    {
634
        Assert::true($this->showPage->hasShipment($shipmentState));
635
    }
636
637
    /**
638
     * @Then order :orderNumber should have shipment state :shippingState
639
     */
640
    public function thisOrderShipmentStateShouldBe($shippingState)
641
    {
642
        Assert::true($this->indexPage->isSingleResourceOnPage(['shippingState' => $shippingState]));
643
    }
644
645
    /**
646
     * @Then the order :order should have order payment state :orderPaymentState
647
     * @Then /^(this order) should have order payment state "([^"]+)"$/
648
     */
649
    public function theOrderShouldHavePaymentState(OrderInterface $order, $orderPaymentState)
0 ignored issues
show
Unused Code introduced by
The parameter $order is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
650
    {
651
        Assert::true($this->indexPage->isSingleResourceOnPage(['paymentState' => $orderPaymentState]));
652
    }
653
654
    /**
655
     * @Then /^(this order) should have order shipping state "([^"]+)"$/
656
     */
657
    public function theOrderShouldHaveShipmentState(OrderInterface $order, $orderShipmentState)
0 ignored issues
show
Unused Code introduced by
The parameter $order is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
658
    {
659
        Assert::true($this->indexPage->isSingleResourceOnPage(['shippingState' => $orderShipmentState]));
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)
0 ignored issues
show
Unused Code introduced by
The parameter $orderNumber is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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 payments
821
     */
822
    public function iShouldNotSeeInformationAboutPayments()
823
    {
824
        Assert::same($this->showPage->getPaymentsCount(), 0);
825
    }
826
827
    /**
828
     * @param string $type
829
     * @param string $element
830
     * @param string $expectedMessage
831
     *
832
     * @throws \InvalidArgumentException
833
     */
834
    private function assertElementValidationMessage($type, $element, $expectedMessage)
835
    {
836
        $element = sprintf('%s_%s', $type, implode('_', explode(' ', $element)));
837
        Assert::true($this->updatePage->checkValidationMessageFor($element, $expectedMessage));
838
    }
839
}
840