Completed
Push — allow-no-default-tax-zone-in-c... ( 67cea0 )
by Kamil
06:23
created

AccountContext::iViewTheSummaryOfTheOrder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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
declare(strict_types=1);
13
14
namespace Sylius\Behat\Context\Ui\Shop;
15
16
use Behat\Behat\Context\Context;
17
use Sylius\Behat\NotificationType;
18
use Sylius\Behat\Page\Shop\Account\ChangePasswordPageInterface;
19
use Sylius\Behat\Page\Shop\Account\DashboardPageInterface;
20
use Sylius\Behat\Page\Shop\Account\LoginPageInterface;
21
use Sylius\Behat\Page\Shop\Account\Order\IndexPageInterface;
22
use Sylius\Behat\Page\Shop\Account\Order\ShowPageInterface;
23
use Sylius\Behat\Page\Shop\Account\ProfileUpdatePageInterface;
24
use Sylius\Behat\Service\NotificationCheckerInterface;
25
use Sylius\Component\Core\Formatter\StringInflector;
26
use Sylius\Component\Core\Model\OrderInterface;
27
use Webmozart\Assert\Assert;
28
29
final class AccountContext implements Context
30
{
31
    /** @var DashboardPageInterface */
32
    private $dashboardPage;
33
34
    /** @var ProfileUpdatePageInterface */
35
    private $profileUpdatePage;
36
37
    /** @var ChangePasswordPageInterface */
38
    private $changePasswordPage;
39
40
    /** @var IndexPageInterface */
41
    private $orderIndexPage;
42
43
    /** @var ShowPageInterface */
44
    private $orderShowPage;
45
46
    /** @var LoginPageInterface */
47
    private $loginPage;
48
49
    /** @var NotificationCheckerInterface */
50
    private $notificationChecker;
51
52
    public function __construct(
53
        DashboardPageInterface $dashboardPage,
54
        ProfileUpdatePageInterface $profileUpdatePage,
55
        ChangePasswordPageInterface $changePasswordPage,
56
        IndexPageInterface $orderIndexPage,
57
        ShowPageInterface $orderShowPage,
58
        LoginPageInterface $loginPage,
59
        NotificationCheckerInterface $notificationChecker
60
    ) {
61
        $this->dashboardPage = $dashboardPage;
62
        $this->profileUpdatePage = $profileUpdatePage;
63
        $this->changePasswordPage = $changePasswordPage;
64
        $this->orderIndexPage = $orderIndexPage;
65
        $this->orderShowPage = $orderShowPage;
66
        $this->loginPage = $loginPage;
67
        $this->notificationChecker = $notificationChecker;
68
    }
69
70
    /**
71
     * @When I want to modify my profile
72
     */
73
    public function iWantToModifyMyProfile()
74
    {
75
        $this->profileUpdatePage->open();
76
    }
77
78
    /**
79
     * @When I specify the first name as :firstName
80
     * @When I remove the first name
81
     */
82
    public function iSpecifyTheFirstName($firstName = null)
83
    {
84
        $this->profileUpdatePage->specifyFirstName($firstName);
85
    }
86
87
    /**
88
     * @When I specify the last name as :lastName
89
     * @When I remove the last name
90
     */
91
    public function iSpecifyTheLastName($lastName = null)
92
    {
93
        $this->profileUpdatePage->specifyLastName($lastName);
94
    }
95
96
    /**
97
     * @When I specify the customer email as :email
98
     * @When I remove the customer email
99
     */
100
    public function iSpecifyCustomerTheEmail($email = null)
101
    {
102
        $this->profileUpdatePage->specifyEmail($email);
103
    }
104
105
    /**
106
     * @When I save my changes
107
     * @When I try to save my changes
108
     */
109
    public function iSaveMyChanges()
110
    {
111
        $this->profileUpdatePage->saveChanges();
112
    }
113
114
    /**
115
     * @Then I should be notified that it has been successfully edited
116
     */
117
    public function iShouldBeNotifiedThatItHasBeenSuccessfullyEdited()
118
    {
119
        $this->notificationChecker->checkNotification('has been successfully updated.', NotificationType::success());
120
    }
121
122
    /**
123
     * @Then my name should be :name
124
     * @Then my name should still be :name
125
     */
126
    public function myNameShouldBe($name)
127
    {
128
        $this->dashboardPage->open();
129
130
        Assert::true($this->dashboardPage->hasCustomerName($name));
131
    }
132
133
    /**
134
     * @Then my email should be :email
135
     * @Then my email should still be :email
136
     */
137
    public function myEmailShouldBe($email)
138
    {
139
        $this->dashboardPage->open();
140
141
        Assert::true($this->dashboardPage->hasCustomerEmail($email));
142
    }
143
144
    /**
145
     * @Then /^I should be notified that the (email|password|city|street|first name|last name) is required$/
146
     */
147
    public function iShouldBeNotifiedThatElementIsRequired($element)
148
    {
149
        Assert::true($this->profileUpdatePage->checkValidationMessageFor(
150
            StringInflector::nameToCode($element),
151
            sprintf('Please enter your %s.', $element)
152
        ));
153
    }
154
155
    /**
156
     * @Then /^I should be notified that the (email) is invalid$/
157
     */
158
    public function iShouldBeNotifiedThatElementIsInvalid($element)
159
    {
160
        Assert::true($this->profileUpdatePage->checkValidationMessageFor(
161
            StringInflector::nameToCode($element),
162
            sprintf('This %s is invalid.', $element)
163
        ));
164
    }
165
166
    /**
167
     * @Then I should be notified that the email is already used
168
     */
169
    public function iShouldBeNotifiedThatTheEmailIsAlreadyUsed()
170
    {
171
        Assert::true($this->profileUpdatePage->checkValidationMessageFor('email', 'This email is already used.'));
172
    }
173
174
    /**
175
     * @Given /^I want to change my password$/
176
     */
177
    public function iWantToChangeMyPassword()
178
    {
179
        $this->changePasswordPage->open();
180
    }
181
182
    /**
183
     * @Given I change password from :oldPassword to :newPassword
184
     */
185
    public function iChangePasswordTo($oldPassword, $newPassword)
186
    {
187
        $this->iSpecifyTheCurrentPasswordAs($oldPassword);
188
        $this->iSpecifyTheNewPasswordAs($newPassword);
189
        $this->iSpecifyTheConfirmationPasswordAs($newPassword);
190
    }
191
192
    /**
193
     * @Then I should be notified that my password has been successfully changed
194
     */
195
    public function iShouldBeNotifiedThatMyPasswordHasBeenSuccessfullyChanged()
196
    {
197
        $this->notificationChecker->checkNotification('has been changed successfully!', NotificationType::success());
198
    }
199
200
    /**
201
     * @Given I specify the current password as :password
202
     */
203
    public function iSpecifyTheCurrentPasswordAs($password)
204
    {
205
        $this->changePasswordPage->specifyCurrentPassword($password);
206
    }
207
208
    /**
209
     * @Given I specify the new password as :password
210
     */
211
    public function iSpecifyTheNewPasswordAs($password)
212
    {
213
        $this->changePasswordPage->specifyNewPassword($password);
214
    }
215
216
    /**
217
     * @Given I confirm this password as :password
218
     */
219
    public function iSpecifyTheConfirmationPasswordAs($password)
220
    {
221
        $this->changePasswordPage->specifyConfirmationPassword($password);
222
    }
223
224
    /**
225
     * @Then I should be notified that provided password is different than the current one
226
     */
227
    public function iShouldBeNotifiedThatProvidedPasswordIsDifferentThanTheCurrentOne()
228
    {
229
        Assert::true($this->changePasswordPage->checkValidationMessageFor(
230
            'current_password',
231
            'Provided password is different than the current one.'
232
        ));
233
    }
234
235
    /**
236
     * @Then I should be notified that the entered passwords do not match
237
     */
238
    public function iShouldBeNotifiedThatTheEnteredPasswordsDoNotMatch()
239
    {
240
        Assert::true($this->changePasswordPage->checkValidationMessageFor(
241
            'new_password',
242
            'The entered passwords don\'t match'
243
        ));
244
    }
245
246
    /**
247
     * @Then I should be notified that the password should be at least 4 characters long
248
     */
249
    public function iShouldBeNotifiedThatThePasswordShouldBeAtLeastCharactersLong()
250
    {
251
        Assert::true($this->changePasswordPage->checkValidationMessageFor(
252
            'new_password',
253
            'Password must be at least 4 characters long.'
254
        ));
255
    }
256
257
    /**
258
     * @When I browse my orders
259
     */
260
    public function iBrowseMyOrders()
261
    {
262
        $this->orderIndexPage->open();
263
    }
264
265
    /**
266
     * @Then I should see a single order in the list
267
     */
268
    public function iShouldSeeASingleOrderInTheList()
269
    {
270
        Assert::same($this->orderIndexPage->countOrders(), 1);
271
    }
272
273
    /**
274
     * @Then this order should have :order number
275
     */
276
    public function thisOrderShouldHaveNumber(OrderInterface $order)
277
    {
278
        Assert::true($this->orderIndexPage->isOrderWithNumberInTheList($order->getNumber()));
279
    }
280
281
    /**
282
     * @When I view the summary of the order :order
283
     */
284
    public function iViewTheSummaryOfTheOrder(OrderInterface $order)
285
    {
286
        $this->orderShowPage->open(['number' => $order->getNumber()]);
287
    }
288
289
    /**
290
     * @When I am viewing the summary of my last order
291
     */
292
    public function iViewingTheSummaryOfMyLastOrder()
293
    {
294
        $this->orderIndexPage->open();
295
        $this->orderIndexPage->openLastOrderPage();
296
    }
297
298
    /**
299
     * @Then it should has number :orderNumber
300
     */
301
    public function itShouldHasNumber($orderNumber)
302
    {
303
        Assert::same($this->orderShowPage->getNumber(), $orderNumber);
304
    }
305
306
    /**
307
     * @Then I should see :customerName, :street, :postcode, :city, :countryName as shipping address
308
     */
309
    public function iShouldSeeAsShippingAddress($customerName, $street, $postcode, $city, $countryName)
310
    {
311
        Assert::true($this->orderShowPage->hasShippingAddress($customerName, $street, $postcode, $city, $countryName));
312
    }
313
314
    /**
315
     * @Then I should see :customerName, :street, :postcode, :city, :countryName as billing address
316
     */
317
    public function itShouldBeShippedTo($customerName, $street, $postcode, $city, $countryName)
318
    {
319
        Assert::true($this->orderShowPage->hasBillingAddress($customerName, $street, $postcode, $city, $countryName));
320
    }
321
322
    /**
323
     * @Then I should see :total as order's total
324
     */
325
    public function iShouldSeeAsOrderSTotal($total)
326
    {
327
        Assert::same($this->orderShowPage->getTotal(), $total);
328
    }
329
330
    /**
331
     * @Then I should see :itemsTotal as order's subtotal
332
     */
333
    public function iShouldSeeAsOrderSSubtotal($subtotal)
334
    {
335
        Assert::same($this->orderShowPage->getSubtotal(), $subtotal);
336
    }
337
338
    /**
339
     * @Then I should see that I have to pay :paymentAmount for this order
340
     * @Then I should see :paymentTotal as payment total
341
     */
342
    public function iShouldSeeIHaveToPayForThisOrder($paymentAmount)
343
    {
344
        Assert::same($this->orderShowPage->getPaymentPrice(), $paymentAmount);
345
    }
346
347
    /**
348
     * @Then I should see :numberOfItems items in the list
349
     */
350
    public function iShouldSeeItemsInTheList($numberOfItems)
351
    {
352
        Assert::same($this->orderShowPage->countItems(), (int) $numberOfItems);
353
    }
354
355
    /**
356
     * @Then the product named :productName should be in the items list
357
     */
358
    public function theProductShouldBeInTheItemsList($productName)
359
    {
360
        Assert::true($this->orderShowPage->isProductInTheList($productName));
361
    }
362
363
    /**
364
     * @Then I should see :itemPrice as item price
365
     */
366
    public function iShouldSeeAsItemPrice($itemPrice)
367
    {
368
        Assert::same($this->orderShowPage->getItemPrice(), $itemPrice);
369
    }
370
371
    /**
372
     * @When I subscribe to the newsletter
373
     */
374
    public function iSubscribeToTheNewsletter()
375
    {
376
        $this->profileUpdatePage->subscribeToTheNewsletter();
377
    }
378
379
    /**
380
     * @Then I should be subscribed to the newsletter
381
     */
382
    public function iShouldBeSubscribedToTheNewsletter()
383
    {
384
        Assert::true($this->profileUpdatePage->isSubscribedToTheNewsletter());
385
    }
386
387
    /**
388
     * @Then I should see :provinceName as province in the shipping address
389
     */
390
    public function iShouldSeeAsProvinceInTheShippingAddress($provinceName)
391
    {
392
        Assert::true($this->orderShowPage->hasShippingProvinceName($provinceName));
393
    }
394
395
    /**
396
     * @Then I should see :provinceName as province in the billing address
397
     */
398
    public function iShouldSeeAsProvinceInTheBillingAddress($provinceName)
399
    {
400
        Assert::true($this->orderShowPage->hasBillingProvinceName($provinceName));
401
    }
402
403
    /**
404
     * @Then /^I should be able to change payment method for (this order)$/
405
     */
406
    public function iShouldBeAbleToChangePaymentMethodForThisOrder(OrderInterface $order)
407
    {
408
        Assert::true($this->orderIndexPage->isItPossibleToChangePaymentMethodForOrder($order));
409
    }
410
411
    /**
412
     * @Then I should be redirected to my account dashboard
413
     */
414
    public function iShouldBeRedirectedToMyAccountDashboard()
415
    {
416
        Assert::true($this->dashboardPage->isOpen(), 'User should be on the account panel dashboard page but they are not.');
417
    }
418
419
    /**
420
     * @When I want to log in
421
     */
422
    public function iWantToLogIn()
423
    {
424
        $this->loginPage->tryToOpen();
425
    }
426
427
    /**
428
     * @Then I should see its payment status as :paymentStatus
429
     */
430
    public function shouldSeePaymentStatus(string $paymentStatus): void
431
    {
432
        Assert::same($this->orderShowPage->getPaymentStatus(), $paymentStatus);
433
    }
434
435
    /**
436
     * @Then I should see its order's payment status as :orderPaymentState
437
     */
438
    public function iShouldSeeItsOrderSPaymentStatusAs(string $orderPaymentState): void
439
    {
440
        Assert::same($this->orderShowPage->getOrderPaymentStatus(), $orderPaymentState);
441
    }
442
443
    /**
444
     * @Then the order's shipment status should be :orderShipmentStatus
445
     */
446
    public function theOrderShipmentStatusShouldBe(string $orderShipmentStatus): void
447
    {
448
        Assert::same($this->orderShowPage->getOrderShipmentStatus(), $orderShipmentStatus);
449
    }
450
451
    /**
452
     * @Then the shipment status should be :shipmentStatus
453
     */
454
    public function theShipmentStatusShouldBe(string $shipmentStatus): void
455
    {
456
        Assert::same($this->orderShowPage->getShipmentStatus(), $shipmentStatus);
457
    }
458
}
459