Completed
Push — upgrade-boilerplate ( 903b21 )
by Kamil
17:46
created

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