Completed
Branch master (b23e60)
by Kamil
35:19
created

theCustomerServiceShouldKnowAboutThisAdditionalNotes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
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\Crud\IndexPageInterface;
17
use Sylius\Behat\Page\Admin\Order\ShowPageInterface;
18
use Sylius\Behat\Service\NotificationCheckerInterface;
19
use Sylius\Behat\Service\SecurityServiceInterface;
20
use Sylius\Component\Core\Model\CustomerInterface;
21
use Sylius\Component\Core\Model\OrderInterface;
22
use Sylius\Component\Core\Model\UserInterface;
23
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
24
use Webmozart\Assert\Assert;
25
26
/**
27
 * @author Paweł Jędrzejewski <[email protected]>
28
 * @author Grzegorz Sadowski <[email protected]>
29
 */
30
final class ManagingOrdersContext implements Context
31
{
32
    /**
33
     * @var SharedStorageInterface
34
     */
35
    private $sharedStorage;
36
37
    /**
38
     * @var IndexPageInterface
39
     */
40
    private $indexPage;
41
42
    /**
43
     * @var ShowPageInterface
44
     */
45
    private $showPage;
46
47
    /**
48
     * @var NotificationCheckerInterface
49
     */
50
    private $notificationChecker;
51
52
    /**
53
     * @var SecurityServiceInterface
54
     */
55
    private $securityService;
56
57
    /**
58
     * @param SharedStorageInterface $sharedStorage
59
     * @param IndexPageInterface $indexPage
60
     * @param ShowPageInterface $showPage
61
     * @param NotificationCheckerInterface $notificationChecker
62
     * @param SecurityServiceInterface $securityService
63
     */
64 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
        SharedStorageInterface $sharedStorage,
66
        IndexPageInterface $indexPage,
67
        ShowPageInterface $showPage,
68
        NotificationCheckerInterface $notificationChecker,
69
        SecurityServiceInterface $securityService
70
    ) {
71
        $this->sharedStorage = $sharedStorage;
72
        $this->indexPage = $indexPage;
73
        $this->showPage = $showPage;
74
        $this->notificationChecker = $notificationChecker;
75
        $this->securityService = $securityService;
76
    }
77
78
    /**
79
     * @When I browse orders
80
     */
81
    public function iBrowseOrders()
82
    {
83
        $this->indexPage->open();
84
    }
85
86
    /**
87
     * @When I view the summary of the order :order
88
     */
89
    public function iSeeTheOrder(OrderInterface $order)
90
    {
91
        $this->showPage->open(['id' => $order->getId()]);
92
    }
93
94
    /**
95
     * @When /^I mark (this order) as a paid$/
96
     */
97
    public function iMarkThisOrderAsAPaid(OrderInterface $order)
98
    {
99
        $this->showPage->completeOrderLastPayment($order);
100
    }
101
102
    /**
103
     * @When specify its tracking code as :trackingCode
104
     */
105
    public function specifyItsTrackingCodeAs($trackingCode)
106
    {
107
        $this->showPage->specifyTrackingCode($trackingCode);
108
    }
109
110
    /**
111
     * @Given /^I ship (this order)$/
112
     */
113
    public function iShipThisOrder(OrderInterface $order)
114
    {
115
        $this->showPage->shipOrder($order);
116
    }
117
118
    /**
119
     * @Then I should see a single order from customer :customer
120
     */
121 View Code Duplication
    public function iShouldSeeASingleOrderFromCustomer(CustomerInterface $customer)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
122
    {
123
        Assert::true(
124
            $this->indexPage->isSingleResourceOnPage(['customer' => $customer->getEmail()]),
125
            sprintf('Cannot find order for customer "%s" in the list.', $customer->getEmail())
126
        );
127
    }
128
129
    /**
130
     * @Then it should have been placed by the customer :customerEmail
131
     */
132
    public function itShouldBePlacedByCustomer($customerEmail)
133
    {
134
        Assert::true(
135
            $this->showPage->hasCustomer($customerEmail),
136
            sprintf('Cannot find customer "%s".', $customerEmail)
137
        );
138
    }
139
140
    /**
141
     * @Then it should be shipped to :customerName, :street, :postcode, :city, :countryName
142
     */
143
    public function itShouldBeShippedTo($customerName, $street, $postcode, $city, $countryName)
144
    {
145
        Assert::true(
146
            $this->showPage->hasShippingAddress($customerName, $street, $postcode, $city, $countryName),
147
            sprintf('Cannot find shipping address "%s, %s %s, %s".', $street, $postcode, $city, $countryName)
148
        );
149
    }
150
151
    /**
152
     * @Then it should be billed to :customerName, :street, :postcode, :city, :countryName
153
     */
154 View Code Duplication
    public function itShouldBeBilledTo($customerName, $street, $postcode, $city, $countryName)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
155
    {
156
        Assert::true(
157
            $this->showPage->hasBillingAddress($customerName, $street, $postcode, $city, $countryName),
158
            sprintf('Cannot find shipping address "%s, %s %s, %s".', $street, $postcode, $city, $countryName)
159
        );
160
    }
161
162
    /**
163
     * @Then it should be shipped via the :shippingMethodName shipping method
164
     */
165
    public function itShouldBeShippedViaShippingMethod($shippingMethodName)
166
    {
167
        Assert::true(
168
            $this->showPage->hasShipment($shippingMethodName),
169
            sprintf('Cannot find shipment "%s".', $shippingMethodName)
170
        );
171
    }
172
173
    /**
174
     * @Then it should be paid with :paymentMethodName
175
     */
176
    public function itShouldBePaidWith($paymentMethodName)
177
    {
178
        Assert::true(
179
            $this->showPage->hasPayment($paymentMethodName),
180
            sprintf('Cannot find payment "%s".', $paymentMethodName)
181
        );
182
    }
183
184
    /**
185
     * @Then /^it should have (\d+) items$/
186
     */
187
    public function itShouldHaveAmountOfItems($amount)
188
    {
189
        $itemsCount = $this->showPage->countItems();
190
191
        Assert::eq(
192
            $amount,
193
            $itemsCount,
194
            sprintf('There should be %d items, but get %d.', $amount, $itemsCount)
195
        );
196
    }
197
198
    /**
199
     * @Then the product named :productName should be in the items list
200
     */
201
    public function theProductShouldBeInTheItemsList($productName)
202
    {
203
        Assert::true(
204
            $this->showPage->isProductInTheList($productName),
205
            sprintf('Product %s is not in the item list.', $productName)
206
        );
207
    }
208
209
    /**
210
     * @Then the order's items total should be :itemsTotal
211
     */
212
    public function theOrdersItemsTotalShouldBe($itemsTotal)
213
    {
214
        $itemsTotalOnPage = $this->showPage->getItemsTotal();
215
216
        Assert::eq(
217
            $itemsTotalOnPage,
218
            $itemsTotal,
219
            'Items total is %s, but should be %s.'
220
        );
221
    }
222
223
    /**
224
     * @Then the order's total should be :total
225
     */
226
    public function theOrdersTotalShouldBe($total)
227
    {
228
        $totalOnPage = $this->showPage->getTotal();
229
230
        Assert::eq(
231
            $totalOnPage,
232
            $total,
233
            'Total is %s, but should be %s.'
234
        );
235
    }
236
237
    /**
238
     * @Then there should be a shipping charge :shippingCharge
239
     */
240
    public function theOrdersShippingChargesShouldBe($shippingCharge)
241
    {
242
        Assert::true(
243
            $this->showPage->hasShippingCharge($shippingCharge),
244
            sprintf('Shipping charges is not "%s".', $shippingCharge)
245
        );
246
    }
247
248
    /**
249
     * @Then the order's shipping total should be :shippingTotal
250
     */
251
    public function theOrdersShippingTotalShouldBe($shippingTotal)
252
    {
253
        $shippingTotalOnPage = $this->showPage->getShippingTotal();
254
255
        Assert::eq(
256
            $shippingTotal,
257
            $shippingTotalOnPage,
258
            sprintf('Shipping total is "%s", but should be "%s".', $shippingTotalOnPage, $shippingTotal)
259
        );
260
    }
261
262
    /**
263
     * @Then the order should have tax :tax
264
     */
265
    public function theOrderShouldHaveTax($tax)
266
    {
267
        Assert::true(
268
            $this->showPage->hasTax($tax),
269
            sprintf('Order should have tax "%s", but it does not.', $tax)
270
        );
271
    }
272
273
    /**
274
     * @Then the order's tax total should be :taxTotal
275
     */
276
    public function theOrdersTaxTotalShouldBe($taxTotal)
277
    {
278
        $taxTotalOnPage = $this->showPage->getTaxTotal();
279
280
        Assert::eq(
281
            $taxTotal,
282
            $taxTotalOnPage,
283
            sprintf('Tax total is "%s", but should be "%s".', $taxTotalOnPage, $taxTotal)
284
        );
285
    }
286
287
    /**
288
     * @Then the order's promotion discount should be :promotionDiscount
289
     */
290
    public function theOrdersPromotionDiscountShouldBe($promotionDiscount)
291
    {
292
        Assert::true(
293
            $this->showPage->hasPromotionDiscount($promotionDiscount),
294
            sprintf('Promotion discount is not "%s".', $promotionDiscount)
295
        );
296
    }
297
298
    /**
299
     * @Then the order's promotion total should be :promotionTotal
300
     */
301
    public function theOrdersPromotionTotalShouldBe($promotionTotal)
302
    {
303
        $promotionTotalOnPage = $this->showPage->getPromotionTotal();
304
305
        Assert::eq(
306
            $promotionTotalOnPage,
307
            $promotionTotal,
308
            'Promotion total is %s, but should be %s.'
309
        );
310
    }
311
312
    /**
313
     * @When I check :itemName data
314
     */
315
    public function iCheckData($itemName)
316
    {
317
        $this->sharedStorage->set('item', $itemName);
318
    }
319
320
    /**
321
     * @Then /^(its) unit price should be ([^"]+)$/
322
     */
323
    public function itemUnitPriceShouldBe($itemName, $unitPrice)
324
    {
325
        $itemUnitPriceOnPage = $this->showPage->getItemUnitPrice($itemName);
326
327
        Assert::eq(
328
            $itemUnitPriceOnPage,
329
            $unitPrice,
330
            'Item unit price is %s, but should be %s.'
331
        );
332
    }
333
334
    /**
335
     * @Then /^(its) discounted unit price should be ([^"]+)$/
336
     */
337
    public function itemDiscountedUnitPriceShouldBe($itemName, $discountedUnitPrice)
338
    {
339
        $itemUnitPriceOnPage = $this->showPage->getItemDiscountedUnitPrice($itemName);
340
341
        Assert::eq(
342
            $itemUnitPriceOnPage,
343
            $discountedUnitPrice,
344
            'Item discounted unit price is %s, but should be %s.'
345
        );
346
    }
347
348
    /**
349
     * @Then /^(its) quantity should be ([^"]+)$/
350
     */
351
    public function itemQuantityShouldBe($itemName, $quantity)
352
    {
353
        $itemQuantityOnPage = $this->showPage->getItemQuantity($itemName);
354
355
        Assert::eq(
356
            $itemQuantityOnPage,
357
            $quantity,
358
            'Item quantity is %s, but should be %s.'
359
        );
360
    }
361
362
    /**
363
     * @Then /^(its) subtotal should be ([^"]+)$/
364
     */
365
    public function itemSubtotalShouldBe($itemName, $subtotal)
366
    {
367
        $itemSubtotalOnPage = $this->showPage->getItemSubtotal($itemName);
368
369
        Assert::eq(
370
            $itemSubtotalOnPage,
371
            $subtotal,
372
            'Item subtotal is %s, but should be %s.'
373
        );
374
    }
375
376
    /**
377
     * @Then /^(its) discount should be ([^"]+)$/
378
     * @Then the :itemName should have :discount discount
379
     */
380
    public function theItemShouldHaveDiscount($itemName, $discount)
381
    {
382
        $itemDiscountOnPage = $this->showPage->getItemDiscount($itemName);
383
384
        Assert::eq(
385
            $itemDiscountOnPage,
386
            $discount,
387
            'Item discount is %s, but should be %s.'
388
        );
389
    }
390
391
    /**
392
     * @Then /^(its) tax should be ([^"]+)$/
393
     */
394
    public function itemTaxShouldBe($itemName, $tax)
395
    {
396
        $itemTaxOnPage = $this->showPage->getItemTax($itemName);
397
398
        Assert::eq(
399
            $itemTaxOnPage,
400
            $tax,
401
            'Item tax is %s, but should be %s.'
402
        );
403
    }
404
405
    /**
406
     * @Then /^(its) total should be ([^"]+)$/
407
     */
408
    public function itemTotalShouldBe($itemName, $total)
409
    {
410
        $itemTotalOnPage = $this->showPage->getItemTotal($itemName);
411
412
        Assert::eq(
413
            $itemTotalOnPage,
414
            $total,
415
            'Item total is %s, but should be %s.'
416
        );
417
    }
418
419
    /**
420
     * @When I delete the order :order
421
     */
422
    public function iDeleteOrder(OrderInterface $order)
423
    {
424
        $this->sharedStorage->set('order', $order);
425
426
        $this->showPage->open(['id' => $order->getId()]);
427
        $this->showPage->deleteOrder();
428
    }
429
430
    /**
431
     * @Then /^(this order) should not exist in the registry$/
432
     */
433
    public function orderShouldNotExistInTheRegistry(OrderInterface $order)
434
    {
435
        $this->indexPage->open();
436
437
        Assert::false(
438
            $this->indexPage->isSingleResourceOnPage(['number' => $order->getNumber()]),
439
            sprintf('Order with number %s exists but should not.', $order->getNumber())
440
        );
441
    }
442
443
    /**
444
     * @Then I should be notified that the order's payment has been successfully completed
445
     */
446
    public function iShouldBeNotifiedThatTheOrderSPaymentHasBeenSuccessfullyCompleted()
447
    {
448
        $this->notificationChecker->checkNotification('Payment has been successfully updated.', NotificationType::success());
449
    }
450
451
    /**
452
     * @Then it should have completed payment state
453
     */
454
    public function itShouldHaveCompletedPaymentState()
455
    {
456
        Assert::true(
457
            $this->showPage->hasPayment('Completed'),
458
            'It should have payment with completed state.'
459
        );
460
    }
461
462
    /**
463
     * @Then /^I should not be able to mark (this order) as paid again$/
464
     */
465
    public function iShouldNotBeAbleToFinalizeItsPayment(OrderInterface $order)
466
    {
467
        Assert::false(
468
            $this->showPage->canCompleteOrderLastPayment($order),
469
            'It should not have complete payment button.'
470
        );
471
    }
472
473
    /**
474
     * @Then I should be notified that the order's shipment has been successfully shipped
475
     */
476
    public function iShouldBeNotifiedThatTheOrderSShipmentHasBeenSuccessfullyShipped()
477
    {
478
        $this->notificationChecker->checkNotification('Shipment has been successfully updated.', NotificationType::success());
479
    }
480
481
    /**
482
     * @Then its shipment state should be :shipmentState
483
     */
484
    public function itsShipmentStateShouldBe($shipmentState)
485
    {
486
        Assert::true(
487
            $this->showPage->hasShipment($shipmentState),
488
            sprintf('It should have shipment with %s state', $shipmentState)
489
        );
490
    }
491
492
    /**
493
     * @Then /^I should not be able to ship (this order)$/
494
     */
495
    public function iShouldNotBeAbleToShipThisOrder(OrderInterface $order)
496
    {
497
        Assert::false(
498
            $this->showPage->canShipOrder($order),
499
            'It should not have ship shipment button.'
500
        );
501
    }
502
503
    /**
504
     * @When I cancel this order
505
     */
506
    public function iCancelThisOrder()
507
    {
508
        $this->showPage->cancelOrder();
509
    }
510
511
    /**
512
     * @Then I should be notified that it has been successfully updated
513
     */
514
    public function iShouldBeNotifiedAboutItHasBeenSuccessfullyCanceled()
515
    {
516
        $this->notificationChecker->checkNotification(
517
            'Order has been successfully updated.',
518
            NotificationType::success()
519
        );
520
    }
521
522
    /**
523
     * @Then I should not be able to cancel this order
524
     */
525
    public function iShouldNotBeAbleToCancelThisOrder()
526
    {
527
        Assert::false(
528
            $this->showPage->hasCancelButton(),
529
            'There should not be a cancel button, but it is.'
530
        );
531
    }
532
533
    /**
534
     * @Then its state should be :state
535
     */
536
    public function itsStateShouldBe($state)
537
    {
538
        Assert::same(
539
            $this->showPage->getOrderState(),
540
            $state,
541
            'The order state should be %2$s, but it is %s.'
542
        );
543
    }
544
545
    /**
546
     * @Then it should have a :state state
547
     */
548
    public function itShouldHaveState($state)
549
    {
550
        $this->indexPage->isSingleResourceOnPage(['state' => $state]);
551
    }
552
553
    /**
554
     * @Then /^(the customer service) should know about (this additional note) for (this order made by "[^"]+")$/
555
     */
556
    public function theCustomerServiceShouldKnowAboutThisAdditionalNotes(UserInterface $user, $note, OrderInterface $order)
557
    {
558
        $this->securityService->performActionAs($user, function () use ($note, $order) {
559
            $this->showPage->open(['id' => $order->getId()]);
560
            Assert::true($this->showPage->hasNote($note), sprintf('I should see %s note, but I do not see', $note));
561
        });
562
    }
563
}
564