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