Completed
Push — master ( d81c19...f57266 )
by Kamil
20s
created

Context/Ui/Admin/ManagingCustomersContext.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\Admin;
15
16
use Behat\Behat\Context\Context;
17
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
18
use Sylius\Behat\Page\Admin\Customer\CreatePageInterface;
19
use Sylius\Behat\Page\Admin\Customer\IndexPageInterface as CustomerIndexPageInterface;
20
use Sylius\Behat\Page\Admin\Customer\ShowPageInterface;
21
use Sylius\Behat\Page\Admin\Customer\UpdatePageInterface;
22
use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface;
23
use Sylius\Component\Core\Model\CustomerInterface;
24
use Webmozart\Assert\Assert;
25
26
final class ManagingCustomersContext implements Context
27
{
28
    /**
29
     * @var CustomerIndexPageInterface
30
     */
31
    private $indexPage;
32
33
    /**
34
     * @var CreatePageInterface
35
     */
36
    private $createPage;
37
38
    /**
39
     * @var UpdatePageInterface
40
     */
41
    private $updatePage;
42
43
    /**
44
     * @var ShowPageInterface
45
     */
46
    private $showPage;
47
48
    /**
49
     * @var IndexPageInterface
50
     */
51
    private $ordersIndexPage;
52
53
    /**
54
     * @var CurrentPageResolverInterface
55
     */
56
    private $currentPageResolver;
57
58
    /**
59
     * @param CreatePageInterface $createPage
60
     * @param CustomerIndexPageInterface $indexPage
61
     * @param UpdatePageInterface $updatePage
62
     * @param ShowPageInterface $showPage
63
     * @param IndexPageInterface $ordersIndexPage
64
     * @param CurrentPageResolverInterface $currentPageResolver
65
     */
66
    public function __construct(
67
        CreatePageInterface $createPage,
68
        IndexPageInterface $indexPage,
69
        UpdatePageInterface $updatePage,
70
        ShowPageInterface $showPage,
71
        IndexPageInterface $ordersIndexPage,
72
        CurrentPageResolverInterface $currentPageResolver
73
    ) {
74
        $this->createPage = $createPage;
75
        $this->indexPage = $indexPage;
76
        $this->updatePage = $updatePage;
77
        $this->showPage = $showPage;
78
        $this->ordersIndexPage = $ordersIndexPage;
79
        $this->currentPageResolver = $currentPageResolver;
80
    }
81
82
    /**
83
     * @Given I want to create a new customer
84
     * @Given I want to create a new customer account
85
     */
86
    public function iWantToCreateANewCustomer()
87
    {
88
        $this->createPage->open();
89
    }
90
91
    /**
92
     * @When /^I specify (?:their|his) first name as "([^"]*)"$/
93
     */
94
    public function iSpecifyItsFirstNameAs($name)
95
    {
96
        $this->createPage->specifyFirstName($name);
97
    }
98
99
    /**
100
     * @When /^I specify (?:their|his) last name as "([^"]*)"$/
101
     */
102
    public function iSpecifyItsLastNameAs($name)
103
    {
104
        $this->createPage->specifyLastName($name);
105
    }
106
107
    /**
108
     * @When I specify their email as :name
109
     * @When I do not specify their email
110
     */
111
    public function iSpecifyItsEmailAs($email = null)
112
    {
113
        $this->createPage->specifyEmail($email);
114
    }
115
116
    /**
117
     * @When I change their email to :email
118
     * @When I remove its email
119
     */
120
    public function iChangeTheirEmailTo(?string $email = null): void
121
    {
122
        $this->updatePage->changeEmail($email);
123
    }
124
125
    /**
126
     * @When I add them
127
     * @When I try to add them
128
     */
129
    public function iAddIt()
130
    {
131
        $this->createPage->create();
132
    }
133
134
    /**
135
     * @Then the customer :customer should appear in the store
136
     * @Then the customer :customer should still have this email
137
     */
138
    public function theCustomerShould(CustomerInterface $customer)
139
    {
140
        $this->indexPage->open();
141
142
        Assert::true($this->indexPage->isSingleResourceOnPage(['email' => $customer->getEmail()]));
143
    }
144
145
    /**
146
     * @When I select :gender as its gender
147
     */
148
    public function iSelectGender($gender)
149
    {
150
        $this->createPage->chooseGender($gender);
151
    }
152
153
    /**
154
     * @When I select :group as their group
155
     */
156
    public function iSelectGroup($group)
157
    {
158
        $this->createPage->chooseGroup($group);
159
    }
160
161
    /**
162
     * @When I specify its birthday as :birthday
163
     */
164
    public function iSpecifyItsBirthdayAs($birthday)
165
    {
166
        $this->createPage->specifyBirthday($birthday);
167
    }
168
169
    /**
170
     * @When /^I want to edit (this customer)$/
171
     */
172
    public function iWantToEditThisCustomer(CustomerInterface $customer)
173
    {
174
        $this->updatePage->open(['id' => $customer->getId()]);
175
    }
176
177
    /**
178
     * @When I save my changes
179
     * @When I try to save my changes
180
     */
181
    public function iSaveMyChanges()
182
    {
183
        $this->updatePage->saveChanges();
184
    }
185
186
    /**
187
     * @Then /^(this customer) with name "([^"]*)" should appear in the store$/
188
     */
189
    public function theCustomerWithNameShouldAppearInTheRegistry(CustomerInterface $customer, $name)
190
    {
191
        $this->updatePage->open(['id' => $customer->getId()]);
192
193
        Assert::same($this->updatePage->getFullName(), $name);
194
    }
195
196
    /**
197
     * @When I want to see all customers in store
198
     */
199
    public function iWantToSeeAllCustomersInStore()
200
    {
201
        $this->indexPage->open();
202
    }
203
204
    /**
205
     * @Then /^I should see (\d+) customers in the list$/
206
     */
207
    public function iShouldSeeCustomersInTheList($amountOfCustomers)
208
    {
209
        Assert::same($this->indexPage->countItems(), (int) $amountOfCustomers);
210
    }
211
212
    /**
213
     * @Then I should see the customer :email in the list
214
     */
215
    public function iShouldSeeTheCustomerInTheList($email)
216
    {
217
        Assert::true($this->indexPage->isSingleResourceOnPage(['email' => $email]));
218
    }
219
220
    /**
221
     * @Then /^I should be notified that ([^"]+) is required$/
222
     */
223
    public function iShouldBeNotifiedThatFirstNameIsRequired($elementName)
224
    {
225
        Assert::same(
226
            $this->createPage->getValidationMessage($elementName),
227
            sprintf('Please enter your %s.', $elementName)
228
        );
229
    }
230
231
    /**
232
     * @Then /^I should be notified that ([^"]+) should be ([^"]+)$/
233
     */
234
    public function iShouldBeNotifiedThatTheElementShouldBe($elementName, $validationMessage)
235
    {
236
        Assert::same(
237
            $this->updatePage->getValidationMessage($elementName),
238
            sprintf('%s must be %s.', ucfirst($elementName), $validationMessage)
239
        );
240
    }
241
242
    /**
243
     * @Then the customer with email :email should not appear in the store
244
     */
245
    public function theCustomerShouldNotAppearInTheStore($email)
246
    {
247
        $this->indexPage->open();
248
249
        Assert::false($this->indexPage->isSingleResourceOnPage(['email' => $email]));
250
    }
251
252
    /**
253
     * @When I remove its first name
254
     */
255
    public function iRemoveItsFirstName()
256
    {
257
        $this->updatePage->changeFirstName('');
258
    }
259
260
    /**
261
     * @Then /^(this customer) should have an empty first name$/
262
     * @Then the customer :customer should still have an empty first name
263
     */
264
    public function theCustomerShouldStillHaveAnEmptyFirstName(CustomerInterface $customer)
265
    {
266
        $this->updatePage->open(['id' => $customer->getId()]);
267
268
        Assert::eq($this->updatePage->getFirstName(), '');
269
    }
270
271
    /**
272
     * @When I remove its last name
273
     */
274
    public function iRemoveItsLastName()
275
    {
276
        $this->updatePage->changeLastName('');
277
    }
278
279
    /**
280
     * @Then /^(this customer) should have an empty last name$/
281
     * @Then the customer :customer should still have an empty last name
282
     */
283
    public function theCustomerShouldStillHaveAnEmptyLastName(CustomerInterface $customer)
284
    {
285
        $this->updatePage->open(['id' => $customer->getId()]);
286
287
        Assert::eq($this->updatePage->getLastName(), '');
288
    }
289
290
    /**
291
     * @Then I should be notified that email is not valid
292
     */
293
    public function iShouldBeNotifiedThatEmailIsNotValid()
294
    {
295
        Assert::same($this->createPage->getValidationMessage('email'), 'This email is invalid.');
296
    }
297
298
    /**
299
     * @Then I should be notified that email must be unique
300
     */
301
    public function iShouldBeNotifiedThatEmailMustBeUnique()
302
    {
303
        Assert::same($this->createPage->getValidationMessage('email'), 'This email is already used.');
304
    }
305
306
    /**
307
     * @Then there should still be only one customer with email :email
308
     */
309
    public function thereShouldStillBeOnlyOneCustomerWithEmail($email)
310
    {
311
        $this->indexPage->open();
312
313
        Assert::true($this->indexPage->isSingleResourceOnPage(['email' => $email]));
314
    }
315
316
    /**
317
     * @Given I want to enable :customer
318
     * @Given I want to disable :customer
319
     */
320
    public function iWantToChangeStatusOf(CustomerInterface $customer)
321
    {
322
        $this->updatePage->open(['id' => $customer->getId()]);
323
    }
324
325
    /**
326
     * @When I enable their account
327
     */
328
    public function iEnableIt()
329
    {
330
        $this->updatePage->enable();
331
    }
332
333
    /**
334
     * @When I disable their account
335
     */
336
    public function iDisableIt()
337
    {
338
        $this->updatePage->disable();
339
    }
340
341
    /**
342
     * @Then /^(this customer) should be enabled$/
343
     */
344
    public function thisCustomerShouldBeEnabled(CustomerInterface $customer)
345
    {
346
        $this->indexPage->open();
347
348
        Assert::eq($this->indexPage->getCustomerAccountStatus($customer), 'Enabled');
349
    }
350
351
    /**
352
     * @Then /^(this customer) should be disabled$/
353
     */
354
    public function thisCustomerShouldBeDisabled(CustomerInterface $customer)
355
    {
356
        $this->indexPage->open();
357
358
        Assert::eq($this->indexPage->getCustomerAccountStatus($customer), 'Disabled');
359
    }
360
361
    /**
362
     * @When I specify their password as :password
363
     */
364
    public function iSpecifyItsPasswordAs($password)
365
    {
366
        $this->createPage->specifyPassword($password);
367
    }
368
369
    /**
370
     * @When I choose create account option
371
     */
372
    public function iChooseCreateAccountOption()
373
    {
374
        $this->createPage->selectCreateAccount();
375
    }
376
377
    /**
378
     * @When I browse orders of a customer :customer
379
     */
380
    public function iBrowseOrdersOfACustomer(CustomerInterface $customer)
381
    {
382
        $this->ordersIndexPage->open(['id' => $customer->getId()]);
383
    }
384
385
    /**
386
     * @Then the customer :customer should have an account created
387
     * @Then /^(this customer) should have an account created$/
388
     */
389
    public function theyShouldHaveAnAccountCreated(CustomerInterface $customer)
390
    {
391
        Assert::notNull(
392
            $customer->getUser()->getPassword(),
393
            'Customer should have an account, but they do not.'
394
        );
395
    }
396
397
    /**
398
     * @When I view details of the customer :customer
399
     * @When /^I view (their) details$/
400
     */
401
    public function iViewDetailsOfTheCustomer(CustomerInterface $customer)
402
    {
403
        $this->showPage->open(['id' => $customer->getId()]);
404
    }
405
406
    /**
407
     * @Then his name should be :name
408
     */
409
    public function hisNameShouldBe($name)
410
    {
411
        Assert::same($this->showPage->getCustomerName(), $name);
412
    }
413
414
    /**
415
     * @Then he should be registered since :registrationDate
416
     */
417
    public function hisRegistrationDateShouldBe($registrationDate)
418
    {
419
        Assert::eq($this->showPage->getRegistrationDate(), new \DateTime($registrationDate));
420
    }
421
422
    /**
423
     * @Then his email should be :email
424
     */
425
    public function hisEmailShouldBe($email)
426
    {
427
        Assert::same($this->showPage->getCustomerEmail(), $email);
428
    }
429
430
    /**
431
     * @Then his phone number should be :phoneNumber
432
     */
433
    public function hisPhoneNumberShouldBe($phoneNumber)
434
    {
435
        Assert::same($this->showPage->getCustomerPhoneNumber(), $phoneNumber);
436
    }
437
438
    /**
439
     * @Then his default address should be :defaultAddress
440
     */
441
    public function hisShippingAddressShouldBe($defaultAddress)
442
    {
443
        Assert::same($this->showPage->getDefaultAddress(), str_replace(',', '', $defaultAddress));
444
    }
445
446
    /**
447
     * @Then I should see information about no existing account for this customer
448
     */
449
    public function iShouldSeeInformationAboutNoExistingAccountForThisCustomer()
450
    {
451
        Assert::true($this->showPage->hasAccount());
452
    }
453
454
    /**
455
     * @Then I should see that this customer is subscribed to the newsletter
456
     */
457
    public function iShouldSeeThatThisCustomerIsSubscribedToTheNewsletter()
458
    {
459
        Assert::true($this->showPage->isSubscribedToNewsletter());
460
    }
461
462
    /**
463
     * @Then I should not see information about email verification
464
     */
465
    public function iShouldSeeInformationAboutEmailVerification()
466
    {
467
        Assert::true($this->showPage->hasEmailVerificationInformation());
468
    }
469
470
    /**
471
     * @When I make them subscribed to the newsletter
472
     */
473
    public function iMakeThemSubscribedToTheNewsletter()
474
    {
475
        $this->updatePage->subscribeToTheNewsletter();
476
    }
477
478
    /**
479
     * @When I change the password of user :customer to :newPassword
480
     */
481
    public function iChangeThePasswordOfUserTo(CustomerInterface $customer, $newPassword)
482
    {
483
        $this->updatePage->open(['id' => $customer->getId()]);
484
        $this->updatePage->changePassword($newPassword);
485
        $this->updatePage->saveChanges();
486
    }
487
488
    /**
489
     * @Then this customer should be subscribed to the newsletter
490
     */
491
    public function thisCustomerShouldBeSubscribedToTheNewsletter()
492
    {
493
        Assert::true($this->updatePage->isSubscribedToTheNewsletter());
494
    }
495
496
    /**
497
     * @Then the province in the default address should be :provinceName
498
     */
499
    public function theProvinceInTheDefaultAddressShouldBe($provinceName)
500
    {
501
        Assert::true($this->showPage->hasDefaultAddressProvinceName($provinceName));
502
    }
503
504
    /**
505
     * @Then this customer should have :groupName as their group
506
     */
507
    public function thisCustomerShouldHaveAsTheirGroup($groupName)
508
    {
509
        /** @var UpdatePageInterface|ShowPageInterface $currentPage */
510
        $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->updatePage, $this->showPage]);
511
512
        Assert::same($currentPage->getGroupName(), $groupName);
513
    }
514
515
    /**
516
     * @Then I should see that this customer has verified the email
517
     */
518
    public function iShouldSeeThatThisCustomerHasVerifiedTheEmail()
519
    {
520
        Assert::true($this->showPage->hasVerifiedEmail());
521
    }
522
523
    /**
524
     * @Then I should see a single order in the list
525
     */
526
    public function iShouldSeeASingleOrderInTheList()
527
    {
528
        Assert::same($this->ordersIndexPage->countItems(), 1);
529
    }
530
531
    /**
532
     * @Then I should see the order with number :orderNumber in the list
533
     */
534
    public function iShouldSeeASingleOrderFromCustomer($orderNumber)
535
    {
536
        Assert::true($this->indexPage->isSingleResourceOnPage(['number' => $orderNumber]));
537
    }
538
539
    /**
540
     * @Then I should not see the order with number :orderNumber in the list
541
     */
542
    public function iShouldNotSeeASingleOrderFromCustomer($orderNumber)
543
    {
544
        Assert::false($this->indexPage->isSingleResourceOnPage(['number' => $orderNumber]));
545
    }
546
547
    /**
548
     * @When I do not specify any information
549
     */
550
    public function iDoNotSpecifyAnyInformation()
551
    {
552
        // Intentionally left blank.
553
    }
554
555
    /**
556
     * @Then I should not be able to specify their password
557
     */
558
    public function iShouldNotBeAbleToSpecifyItPassword()
559
    {
560
        Assert::true($this->createPage->isUserFormHidden());
561
    }
562
563
    /**
564
     * @Then I should still be on the customer creation page
565
     */
566
    public function iShouldBeOnTheCustomerCreationPage()
567
    {
568
        $this->createPage->verify();
569
    }
570
571
    /**
572
     * @Then I should be able to select create account option
573
     */
574
    public function iShouldBeAbleToSelectCreateAccountOption()
575
    {
576
        Assert::false($this->createPage->hasCheckedCreateOption());
577
    }
578
579
    /**
580
     * @Then I should be able to specify their password
581
     */
582
    public function iShouldBeAbleToSpecifyItPassword()
583
    {
584
        Assert::true($this->createPage->hasPasswordField());
585
    }
586
587
    /**
588
     * @Then I should not be able to select create account option
589
     */
590
    public function iShouldNotBeAbleToSelectCreateAccountOption()
591
    {
592
        Assert::true($this->createPage->hasCheckedCreateOption());
593
    }
594
595
    /**
596
     * @When I do not choose create account option
597
     */
598
    public function iDoNotChooseCreateAccountOption()
599
    {
600
        // Intentionally left blank.
601
    }
602
603
    /**
604
     * @Then I should not see create account option
605
     */
606
    public function iShouldNotSeeCreateAccountOption()
607
    {
608
        Assert::false($this->createPage->hasCreateOption());
0 ignored issues
show
The method hasCreateOption() does not exist on Sylius\Behat\Page\Admin\...mer\CreatePageInterface. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
609
    }
610
611
    /**
612
     * @Then /^I should be notified that the password must be at least (\d+) characters long$/
613
     */
614
    public function iShouldBeNotifiedThatThePasswordMustBeAtLeastCharactersLong($amountOfCharacters)
615
    {
616
        Assert::same(
617
            $this->createPage->getValidationMessage('password'),
618
            sprintf('Password must be at least %d characters long.', $amountOfCharacters)
619
        );
620
    }
621
622
    /**
623
     * @Then I should see the customer has not placed any orders yet
624
     */
625
    public function iShouldSeeTheCustomerHasNotYetPlacedAnyOrders()
626
    {
627
        Assert::false($this->showPage->hasCustomerPlacedAnyOrders());
628
    }
629
630
    /**
631
     * @Then /^I should see that they have placed (\d+) orders? in the "([^"]+)" channel$/
632
     */
633
    public function iShouldSeeThatTheyHavePlacedOrdersInTheChannel($ordersCount, $channelName)
634
    {
635
        Assert::same($this->showPage->getOrdersCountInChannel($channelName), (int) $ordersCount);
636
    }
637
638
    /**
639
     * @Then /^I should see that the overall total value of all their orders in the "([^"]+)" channel is "([^"]+)"$/
640
     */
641
    public function iShouldSeeThatTheOverallTotalValueOfAllTheirOrdersInTheChannelIs($channelName, $ordersValue)
642
    {
643
        Assert::same($this->showPage->getOrdersTotalInChannel($channelName), $ordersValue);
644
    }
645
646
    /**
647
     * @Then /^I should see that the average total value of their order in the "([^"]+)" channel is "([^"]+)"$/
648
     */
649
    public function iShouldSeeThatTheAverageTotalValueOfTheirOrderInTheChannelIs($channelName, $ordersValue)
650
    {
651
        Assert::same($this->showPage->getOrdersTotalInChannel($channelName), $ordersValue);
652
    }
653
}
654