|
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\Shop; |
|
13
|
|
|
|
|
14
|
|
|
use Behat\Behat\Context\Context; |
|
15
|
|
|
use Sylius\Behat\NotificationType; |
|
16
|
|
|
use Sylius\Behat\Page\Shop\Account\DashboardPageInterface; |
|
17
|
|
|
use Sylius\Behat\Page\Shop\Account\LoginPageInterface; |
|
18
|
|
|
use Sylius\Behat\Page\Shop\Account\ProfileUpdatePageInterface; |
|
19
|
|
|
use Sylius\Behat\Page\Shop\Account\VerificationPageInterface; |
|
20
|
|
|
use Sylius\Behat\Page\Shop\Account\RegisterPageInterface; |
|
21
|
|
|
use Sylius\Behat\Page\Shop\HomePageInterface; |
|
22
|
|
|
use Sylius\Behat\Service\NotificationCheckerInterface; |
|
23
|
|
|
use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface; |
|
24
|
|
|
use Sylius\Behat\Service\SharedStorageInterface; |
|
25
|
|
|
use Sylius\Behat\Service\SecurityServiceInterface; |
|
26
|
|
|
use Sylius\Component\Core\Model\ShopUserInterface; |
|
27
|
|
|
use Sylius\Component\Core\Model\CustomerInterface; |
|
28
|
|
|
use Webmozart\Assert\Assert; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @author Arkadiusz Krakowiak <[email protected]> |
|
32
|
|
|
*/ |
|
33
|
|
|
class RegistrationContext implements Context |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* @var SharedStorageInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
private $sharedStorage; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var DashboardPageInterface |
|
42
|
|
|
*/ |
|
43
|
|
|
private $dashboardPage; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var HomePageInterface |
|
47
|
|
|
*/ |
|
48
|
|
|
private $homePage; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var LoginPageInterface |
|
52
|
|
|
*/ |
|
53
|
|
|
private $loginPage; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var RegisterPageInterface |
|
57
|
|
|
*/ |
|
58
|
|
|
private $registerPage; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var VerificationPageInterface |
|
62
|
|
|
*/ |
|
63
|
|
|
private $verificationPage; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @var ProfileUpdatePageInterface |
|
67
|
|
|
*/ |
|
68
|
|
|
private $profileUpdatePage; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @var SecurityServiceInterface |
|
72
|
|
|
*/ |
|
73
|
|
|
private $securityService; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @var CurrentPageResolverInterface |
|
77
|
|
|
*/ |
|
78
|
|
|
private $currentPageResolver; |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @var NotificationCheckerInterface |
|
82
|
|
|
*/ |
|
83
|
|
|
private $notificationChecker; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param SharedStorageInterface $sharedStorage |
|
87
|
|
|
* @param DashboardPageInterface $dashboardPage |
|
88
|
|
|
* @param HomePageInterface $homePage |
|
89
|
|
|
* @param LoginPageInterface $loginPage |
|
90
|
|
|
* @param RegisterPageInterface $registerPage |
|
91
|
|
|
* @param VerificationPageInterface $verificationPage |
|
92
|
|
|
* @param ProfileUpdatePageInterface $profileUpdatePage |
|
93
|
|
|
* @param SecurityServiceInterface $securityService |
|
94
|
|
|
* @param CurrentPageResolverInterface $currentPageResolver |
|
95
|
|
|
* @param NotificationCheckerInterface $notificationChecker |
|
96
|
|
|
*/ |
|
97
|
|
|
public function __construct( |
|
98
|
|
|
SharedStorageInterface $sharedStorage, |
|
99
|
|
|
DashboardPageInterface $dashboardPage, |
|
100
|
|
|
HomePageInterface $homePage, |
|
101
|
|
|
LoginPageInterface $loginPage, |
|
102
|
|
|
RegisterPageInterface $registerPage, |
|
103
|
|
|
VerificationPageInterface $verificationPage, |
|
104
|
|
|
ProfileUpdatePageInterface $profileUpdatePage, |
|
105
|
|
|
SecurityServiceInterface $securityService, |
|
106
|
|
|
CurrentPageResolverInterface $currentPageResolver, |
|
107
|
|
|
NotificationCheckerInterface $notificationChecker |
|
108
|
|
|
) { |
|
109
|
|
|
$this->sharedStorage = $sharedStorage; |
|
110
|
|
|
$this->dashboardPage = $dashboardPage; |
|
111
|
|
|
$this->homePage = $homePage; |
|
112
|
|
|
$this->loginPage = $loginPage; |
|
113
|
|
|
$this->registerPage = $registerPage; |
|
114
|
|
|
$this->verificationPage = $verificationPage; |
|
115
|
|
|
$this->profileUpdatePage = $profileUpdatePage; |
|
116
|
|
|
$this->securityService = $securityService; |
|
117
|
|
|
$this->currentPageResolver = $currentPageResolver; |
|
118
|
|
|
$this->notificationChecker = $notificationChecker; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @When /^I want to(?:| again) register a new account$/ |
|
123
|
|
|
*/ |
|
124
|
|
|
public function iWantToRegisterANewAccount() |
|
125
|
|
|
{ |
|
126
|
|
|
$this->registerPage->open(); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @When I specify the first name as :firstName |
|
131
|
|
|
* @When I do not specify the first name |
|
132
|
|
|
*/ |
|
133
|
|
|
public function iSpecifyTheFirstName($firstName = null) |
|
134
|
|
|
{ |
|
135
|
|
|
$this->registerPage->specifyFirstName($firstName); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @When I specify the last name as :lastName |
|
140
|
|
|
* @When I do not specify the last name |
|
141
|
|
|
*/ |
|
142
|
|
|
public function iSpecifyTheLastName($lastName = null) |
|
143
|
|
|
{ |
|
144
|
|
|
$this->registerPage->specifyLastName($lastName); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @When I specify the email as :email |
|
149
|
|
|
* @When I do not specify the email |
|
150
|
|
|
*/ |
|
151
|
|
|
public function iSpecifyTheEmail($email = null) |
|
152
|
|
|
{ |
|
153
|
|
|
$this->registerPage->specifyEmail($email); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @When I specify the password as :password |
|
158
|
|
|
* @When I do not specify the password |
|
159
|
|
|
*/ |
|
160
|
|
|
public function iSpecifyThePasswordAs($password = null) |
|
161
|
|
|
{ |
|
162
|
|
|
$this->registerPage->specifyPassword($password); |
|
163
|
|
|
$this->sharedStorage->set('password', $password); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @When /^I confirm (this password)$/ |
|
168
|
|
|
*/ |
|
169
|
|
|
public function iConfirmThisPassword($password) |
|
170
|
|
|
{ |
|
171
|
|
|
$this->registerPage->verifyPassword($password); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @Given I do not confirm the password |
|
176
|
|
|
*/ |
|
177
|
|
|
public function iDoNotConfirmPassword() |
|
178
|
|
|
{ |
|
179
|
|
|
$this->registerPage->verifyPassword(null); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* @When I specify the phone number as :phoneNumber |
|
184
|
|
|
*/ |
|
185
|
|
|
public function iSpecifyThePhoneNumberAs($phoneNumber) |
|
186
|
|
|
{ |
|
187
|
|
|
$this->registerPage->specifyPhoneNumber($phoneNumber); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* @When I register this account |
|
192
|
|
|
* @When I try to register this account |
|
193
|
|
|
*/ |
|
194
|
|
|
public function iRegisterThisAccount() |
|
195
|
|
|
{ |
|
196
|
|
|
$this->registerPage->register(); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* @Then my email should be :email |
|
201
|
|
|
* @Then my email should still be :email |
|
202
|
|
|
*/ |
|
203
|
|
|
public function myEmailShouldBe($email) |
|
204
|
|
|
{ |
|
205
|
|
|
$this->dashboardPage->open(); |
|
206
|
|
|
|
|
207
|
|
|
Assert::true( |
|
208
|
|
|
$this->dashboardPage->hasCustomerEmail($email), |
|
209
|
|
|
sprintf('Cannot find customer email "%s".', $email) |
|
210
|
|
|
); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* @Then /^I should be notified that the ([^"]+) is required$/ |
|
215
|
|
|
*/ |
|
216
|
|
|
public function iShouldBeNotifiedThatElementIsRequired($element) |
|
217
|
|
|
{ |
|
218
|
|
|
$this->assertFieldValidationMessage($element, sprintf('Please enter your %s.', $element)); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* @Then I should be notified that the email is already used |
|
223
|
|
|
*/ |
|
224
|
|
|
public function iShouldBeNotifiedThatTheEmailIsAlreadyUsed() |
|
225
|
|
|
{ |
|
226
|
|
|
$this->assertFieldValidationMessage('email', 'This email is already used.'); |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* @Then I should be notified that the password do not match |
|
231
|
|
|
*/ |
|
232
|
|
|
public function iShouldBeNotifiedThatThePasswordDoNotMatch() |
|
233
|
|
|
{ |
|
234
|
|
|
$this->assertFieldValidationMessage('password', 'The entered passwords don\'t match'); |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
/** |
|
238
|
|
|
* @Then I should be notified that new account has been successfully created |
|
239
|
|
|
* @Then I should be notified that my account has been created and the verification email has been sent |
|
240
|
|
|
*/ |
|
241
|
|
|
public function iShouldBeNotifiedThatNewAccountHasBeenSuccessfullyCreated() |
|
242
|
|
|
{ |
|
243
|
|
|
$this->notificationChecker->checkNotification( |
|
244
|
|
|
'Thank you for registering, check your email to verify your account.', |
|
245
|
|
|
NotificationType::success() |
|
246
|
|
|
); |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* @Then I should be logged in |
|
251
|
|
|
*/ |
|
252
|
|
|
public function iShouldBeLoggedIn() |
|
253
|
|
|
{ |
|
254
|
|
|
Assert::true( |
|
255
|
|
|
$this->homePage->hasLogoutButton(), |
|
256
|
|
|
'I should be able to sign out.' |
|
257
|
|
|
); |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
/** |
|
261
|
|
|
* @Then I should not be logged in |
|
262
|
|
|
*/ |
|
263
|
|
|
public function iShouldNotBeLoggedIn() |
|
264
|
|
|
{ |
|
265
|
|
|
Assert::false( |
|
266
|
|
|
$this->homePage->hasLogoutButton(), |
|
267
|
|
|
'I should not be logged in.' |
|
268
|
|
|
); |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* @Then I should be able to log in as :email with :password password |
|
273
|
|
|
*/ |
|
274
|
|
|
public function iShouldBeAbleToLogInAsWithPassword($email, $password) |
|
275
|
|
|
{ |
|
276
|
|
|
$this->iLogInAsWithPassword($email, $password); |
|
277
|
|
|
$this->iShouldBeLoggedIn(); |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
/** |
|
281
|
|
|
* @Then I should not be able to log in as :email with :password password |
|
282
|
|
|
*/ |
|
283
|
|
|
public function iShouldNotBeAbleToLogInAsWithPassword($email, $password) |
|
284
|
|
|
{ |
|
285
|
|
|
$this->iLogInAsWithPassword($email, $password); |
|
286
|
|
|
|
|
287
|
|
|
Assert::true( |
|
288
|
|
|
$this->loginPage->hasValidationErrorWith('Error Account is disabled.'), |
|
289
|
|
|
'I should see validation error.' |
|
290
|
|
|
); |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
/** |
|
294
|
|
|
* @When I log in as :email with :password password |
|
295
|
|
|
*/ |
|
296
|
|
|
public function iLogInAsWithPassword($email, $password) |
|
297
|
|
|
{ |
|
298
|
|
|
$this->loginPage->open(); |
|
299
|
|
|
$this->loginPage->specifyUsername($email); |
|
300
|
|
|
$this->loginPage->specifyPassword($password); |
|
301
|
|
|
$this->loginPage->logIn(); |
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
|
|
/** |
|
305
|
|
|
* @When I register with email :email and password :password |
|
306
|
|
|
*/ |
|
307
|
|
|
public function iRegisterWithEmailAndPassword($email, $password) |
|
308
|
|
|
{ |
|
309
|
|
|
$this->registerPage->open(); |
|
310
|
|
|
$this->registerPage->specifyEmail($email); |
|
311
|
|
|
$this->registerPage->specifyPassword($password); |
|
312
|
|
|
$this->registerPage->verifyPassword($password); |
|
313
|
|
|
$this->registerPage->specifyFirstName('Carrot'); |
|
314
|
|
|
$this->registerPage->specifyLastName('Ironfoundersson'); |
|
315
|
|
|
$this->registerPage->register(); |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
/** |
|
319
|
|
|
* @Then /^(my) account should be verified$/ |
|
320
|
|
|
*/ |
|
321
|
|
|
public function myAccountShouldBeVerified(ShopUserInterface $user) |
|
|
|
|
|
|
322
|
|
|
{ |
|
323
|
|
|
Assert::true( |
|
324
|
|
|
$this->dashboardPage->isVerified(), |
|
325
|
|
|
'My account should be verified.' |
|
326
|
|
|
); |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
/** |
|
330
|
|
|
* @When /^(I) try to verify my account using the link from this email$/ |
|
331
|
|
|
*/ |
|
332
|
|
|
public function iUseItToVerify(ShopUserInterface $user) |
|
333
|
|
|
{ |
|
334
|
|
|
$this->verificationPage->verifyAccount($user->getEmailVerificationToken()); |
|
335
|
|
|
} |
|
336
|
|
|
|
|
337
|
|
|
/** |
|
338
|
|
|
* @When I verify my account using link sent to :customer |
|
339
|
|
|
*/ |
|
340
|
|
|
public function iVerifyMyAccount(CustomerInterface $customer) |
|
341
|
|
|
{ |
|
342
|
|
|
$user = $customer->getUser(); |
|
343
|
|
|
Assert::notNull($user, 'No account for given customer'); |
|
344
|
|
|
|
|
345
|
|
|
$this->iUseItToVerify($user); |
|
|
|
|
|
|
346
|
|
|
} |
|
347
|
|
|
|
|
348
|
|
|
/** |
|
349
|
|
|
* @When I resend the verification email |
|
350
|
|
|
*/ |
|
351
|
|
|
public function iResendVerificationEmail() |
|
352
|
|
|
{ |
|
353
|
|
|
$this->dashboardPage->open(); |
|
354
|
|
|
$this->dashboardPage->pressResendVerificationEmail(); |
|
355
|
|
|
} |
|
356
|
|
|
|
|
357
|
|
|
/** |
|
358
|
|
|
* @When I use the verification link from the first email to verify |
|
359
|
|
|
*/ |
|
360
|
|
|
public function iUseVerificationLinkFromFirstEmailToVerify() |
|
361
|
|
|
{ |
|
362
|
|
|
$token = $this->sharedStorage->get('verification_token'); |
|
363
|
|
|
|
|
364
|
|
|
$this->verificationPage->verifyAccount($token); |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
/** |
|
368
|
|
|
* @When I (try to )verify using :token token |
|
369
|
|
|
*/ |
|
370
|
|
|
public function iTryToVerifyUsing($token) |
|
371
|
|
|
{ |
|
372
|
|
|
$this->verificationPage->verifyAccount($token); |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
|
|
/** |
|
376
|
|
|
* @Then /^(?:my|his|her) account should not be verified$/ |
|
377
|
|
|
*/ |
|
378
|
|
|
public function myAccountShouldNotBeVerified() |
|
379
|
|
|
{ |
|
380
|
|
|
$this->dashboardPage->open(); |
|
381
|
|
|
|
|
382
|
|
|
Assert::false( |
|
383
|
|
|
$this->dashboardPage->isVerified(), |
|
384
|
|
|
'Account should not be verified.' |
|
385
|
|
|
); |
|
386
|
|
|
} |
|
387
|
|
|
|
|
388
|
|
|
/** |
|
389
|
|
|
* @Then I should not be able to resend the verification email |
|
390
|
|
|
*/ |
|
391
|
|
|
public function iShouldBeUnableToResendVerificationEmail() |
|
392
|
|
|
{ |
|
393
|
|
|
$this->dashboardPage->open(); |
|
394
|
|
|
|
|
395
|
|
|
Assert::false( |
|
396
|
|
|
$this->dashboardPage->hasResendVerificationEmailButton(), |
|
397
|
|
|
'You should not be able to resend the verification email.' |
|
398
|
|
|
); |
|
399
|
|
|
} |
|
400
|
|
|
|
|
401
|
|
|
/** |
|
402
|
|
|
* @Then I should be notified that the verification was successful |
|
403
|
|
|
*/ |
|
404
|
|
|
public function iShouldBeNotifiedThatTheVerificationWasSuccessful() |
|
405
|
|
|
{ |
|
406
|
|
|
$this->notificationChecker->checkNotification('has been successfully verified.', NotificationType::success()); |
|
407
|
|
|
} |
|
408
|
|
|
|
|
409
|
|
|
/** |
|
410
|
|
|
* @Then I should be notified that the verification token is invalid |
|
411
|
|
|
*/ |
|
412
|
|
|
public function iShouldBeNotifiedThatTheVerificationTokenIsInvalid() |
|
413
|
|
|
{ |
|
414
|
|
|
$this->notificationChecker->checkNotification('The verification token is invalid.', NotificationType::failure()); |
|
415
|
|
|
} |
|
416
|
|
|
|
|
417
|
|
|
/** |
|
418
|
|
|
* @Then I should be notified that the verification email has been sent |
|
419
|
|
|
*/ |
|
420
|
|
|
public function iShouldBeNotifiedThatTheVerificationEmailHasBeenSent() |
|
421
|
|
|
{ |
|
422
|
|
|
$this->notificationChecker->checkNotification( |
|
423
|
|
|
'An email with the verification link has been sent to your email address.', |
|
424
|
|
|
NotificationType::success() |
|
425
|
|
|
); |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
/** |
|
429
|
|
|
* @When I subscribe to the newsletter |
|
430
|
|
|
*/ |
|
431
|
|
|
public function iSubscribeToTheNewsletter() |
|
432
|
|
|
{ |
|
433
|
|
|
$this->registerPage->subscribeToTheNewsletter(); |
|
434
|
|
|
} |
|
435
|
|
|
|
|
436
|
|
|
/** |
|
437
|
|
|
* @Then I should be subscribed to the newsletter |
|
438
|
|
|
*/ |
|
439
|
|
|
public function iShouldBeSubscribedToTheNewsletter() |
|
440
|
|
|
{ |
|
441
|
|
|
$this->profileUpdatePage->open(); |
|
442
|
|
|
|
|
443
|
|
|
Assert::true( |
|
444
|
|
|
$this->profileUpdatePage->isSubscribedToTheNewsletter(), |
|
445
|
|
|
'I should be subscribed to the newsletter, but I am not' |
|
446
|
|
|
); |
|
447
|
|
|
} |
|
448
|
|
|
|
|
449
|
|
|
/** |
|
450
|
|
|
* @param string $element |
|
451
|
|
|
* @param string $expectedMessage |
|
452
|
|
|
*/ |
|
453
|
|
|
private function assertFieldValidationMessage($element, $expectedMessage) |
|
454
|
|
|
{ |
|
455
|
|
|
Assert::true( |
|
456
|
|
|
$this->registerPage->checkValidationMessageFor($element, $expectedMessage), |
|
457
|
|
|
sprintf('The %s should be required.', $element) |
|
458
|
|
|
); |
|
459
|
|
|
} |
|
460
|
|
|
} |
|
461
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.