Completed
Push — pagerfanta-fix ( 187c46...923c07 )
by Kamil
25:06 queued 03:45
created

ManagingOrdersContext   D

Complexity

Total Complexity 80

Size/Duplication

Total Lines 942
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 10

Importance

Changes 0
Metric Value
wmc 80
lcom 3
cbo 10
dl 0
loc 942
rs 4.4444
c 0
b 0
f 0

78 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
A iBrowseOrders() 0 4 1
A iSeeTheOrder() 0 4 1
A iMarkThisOrderAsAPaid() 0 4 1
A iMarkThisOrderSPaymentAsRefunded() 0 4 1
A specifyItsTrackingCodeAs() 0 5 1
A iShipThisOrder() 0 4 1
A iSwitchSortingBy() 0 4 1
A iSpecifyFilterDateFromAs() 0 4 1
A iSpecifyFilterDateToAs() 0 4 1
A iChooseChannelAsAChannelFilter() 0 4 1
A iChooseCurrencyAsTheFilterCurrency() 0 4 1
A iSpecifyFilterTotalBeingGreaterThan() 0 4 1
A iSpecifyFilterTotalBeingLessThan() 0 4 1
A iFilter() 0 4 1
A iShouldSeeASingleOrderFromCustomer() 0 7 1
A itShouldBePlacedByCustomer() 0 7 1
A itShouldBeShippedTo() 0 17 2
A itShouldBeBilledTo() 0 17 2
A itShouldBeShippedViaShippingMethod() 0 7 1
A itShouldBePaidWith() 0 7 1
A itShouldHaveAmountOfItems() 0 10 1
A theProductShouldBeInTheItemsList() 0 7 1
A theOrdersItemsTotalShouldBe() 0 10 1
A theOrdersTotalShouldBe() 0 10 1
A theOrdersShippingChargesShouldBe() 0 7 1
A theOrdersShippingTotalShouldBe() 0 10 1
A theOrdersPaymentShouldBe() 0 6 1
A theOrderShouldHaveTax() 0 7 1
A theOrdersTaxTotalShouldBe() 0 10 1
A theOrdersPromotionDiscountShouldBe() 0 7 1
A theOrdersPromotionTotalShouldBe() 0 10 1
A iCheckData() 0 4 1
A itemCodeShouldBe() 0 10 1
A itemUnitPriceShouldBe() 0 10 1
A itemDiscountedUnitPriceShouldBe() 0 10 1
A itemQuantityShouldBe() 0 10 1
A itemSubtotalShouldBe() 0 10 1
A theItemShouldHaveDiscount() 0 10 1
A itemTaxShouldBe() 0 10 1
A itemTotalShouldBe() 0 10 1
A iShouldBeNotifiedThatTheOrderSPaymentHasBeenSuccessfullyCompleted() 0 6 1
A iShouldBeNotifiedThatTheOrderSPaymentHasBeenSuccessfullyRefunded() 0 6 1
A itShouldHavePaymentState() 0 7 1
A orderPaymentStateShouldBeRefunded() 0 8 1
A iShouldNotBeAbleToFinalizeItsPayment() 0 7 1
A iShouldBeNotifiedThatTheOrderHasBeenSuccessfullyShipped() 0 7 1
A iShouldNotBeAbleToShipThisOrder() 0 7 1
A iCancelThisOrder() 0 4 1
A iShouldBeNotifiedAboutItHasBeenSuccessfullyCanceled() 0 7 1
A iShouldNotBeAbleToCancelThisOrder() 0 7 1
A itsStateShouldBe() 0 8 1
A itShouldHaveState() 0 7 1
A theCustomerServiceShouldKnowAboutThisAdditionalNotes() 0 13 1
A iShouldSeeOrderWithNumber() 0 7 1
A iShouldNotSeeOrderWithNumber() 0 7 1
A iShouldNotSeeAnyOrderWithCurrency() 0 7 1
A theFirstOrderShouldHaveNumber() 0 10 1
A itShouldHaveShipmentState() 0 7 1
A thisOrderShipmentStateShouldBe() 0 7 1
A theOrderShouldHavePaymentState() 0 7 1
A theOrderShouldHaveShipmentState() 0 7 1
A theOrderShouldHaveNumberOfPayments() 0 6 1
A iShouldSeeTheOrderWithTotal() 0 7 1
A iWantToModifyACustomerSShippingAddress() 0 4 1
A iSaveMyChanges() 0 4 1
A iSpecifyTheirShippingAddressAsFor() 0 4 1
A iSpecifyTheirBillingAddressAsFor() 0 4 1
A iShouldBeNotifiedThatTheAndTheInShippingDetailsAreRequired() 0 7 1
A iShouldSeeAsProvinceInTheShippingAddress() 0 7 1
A iShouldSeeAdProvinceInTheBillingAddress() 0 7 1
A theAdministratorShouldKnowAboutIPAddressOfThisOrderMadeBy() 0 17 1
A iSpecifyTheBillingAddressAs() 0 4 1
A iSpecifyTheShippingAddressAs() 0 4 1
A iDoNotSpecifyNewInformation() 0 4 1
A theAdministratorShouldSeeThatThisOrderHasBeenPlacedIn() 0 11 1
A theAdministratorShouldSeeTheOrderWithTotalInOrderList() 0 11 1
A assertElementValidationMessage() 0 8 1

How to fix   Complexity   

Complex Class

Complex classes like ManagingOrdersContext often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ManagingOrdersContext, and based on these observations, apply Extract Interface, too.

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 choose :currencyName as the filter currency
174
     */
175
    public function iChooseCurrencyAsTheFilterCurrency($currencyName)
176
    {
177
        $this->indexPage->chooseCurrencyFilter($currencyName);
178
    }
179
180
    /**
181
     * @When I specify filter total being greater than :total
182
     */
183
    public function iSpecifyFilterTotalBeingGreaterThan($total)
184
    {
185
        $this->indexPage->specifyFilterTotalGreaterThan($total);
186
    }
187
188
    /**
189
     * @When I specify filter total being less than :total
190
     */
191
    public function iSpecifyFilterTotalBeingLessThan($total)
192
    {
193
        $this->indexPage->specifyFilterTotalLessThan($total);
194
    }
195
196
    /**
197
     * @When I filter
198
     */
199
    public function iFilter()
200
    {
201
        $this->indexPage->filter();
202
    }
203
204
    /**
205
     * @Then I should see a single order from customer :customer
206
     */
207
    public function iShouldSeeASingleOrderFromCustomer(CustomerInterface $customer)
208
    {
209
        Assert::true(
210
            $this->indexPage->isSingleResourceOnPage(['customer' => $customer->getEmail()]),
211
            sprintf('Cannot find order for customer "%s" in the list.', $customer->getEmail())
212
        );
213
    }
214
215
    /**
216
     * @Then it should have been placed by the customer :customerEmail
217
     */
218
    public function itShouldBePlacedByCustomer($customerEmail)
219
    {
220
        Assert::true(
221
            $this->showPage->hasCustomer($customerEmail),
222
            sprintf('Cannot find customer "%s".', $customerEmail)
223
        );
224
    }
225
226
    /**
227
     * @Then it should be shipped to :customerName, :street, :postcode, :city, :countryName
228
     * @Then /^(this order) should (?:|still )be shipped to "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)"$/
229
     */
230
    public function itShouldBeShippedTo(
231
        OrderInterface $order = null,
232
        $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...
233
        $street,
234
        $postcode,
235
        $city,
236
        $countryName
237
    ) {
238
        if (null !== $order) {
239
            $this->iSeeTheOrder($order);
240
        }
241
242
        Assert::true(
243
            $this->showPage->hasShippingAddress($customerName, $street, $postcode, $city, $countryName),
244
            sprintf('Cannot find shipping address "%s, %s %s, %s".', $street, $postcode, $city, $countryName)
245
        );
246
    }
247
248
    /**
249
     * @Then it should be billed to :customerName, :street, :postcode, :city, :countryName
250
     * @Then /^(this order) bill should (?:|still )be shipped to "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)"$/
251
     */
252
    public function itShouldBeBilledTo(
253
        OrderInterface $order = null,
254
        $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...
255
        $street,
256
        $postcode,
257
        $city,
258
        $countryName
259
    ) {
260
        if (null !== $order) {
261
            $this->iSeeTheOrder($order);
262
        }
263
264
        Assert::true(
265
            $this->showPage->hasBillingAddress($customerName, $street, $postcode, $city, $countryName),
266
            sprintf('Cannot find shipping address "%s, %s %s, %s".', $street, $postcode, $city, $countryName)
267
        );
268
    }
269
270
    /**
271
     * @Then it should be shipped via the :shippingMethodName shipping method
272
     */
273
    public function itShouldBeShippedViaShippingMethod($shippingMethodName)
274
    {
275
        Assert::true(
276
            $this->showPage->hasShipment($shippingMethodName),
277
            sprintf('Cannot find shipment "%s".', $shippingMethodName)
278
        );
279
    }
280
281
    /**
282
     * @Then it should be paid with :paymentMethodName
283
     */
284
    public function itShouldBePaidWith($paymentMethodName)
285
    {
286
        Assert::true(
287
            $this->showPage->hasPayment($paymentMethodName),
288
            sprintf('Cannot find payment "%s".', $paymentMethodName)
289
        );
290
    }
291
292
    /**
293
     * @Then /^it should have (\d+) items$/
294
     * @Then I should see :amount orders in the list
295
     * @Then I should see a single order in the list
296
     */
297
    public function itShouldHaveAmountOfItems($amount = 1)
298
    {
299
        $itemsCount = $this->showPage->countItems();
300
301
        Assert::same(
302
            (int)$amount,
303
            $itemsCount,
304
            sprintf('There should be %d items, but get %d.', $amount, $itemsCount)
305
        );
306
    }
307
308
    /**
309
     * @Then the product named :productName should be in the items list
310
     */
311
    public function theProductShouldBeInTheItemsList($productName)
312
    {
313
        Assert::true(
314
            $this->showPage->isProductInTheList($productName),
315
            sprintf('Product %s is not in the item list.', $productName)
316
        );
317
    }
318
319
    /**
320
     * @Then the order's items total should be :itemsTotal
321
     */
322
    public function theOrdersItemsTotalShouldBe($itemsTotal)
323
    {
324
        $itemsTotalOnPage = $this->showPage->getItemsTotal();
325
326
        Assert::eq(
327
            $itemsTotalOnPage,
328
            $itemsTotal,
329
            'Items total is %s, but should be %s.'
330
        );
331
    }
332
333
    /**
334
     * @Then /^the order's total should(?:| still) be "([^"]+)"$/
335
     */
336
    public function theOrdersTotalShouldBe($total)
337
    {
338
        $totalOnPage = $this->showPage->getTotal();
339
340
        Assert::eq(
341
            $totalOnPage,
342
            $total,
343
            'Total is %s, but should be %s.'
344
        );
345
    }
346
347
    /**
348
     * @Then there should be a shipping charge :shippingCharge
349
     */
350
    public function theOrdersShippingChargesShouldBe($shippingCharge)
351
    {
352
        Assert::true(
353
            $this->showPage->hasShippingCharge($shippingCharge),
354
            sprintf('Shipping charges is not "%s".', $shippingCharge)
355
        );
356
    }
357
358
    /**
359
     * @Then the order's shipping total should be :shippingTotal
360
     */
361
    public function theOrdersShippingTotalShouldBe($shippingTotal)
362
    {
363
        $shippingTotalOnPage = $this->showPage->getShippingTotal();
364
365
        Assert::eq(
366
            $shippingTotal,
367
            $shippingTotalOnPage,
368
            sprintf('Shipping total is "%s", but should be "%s".', $shippingTotalOnPage, $shippingTotal)
369
        );
370
    }
371
372
    /**
373
     * @Then the order's payment should (also) be :paymentAmount
374
     */
375
    public function theOrdersPaymentShouldBe($paymentAmount)
376
    {
377
        $actualPaymentAmount = $this->showPage->getPaymentAmount();
378
379
        Assert::eq($paymentAmount, $actualPaymentAmount);
380
    }
381
382
    /**
383
     * @Then the order should have tax :tax
384
     */
385
    public function theOrderShouldHaveTax($tax)
386
    {
387
        Assert::true(
388
            $this->showPage->hasTax($tax),
389
            sprintf('Order should have tax "%s", but it does not.', $tax)
390
        );
391
    }
392
393
    /**
394
     * @Then /^the order's tax total should(?:| still) be "([^"]+)"$/
395
     */
396
    public function theOrdersTaxTotalShouldBe($taxTotal)
397
    {
398
        $taxTotalOnPage = $this->showPage->getTaxTotal();
399
400
        Assert::eq(
401
            $taxTotal,
402
            $taxTotalOnPage,
403
            sprintf('Tax total is "%s", but should be "%s".', $taxTotalOnPage, $taxTotal)
404
        );
405
    }
406
407
    /**
408
     * @Then the order's promotion discount should be :promotionDiscount
409
     */
410
    public function theOrdersPromotionDiscountShouldBe($promotionDiscount)
411
    {
412
        Assert::true(
413
            $this->showPage->hasPromotionDiscount($promotionDiscount),
414
            sprintf('Promotion discount is not "%s".', $promotionDiscount)
415
        );
416
    }
417
418
    /**
419
     * @Then /^the order's promotion total should(?:| still) be "([^"]+)"$/
420
     */
421
    public function theOrdersPromotionTotalShouldBe($promotionTotal)
422
    {
423
        $promotionTotalOnPage = $this->showPage->getPromotionTotal();
424
425
        Assert::eq(
426
            $promotionTotalOnPage,
427
            $promotionTotal,
428
            'Promotion total is %s, but should be %s.'
429
        );
430
    }
431
432
    /**
433
     * @When I check :itemName data
434
     */
435
    public function iCheckData($itemName)
436
    {
437
        $this->sharedStorage->set('item', $itemName);
438
    }
439
440
    /**
441
     * @Then /^(its) code should be "([^"]+)"$/
442
     */
443
    public function itemCodeShouldBe($itemName, $code)
444
    {
445
        $itemCodeOnPage = $this->showPage->getItemCode($itemName);
446
447
        Assert::same(
448
            $itemCodeOnPage,
449
            $code,
450
            'Item code is %s, but should be %s.'
451
        );
452
    }
453
454
    /**
455
     * @Then /^(its) unit price should be ([^"]+)$/
456
     */
457
    public function itemUnitPriceShouldBe($itemName, $unitPrice)
458
    {
459
        $itemUnitPriceOnPage = $this->showPage->getItemUnitPrice($itemName);
460
461
        Assert::eq(
462
            $itemUnitPriceOnPage,
463
            $unitPrice,
464
            'Item unit price is %s, but should be %s.'
465
        );
466
    }
467
468
    /**
469
     * @Then /^(its) discounted unit price should be ([^"]+)$/
470
     */
471
    public function itemDiscountedUnitPriceShouldBe($itemName, $discountedUnitPrice)
472
    {
473
        $itemUnitPriceOnPage = $this->showPage->getItemDiscountedUnitPrice($itemName);
474
475
        Assert::eq(
476
            $itemUnitPriceOnPage,
477
            $discountedUnitPrice,
478
            'Item discounted unit price is %s, but should be %s.'
479
        );
480
    }
481
482
    /**
483
     * @Then /^(its) quantity should be ([^"]+)$/
484
     */
485
    public function itemQuantityShouldBe($itemName, $quantity)
486
    {
487
        $itemQuantityOnPage = $this->showPage->getItemQuantity($itemName);
488
489
        Assert::eq(
490
            $itemQuantityOnPage,
491
            $quantity,
492
            'Item quantity is %s, but should be %s.'
493
        );
494
    }
495
496
    /**
497
     * @Then /^(its) subtotal should be ([^"]+)$/
498
     */
499
    public function itemSubtotalShouldBe($itemName, $subtotal)
500
    {
501
        $itemSubtotalOnPage = $this->showPage->getItemSubtotal($itemName);
502
503
        Assert::eq(
504
            $itemSubtotalOnPage,
505
            $subtotal,
506
            'Item subtotal is %s, but should be %s.'
507
        );
508
    }
509
510
    /**
511
     * @Then /^(its) discount should be ([^"]+)$/
512
     * @Then the :itemName should have :discount discount
513
     */
514
    public function theItemShouldHaveDiscount($itemName, $discount)
515
    {
516
        $itemDiscountOnPage = $this->showPage->getItemDiscount($itemName);
517
518
        Assert::eq(
519
            $itemDiscountOnPage,
520
            $discount,
521
            'Item discount is %s, but should be %s.'
522
        );
523
    }
524
525
    /**
526
     * @Then /^(its) tax should be ([^"]+)$/
527
     */
528
    public function itemTaxShouldBe($itemName, $tax)
529
    {
530
        $itemTaxOnPage = $this->showPage->getItemTax($itemName);
531
532
        Assert::eq(
533
            $itemTaxOnPage,
534
            $tax,
535
            'Item tax is %s, but should be %s.'
536
        );
537
    }
538
539
    /**
540
     * @Then /^(its) total should be ([^"]+)$/
541
     */
542
    public function itemTotalShouldBe($itemName, $total)
543
    {
544
        $itemTotalOnPage = $this->showPage->getItemTotal($itemName);
545
546
        Assert::eq(
547
            $itemTotalOnPage,
548
            $total,
549
            'Item total is %s, but should be %s.'
550
        );
551
    }
552
553
    /**
554
     * @Then I should be notified that the order's payment has been successfully completed
555
     */
556
    public function iShouldBeNotifiedThatTheOrderSPaymentHasBeenSuccessfullyCompleted()
557
    {
558
        $this
559
            ->notificationChecker
560
            ->checkNotification('Payment has been successfully updated.', NotificationType::success());
561
    }
562
563
    /**
564
     * @Then I should be notified that the order's payment has been successfully refunded
565
     */
566
    public function iShouldBeNotifiedThatTheOrderSPaymentHasBeenSuccessfullyRefunded()
567
    {
568
        $this
569
            ->notificationChecker
570
            ->checkNotification('Payment has been successfully refunded.', NotificationType::success());
571
    }
572
573
    /**
574
     * @Then it should have payment state :paymentState
575
     * @Then it should have payment with state :paymentState
576
     */
577
    public function itShouldHavePaymentState($paymentState)
578
    {
579
        Assert::true(
580
            $this->showPage->hasPayment($paymentState),
581
            sprintf('It should have payment with %s state', $paymentState)
582
        );
583
    }
584
585
    /**
586
     * @Then it's payment state should be refunded
587
     */
588
    public function orderPaymentStateShouldBeRefunded()
589
    {
590
        Assert::same(
591
            $this->showPage->getPaymentState(),
592
            'Refunded',
593
            'Order payment state should be refunded, but it is not.'
594
        );
595
    }
596
597
    /**
598
     * @Then /^I should not be able to mark (this order) as paid again$/
599
     */
600
    public function iShouldNotBeAbleToFinalizeItsPayment(OrderInterface $order)
601
    {
602
        Assert::false(
603
            $this->showPage->canCompleteOrderLastPayment($order),
604
            'It should not have complete payment button.'
605
        );
606
    }
607
608
    /**
609
     * @Then I should be notified that the order has been successfully shipped
610
     */
611
    public function iShouldBeNotifiedThatTheOrderHasBeenSuccessfullyShipped()
612
    {
613
        $this->notificationChecker->checkNotification(
614
            'Shipment has been successfully updated.',
615
            NotificationType::success()
616
        );
617
    }
618
619
    /**
620
     * @Then /^I should not be able to ship (this order)$/
621
     */
622
    public function iShouldNotBeAbleToShipThisOrder(OrderInterface $order)
623
    {
624
        Assert::false(
625
            $this->showPage->canShipOrder($order),
626
            'It should not have ship shipment button.'
627
        );
628
    }
629
630
    /**
631
     * @When I cancel this order
632
     */
633
    public function iCancelThisOrder()
634
    {
635
        $this->showPage->cancelOrder();
636
    }
637
638
    /**
639
     * @Then I should be notified that it has been successfully updated
640
     */
641
    public function iShouldBeNotifiedAboutItHasBeenSuccessfullyCanceled()
642
    {
643
        $this->notificationChecker->checkNotification(
644
            'Order has been successfully updated.',
645
            NotificationType::success()
646
        );
647
    }
648
649
    /**
650
     * @Then I should not be able to cancel this order
651
     */
652
    public function iShouldNotBeAbleToCancelThisOrder()
653
    {
654
        Assert::false(
655
            $this->showPage->hasCancelButton(),
656
            'There should not be a cancel button, but it is.'
657
        );
658
    }
659
660
    /**
661
     * @Then this order should have state :state
662
     * @Then its state should be :state
663
     */
664
    public function itsStateShouldBe($state)
665
    {
666
        Assert::same(
667
            $this->showPage->getOrderState(),
668
            $state,
669
            'The order state should be %2$s, but it is %s.'
670
        );
671
    }
672
673
    /**
674
     * @Then it should( still) have a :state state
675
     */
676
    public function itShouldHaveState($state)
677
    {
678
        Assert::true(
679
            $this->indexPage->isSingleResourceOnPage(['state' => $state]),
680
            sprintf('Cannot find order with "%s" state in the list.', $state)
681
        );
682
    }
683
684
    /**
685
     * @Then /^(the administrator) should know about (this additional note) for (this order made by "[^"]+")$/
686
     */
687
    public function theCustomerServiceShouldKnowAboutThisAdditionalNotes(
688
        AdminUserInterface $user,
689
        $note,
690
        OrderInterface $order
691
    ) {
692
        $this->sharedSecurityService->performActionAsAdminUser(
693
            $user,
694
            function () use ($note, $order) {
695
                $this->showPage->open(['id' => $order->getId()]);
696
                Assert::true($this->showPage->hasNote($note), sprintf('I should see %s note, but I do not see', $note));
697
            }
698
        );
699
    }
700
701
    /**
702
     * @Then I should see an order with :orderNumber number
703
     */
704
    public function iShouldSeeOrderWithNumber($orderNumber)
705
    {
706
        Assert::true(
707
            $this->indexPage->isSingleResourceOnPage(['number' => $orderNumber]),
708
            sprintf('Cannot find order with "%s" number in the list.', $orderNumber)
709
        );
710
    }
711
712
    /**
713
     * @Then I should not see an order with :orderNumber number
714
     */
715
    public function iShouldNotSeeOrderWithNumber($orderNumber)
716
    {
717
        Assert::false(
718
            $this->indexPage->isSingleResourceOnPage(['number' => $orderNumber]),
719
            sprintf('Order with "%s" number should not be in the list.', $orderNumber)
720
        );
721
    }
722
723
    /**
724
     * @Then I should not see any orders with currency :currencyCode
725
     */
726
    public function iShouldNotSeeAnyOrderWithCurrency($currencyCode)
727
    {
728
        Assert::false(
729
            $this->indexPage->isSingleResourceOnPage(['currencyCode' => $currencyCode]),
730
            sprintf('Order with currency "%s" should not be on the list.', $currencyCode)
731
        );
732
    }
733
734
    /**
735
     * @Then the first order should have number :number
736
     */
737
    public function theFirstOrderShouldHaveNumber($number)
738
    {
739
        $actualNumber = $this->indexPage->getColumnFields('number')[0];
740
741
        Assert::eq(
742
            $actualNumber,
743
            $number,
744
            sprintf('Expected first order\'s number to be %s, but it is %s.', $number, $actualNumber)
745
        );
746
    }
747
748
    /**
749
     * @Then it should have shipment in state :shipmentState
750
     */
751
    public function itShouldHaveShipmentState($shipmentState)
752
    {
753
        Assert::true(
754
            $this->showPage->hasShipment($shipmentState),
755
            sprintf('It should have shipment with %s state', $shipmentState)
756
        );
757
    }
758
759
    /**
760
     * @Then order :orderNumber should have shipment state :shippingState
761
     */
762
    public function thisOrderShipmentStateShouldBe($shippingState)
763
    {
764
        Assert::true(
765
            $this->indexPage->isSingleResourceOnPage(['shippingState' => $shippingState]),
766
            sprintf('Order should have %s shipping state', $shippingState)
767
        );
768
    }
769
770
    /**
771
     * @Then the order :order should have order payment state :orderPaymentState
772
     * @Then /^(this order) should have order payment state "([^"]+)"$/
773
     * @Then /^(its) payment state should be "([^"]+)"$/
774
     */
775
    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...
776
    {
777
        Assert::true(
778
            $this->indexPage->isSingleResourceOnPage(['paymentState' => $orderPaymentState]),
779
            sprintf('Cannot find order with "%s" order payment state in the list.', $orderPaymentState)
780
        );
781
    }
782
783
    /**
784
     * @Then the order :order should have order shipping state :orderShipmentState
785
     * @Then /^(this order) should have order shipping state "([^"]+)"$/
786
     * @Then /^(its) shipping state should be "([^"]+)"$/
787
     */
788
    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...
789
    {
790
        Assert::true(
791
            $this->indexPage->isSingleResourceOnPage(['shippingState' => $orderShipmentState]),
792
            sprintf('Cannot find order with "%s" order shipping state on the list.', $orderShipmentState)
793
        );
794
    }
795
796
    /**
797
     * @Then /^there should be(?:| only) (\d+) payments?$/
798
     */
799
    public function theOrderShouldHaveNumberOfPayments($number)
800
    {
801
        $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...
802
803
        Assert::same((int)$number, $actualNumberOfPayments);
804
    }
805
806
    /**
807
     * @Then I should see the order :orderNumber with total :total
808
     */
809
    public function iShouldSeeTheOrderWithTotal($orderNumber, $total)
810
    {
811
        Assert::true(
812
            $this->indexPage->isSingleResourceOnPage(['total' => $total]),
813
            sprintf('The total of order "%s" is not "%s".', $orderNumber, $total)
814
        );
815
    }
816
817
    /**
818
     * @When /^I want to modify a customer's (?:billing|shipping) address of (this order)$/
819
     */
820
    public function iWantToModifyACustomerSShippingAddress(OrderInterface $order)
821
    {
822
        $this->updatePage->open(['id' => $order->getId()]);
823
    }
824
825
    /**
826
     * @When I save my changes
827
     * @When I try to save my changes
828
     */
829
    public function iSaveMyChanges()
830
    {
831
        $this->updatePage->saveChanges();
832
    }
833
834
    /**
835
     * @When /^I specify their (?:|new )shipping (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/
836
     */
837
    public function iSpecifyTheirShippingAddressAsFor(AddressInterface $address)
838
    {
839
        $this->updatePage->specifyShippingAddress($address);
840
    }
841
842
    /**
843
     * @When /^I specify their (?:|new )billing (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/
844
     */
845
    public function iSpecifyTheirBillingAddressAsFor(AddressInterface $address)
846
    {
847
        $this->updatePage->specifyBillingAddress($address);
848
    }
849
850
    /**
851
     * @Then /^I should be notified that the "([^"]+)", the "([^"]+)", the "([^"]+)" and the "([^"]+)" in (shipping|billing) details are required$/
852
     */
853
    public function iShouldBeNotifiedThatTheAndTheInShippingDetailsAreRequired($firstElement, $secondElement, $thirdElement, $fourthElement, $type)
854
    {
855
        $this->assertElementValidationMessage($type, $firstElement, sprintf('Please enter %s.', $firstElement));
856
        $this->assertElementValidationMessage($type, $secondElement, sprintf('Please enter %s.', $secondElement));
857
        $this->assertElementValidationMessage($type, $thirdElement, sprintf('Please enter %s.', $thirdElement));
858
        $this->assertElementValidationMessage($type, $fourthElement, sprintf('Please enter %s.', $fourthElement));
859
    }
860
861
    /**
862
     * @Then I should see :provinceName as province in the shipping address
863
     */
864
    public function iShouldSeeAsProvinceInTheShippingAddress($provinceName)
865
    {
866
        Assert::true(
867
            $this->showPage->hasShippingProvinceName($provinceName),
868
            sprintf('Cannot find shipping address with province %s', $provinceName)
869
        );
870
    }
871
872
    /**
873
     * @Then I should see :provinceName ad province in the billing address
874
     */
875
    public function iShouldSeeAdProvinceInTheBillingAddress($provinceName)
876
    {
877
        Assert::true(
878
            $this->showPage->hasBillingProvinceName($provinceName),
879
            sprintf('Cannot find shipping address with province %s', $provinceName)
880
        );
881
    }
882
883
    /**
884
     * @Then /^(the administrator) should know about IP address of (this order made by "[^"]+")$/
885
     */
886
    public function theAdministratorShouldKnowAboutIPAddressOfThisOrderMadeBy(
887
        AdminUserInterface $user,
888
        OrderInterface $order
889
    ) {
890
        $this->sharedSecurityService->performActionAsAdminUser(
891
            $user,
892
            function () use ($order) {
893
                $this->showPage->open(['id' => $order->getId()]);
894
895
                Assert::notSame(
896
                    $this->showPage->getIpAddressAssigned(),
897
                    '',
898
                    'There should be IP address assigned to order, but there is not.'
899
                );
900
            }
901
        );
902
    }
903
904
    /**
905
     * @When /^I (clear old billing address) information$/
906
     */
907
    public function iSpecifyTheBillingAddressAs(AddressInterface $address)
908
    {
909
        $this->updatePage->specifyBillingAddress($address);
910
    }
911
912
    /**
913
     * @When /^I (clear old shipping address) information$/
914
     */
915
    public function iSpecifyTheShippingAddressAs(AddressInterface $address)
916
    {
917
        $this->updatePage->specifyShippingAddress($address);
918
    }
919
920
    /**
921
     * @When /^I do not specify new information$/
922
     */
923
    public function iDoNotSpecifyNewInformation()
924
    {
925
        // Intentionally left blank to fulfill context expectation
926
    }
927
928
    /**
929
     * @Then /^(the administrator) should see that (order placed by "[^"]+") has "([^"]+)" currency$/
930
     */
931
    public function theAdministratorShouldSeeThatThisOrderHasBeenPlacedIn(AdminUserInterface $user, OrderInterface $order, $currency)
932
    {
933
        $this->sharedSecurityService->performActionAsAdminUser($user, function () use ($order, $currency) {
934
            $this->showPage->open(['id' => $order->getId()]);
935
            Assert::same(
936
                $this->showPage->getOrderCurrency(),
937
                $currency,
938
                'The order has been placed in %s, but it was expected to be placed in %s'
939
            );
940
        });
941
    }
942
943
    /**
944
     * @Then /^(the administrator) should see the order with total "([^"]+)" in order list$/
945
     */
946
    public function theAdministratorShouldSeeTheOrderWithTotalInOrderList(AdminUserInterface $user, $total)
947
    {
948
        $this->sharedSecurityService->performActionAsAdminUser($user, function () use ($total) {
949
            $this->indexPage->open();
950
951
            Assert::true(
952
                $this->indexPage->isSingleResourceOnPage(['total' => $total]),
953
                sprintf('The order with total "%s" has not been found.', $total)
954
            );
955
        });
956
    }
957
958
    /**
959
     * @param string $type
960
     * @param string $element
961
     * @param string $expectedMessage
962
     *
963
     * @throws \InvalidArgumentException
964
     */
965
    private function assertElementValidationMessage($type, $element, $expectedMessage)
966
    {
967
        $element = sprintf('%s_%s', $type, implode('_', explode(' ', $element)));
968
        Assert::true(
969
            $this->updatePage->checkValidationMessageFor($element, $expectedMessage),
970
            sprintf('The %s should be required.', $element)
971
        );
972
    }
973
}
974