|
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\PageInterface; |
|
17
|
|
|
use Sylius\Behat\Page\Shop\Account\ChangePasswordPageInterface; |
|
18
|
|
|
use Sylius\Behat\Page\Shop\Account\DashboardPageInterface; |
|
19
|
|
|
use Sylius\Behat\Page\Shop\Account\Order\IndexPage; |
|
20
|
|
|
use Sylius\Behat\Page\Shop\Account\Order\IndexPageInterface; |
|
21
|
|
|
use Sylius\Behat\Page\Shop\Account\ProfileUpdatePageInterface; |
|
22
|
|
|
use Sylius\Behat\Service\NotificationCheckerInterface; |
|
23
|
|
|
use Sylius\Component\Core\Formatter\StringInflector; |
|
24
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
|
25
|
|
|
use Webmozart\Assert\Assert; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @author Grzegorz Sadowski <[email protected]> |
|
29
|
|
|
*/ |
|
30
|
|
|
final class AccountContext implements Context |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* @var DashboardPageInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
private $dashboardPage; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var ProfileUpdatePageInterface |
|
39
|
|
|
*/ |
|
40
|
|
|
private $profileUpdatePage; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var ChangePasswordPageInterface |
|
44
|
|
|
*/ |
|
45
|
|
|
private $changePasswordPage; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var IndexPageInterface |
|
49
|
|
|
*/ |
|
50
|
|
|
private $orderIndexPage; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var NotificationCheckerInterface |
|
54
|
|
|
*/ |
|
55
|
|
|
private $notificationChecker; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param DashboardPageInterface $dashboardPage |
|
59
|
|
|
* @param ProfileUpdatePageInterface $profileUpdatePage |
|
60
|
|
|
* @param ChangePasswordPageInterface $changePasswordPage |
|
61
|
|
|
* @param IndexPage $orderIndexPage |
|
62
|
|
|
* @param NotificationCheckerInterface $notificationChecker |
|
63
|
|
|
*/ |
|
64
|
|
|
public function __construct( |
|
65
|
|
|
DashboardPageInterface $dashboardPage, |
|
66
|
|
|
ProfileUpdatePageInterface $profileUpdatePage, |
|
67
|
|
|
ChangePasswordPageInterface $changePasswordPage, |
|
68
|
|
|
IndexPage $orderIndexPage, |
|
69
|
|
|
NotificationCheckerInterface $notificationChecker |
|
70
|
|
|
) { |
|
71
|
|
|
$this->dashboardPage = $dashboardPage; |
|
72
|
|
|
$this->profileUpdatePage = $profileUpdatePage; |
|
73
|
|
|
$this->changePasswordPage = $changePasswordPage; |
|
74
|
|
|
$this->orderIndexPage = $orderIndexPage; |
|
75
|
|
|
$this->notificationChecker = $notificationChecker; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @Given I want to modify my profile |
|
80
|
|
|
*/ |
|
81
|
|
|
public function iWantToModifyMyProfile() |
|
82
|
|
|
{ |
|
83
|
|
|
$this->profileUpdatePage->open(); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @When I specify the first name as :firstName |
|
88
|
|
|
* @When I remove the first name |
|
89
|
|
|
*/ |
|
90
|
|
|
public function iSpecifyTheFirstName($firstName = null) |
|
91
|
|
|
{ |
|
92
|
|
|
$this->profileUpdatePage->specifyFirstName($firstName); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @When I specify the last name as :lastName |
|
97
|
|
|
* @When I remove the last name |
|
98
|
|
|
*/ |
|
99
|
|
|
public function iSpecifyTheLastName($lastName = null) |
|
100
|
|
|
{ |
|
101
|
|
|
$this->profileUpdatePage->specifyLastName($lastName); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @When I specify the email as :email |
|
106
|
|
|
* @When I remove the email |
|
107
|
|
|
*/ |
|
108
|
|
|
public function iSpecifyTheEmail($email = null) |
|
109
|
|
|
{ |
|
110
|
|
|
$this->profileUpdatePage->specifyEmail($email); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @When I save my changes |
|
115
|
|
|
* @When I try to save my changes |
|
116
|
|
|
*/ |
|
117
|
|
|
public function iSaveMyChanges() |
|
118
|
|
|
{ |
|
119
|
|
|
$this->profileUpdatePage->saveChanges(); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @Then I should be notified that it has been successfully edited |
|
124
|
|
|
*/ |
|
125
|
|
|
public function iShouldBeNotifiedThatItHasBeenSuccessfullyEdited() |
|
126
|
|
|
{ |
|
127
|
|
|
$this->notificationChecker->checkNotification('has been successfully updated.', NotificationType::success()); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @Then my name should be :name |
|
132
|
|
|
* @Then my name should still be :name |
|
133
|
|
|
*/ |
|
134
|
|
|
public function myNameShouldBe($name) |
|
135
|
|
|
{ |
|
136
|
|
|
$this->dashboardPage->open(); |
|
137
|
|
|
|
|
138
|
|
|
Assert::true( |
|
139
|
|
|
$this->dashboardPage->hasCustomerName($name), |
|
140
|
|
|
sprintf('Cannot find customer name "%s".', $name) |
|
141
|
|
|
); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @Then my email should be :email |
|
146
|
|
|
* @Then my email should still be :email |
|
147
|
|
|
*/ |
|
148
|
|
|
public function myEmailShouldBe($email) |
|
149
|
|
|
{ |
|
150
|
|
|
$this->dashboardPage->open(); |
|
151
|
|
|
|
|
152
|
|
|
Assert::true( |
|
153
|
|
|
$this->dashboardPage->hasCustomerEmail($email), |
|
154
|
|
|
sprintf('Cannot find customer email "%s".', $email) |
|
155
|
|
|
); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @Then /^I should be notified that the ([^"]+) is required$/ |
|
160
|
|
|
*/ |
|
161
|
|
|
public function iShouldBeNotifiedThatElementIsRequired($element) |
|
162
|
|
|
{ |
|
163
|
|
|
$this->assertFieldValidationMessage($this->profileUpdatePage, StringInflector::nameToCode($element), sprintf('Please enter your %s.', $element)); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @Then /^I should be notified that the ([^"]+) is invalid$/ |
|
168
|
|
|
*/ |
|
169
|
|
|
public function iShouldBeNotifiedThatElementIsInvalid($element) |
|
170
|
|
|
{ |
|
171
|
|
|
$this->assertFieldValidationMessage($this->profileUpdatePage, StringInflector::nameToCode($element), sprintf('This %s is invalid.', $element)); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @Then I should be notified that the email is already used |
|
176
|
|
|
*/ |
|
177
|
|
|
public function iShouldBeNotifiedThatTheEmailIsAlreadyUsed() |
|
178
|
|
|
{ |
|
179
|
|
|
$this->assertFieldValidationMessage($this->profileUpdatePage, 'email', 'This email is already used.'); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* @Given /^I want to change my password$/ |
|
184
|
|
|
*/ |
|
185
|
|
|
public function iWantToChangeMyPassword() |
|
186
|
|
|
{ |
|
187
|
|
|
$this->changePasswordPage->open(); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/** |
|
191
|
|
|
* @Given I change password from :oldPassword to :newPassword |
|
192
|
|
|
*/ |
|
193
|
|
|
public function iChangePasswordTo($oldPassword, $newPassword) |
|
194
|
|
|
{ |
|
195
|
|
|
$this->iSpecifyTheCurrentPasswordAs($oldPassword); |
|
196
|
|
|
$this->iSpecifyTheNewPasswordAs($newPassword); |
|
197
|
|
|
$this->iSpecifyTheConfirmationPasswordAs($newPassword); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* @Then I should be notified that my password has been successfully changed |
|
202
|
|
|
*/ |
|
203
|
|
|
public function iShouldBeNotifiedThatMyPasswordHasBeenSuccessfullyChanged() |
|
204
|
|
|
{ |
|
205
|
|
|
$this->notificationChecker->checkNotification('has been changed successfully!', NotificationType::success()); |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* @Given I specify the current password as :password |
|
210
|
|
|
*/ |
|
211
|
|
|
public function iSpecifyTheCurrentPasswordAs($password) |
|
212
|
|
|
{ |
|
213
|
|
|
$this->changePasswordPage->specifyCurrentPassword($password); |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* @Given I specify the new password as :password |
|
218
|
|
|
*/ |
|
219
|
|
|
public function iSpecifyTheNewPasswordAs($password) |
|
220
|
|
|
{ |
|
221
|
|
|
$this->changePasswordPage->specifyNewPassword($password); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* @Given I confirm this password as :password |
|
226
|
|
|
*/ |
|
227
|
|
|
public function iSpecifyTheConfirmationPasswordAs($password) |
|
228
|
|
|
{ |
|
229
|
|
|
$this->changePasswordPage->specifyConfirmationPassword($password); |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
/** |
|
233
|
|
|
* @Then I should be notified that provided password is different than the current one |
|
234
|
|
|
*/ |
|
235
|
|
|
public function iShouldBeNotifiedThatProvidedPasswordIsDifferentThanTheCurrentOne() |
|
236
|
|
|
{ |
|
237
|
|
|
$this->assertFieldValidationMessage($this->changePasswordPage, 'current_password', 'Provided password is different than the current one.'); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* @Then I should be notified that the entered passwords do not match |
|
242
|
|
|
*/ |
|
243
|
|
|
public function iShouldBeNotifiedThatTheEnteredPasswordsDoNotMatch() |
|
244
|
|
|
{ |
|
245
|
|
|
$this->assertFieldValidationMessage($this->changePasswordPage, 'new_password', 'The entered passwords don\'t match'); |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
/** |
|
249
|
|
|
* @Then I should be notified that the password should be at least 4 characters long |
|
250
|
|
|
*/ |
|
251
|
|
|
public function iShouldBeNotifiedThatThePasswordShouldBeAtLeastCharactersLong() |
|
252
|
|
|
{ |
|
253
|
|
|
$this->assertFieldValidationMessage($this->changePasswordPage, 'new_password', 'Password must be at least 4 characters long.'); |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* @When I browse my orders |
|
258
|
|
|
*/ |
|
259
|
|
|
public function iBrowseMyOrders() |
|
260
|
|
|
{ |
|
261
|
|
|
$this->orderIndexPage->open(); |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
/** |
|
265
|
|
|
* @Then I should see a single order in the list |
|
266
|
|
|
*/ |
|
267
|
|
|
public function iShouldSeeASingleOrderInTheList() |
|
268
|
|
|
{ |
|
269
|
|
|
Assert::same( |
|
270
|
|
|
1, |
|
271
|
|
|
$this->orderIndexPage->countOrders(), |
|
272
|
|
|
'%s rows with orders should appear on page, %s rows have been found.' |
|
273
|
|
|
); |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
/** |
|
277
|
|
|
* @Given this order should have :order number |
|
278
|
|
|
*/ |
|
279
|
|
|
public function thisOrderShouldHaveNumber(OrderInterface $order) |
|
280
|
|
|
{ |
|
281
|
|
|
Assert::true( |
|
282
|
|
|
$this->orderIndexPage->isOrderWithNumberInTheList($order->getNumber()), |
|
283
|
|
|
sprintf('Cannot find order with number "%s" in the list.', $order->getNumber()) |
|
284
|
|
|
); |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
|
/** |
|
288
|
|
|
* @param PageInterface $page |
|
289
|
|
|
* @param string $element |
|
290
|
|
|
* @param string $expectedMessage |
|
291
|
|
|
*/ |
|
292
|
|
|
private function assertFieldValidationMessage(PageInterface $page, $element, $expectedMessage) |
|
293
|
|
|
{ |
|
294
|
|
|
Assert::true( |
|
295
|
|
|
$page->checkValidationMessageFor($element, $expectedMessage), |
|
296
|
|
|
sprintf('There should be a message: "%s".', $expectedMessage) |
|
297
|
|
|
); |
|
298
|
|
|
} |
|
299
|
|
|
} |
|
300
|
|
|
|