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\Admin; |
13
|
|
|
|
14
|
|
|
use Behat\Behat\Context\Context; |
15
|
|
|
use Sylius\Behat\Page\Admin\Crud\UpdatePageInterface; |
16
|
|
|
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface; |
17
|
|
|
use Sylius\Behat\Page\Admin\Customer\CreatePageInterface; |
18
|
|
|
use Sylius\Component\User\Model\CustomerInterface; |
19
|
|
|
use Webmozart\Assert\Assert; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Anna Walasek <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
final class ManagingCustomersContext implements Context |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var IndexPageInterface |
28
|
|
|
*/ |
29
|
|
|
private $indexPage; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var CreatePageInterface |
33
|
|
|
*/ |
34
|
|
|
private $createPage; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var UpdatePageInterface |
38
|
|
|
*/ |
39
|
|
|
private $updatePage; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param CreatePageInterface $createPage |
43
|
|
|
* @param IndexPageInterface $indexPage |
44
|
|
|
* @param UpdatePageInterface $updatePage |
45
|
|
|
*/ |
46
|
|
|
public function __construct( |
47
|
|
|
CreatePageInterface $createPage, |
48
|
|
|
IndexPageInterface $indexPage, |
49
|
|
|
UpdatePageInterface $updatePage |
50
|
|
|
) { |
51
|
|
|
$this->createPage = $createPage; |
52
|
|
|
$this->indexPage = $indexPage; |
53
|
|
|
$this->updatePage = $updatePage; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @Given I want to create a new customer |
58
|
|
|
* @Given I want to create a new customer account |
59
|
|
|
*/ |
60
|
|
|
public function iWantToCreateANewCustomer() |
61
|
|
|
{ |
62
|
|
|
$this->createPage->open(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @When /^I specify (?:their|his) first name as "([^"]*)"$/ |
67
|
|
|
*/ |
68
|
|
|
public function iSpecifyItsFirstNameAs($name) |
69
|
|
|
{ |
70
|
|
|
$this->createPage->specifyFirstName($name); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @When /^I specify (?:their|his) last name as "([^"]*)"$/ |
75
|
|
|
*/ |
76
|
|
|
public function iSpecifyItsLastNameAs($name) |
77
|
|
|
{ |
78
|
|
|
$this->createPage->specifyLastName($name); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @When I specify their email as :name |
83
|
|
|
*/ |
84
|
|
|
public function iSpecifyItsEmailAs($email) |
85
|
|
|
{ |
86
|
|
|
$this->createPage->specifyEmail($email); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @When I add them |
91
|
|
|
* @When I try to add it |
92
|
|
|
*/ |
93
|
|
|
public function iAddIt() |
94
|
|
|
{ |
95
|
|
|
$this->createPage->create(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @Then the customer :customer should appear in the store |
100
|
|
|
* @Then the customer :customer should still have this email |
101
|
|
|
*/ |
102
|
|
|
public function theCustomerShould(CustomerInterface $customer) |
103
|
|
|
{ |
104
|
|
|
$this->indexPage->open(); |
105
|
|
|
|
106
|
|
|
Assert::true( |
107
|
|
|
$this->indexPage->isSingleResourceOnPage(['Email' => $customer->getEmail()]), |
108
|
|
|
sprintf('Customer with email %s should exist but it does not.', $customer->getEmail()) |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @When I select :gender as its gender |
114
|
|
|
*/ |
115
|
|
|
public function iSelectGender($gender) |
116
|
|
|
{ |
117
|
|
|
$this->createPage->chooseGender($gender); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @When I specify its birthday as :birthday |
122
|
|
|
*/ |
123
|
|
|
public function iSpecifyItsBirthdayAs($birthday) |
124
|
|
|
{ |
125
|
|
|
$this->createPage->specifyBirthday($birthday); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @Given I want to edit the customer :customer |
130
|
|
|
*/ |
131
|
|
|
public function iWantToEditThisCustomer(CustomerInterface $customer) |
132
|
|
|
{ |
133
|
|
|
$this->updatePage->open(['id' => $customer->getId()]); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @When I save my changes |
138
|
|
|
* @When I try to save my changes |
139
|
|
|
*/ |
140
|
|
|
public function iSaveMyChanges() |
141
|
|
|
{ |
142
|
|
|
$this->updatePage->saveChanges(); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @Then /^(this customer) with name "([^"]*)" should appear in the store$/ |
147
|
|
|
*/ |
148
|
|
|
public function theCustomerWithNameShouldAppearInTheRegistry(CustomerInterface $customer, $name) |
149
|
|
|
{ |
150
|
|
|
$this->updatePage->open(['id' => $customer->getId()]); |
151
|
|
|
|
152
|
|
|
Assert::eq( |
153
|
|
|
$name, |
154
|
|
|
$this->updatePage->getFullName(), |
|
|
|
|
155
|
|
|
sprintf('Customer should have name %s, but they have %s.', $name, $this->updatePage->getFullName()) |
|
|
|
|
156
|
|
|
); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @When I want to see all customers in store |
161
|
|
|
*/ |
162
|
|
|
public function iWantToSeeAllCustomersInStore() |
163
|
|
|
{ |
164
|
|
|
$this->indexPage->open(); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @Then /^I should see (\d+) customers in the list$/ |
169
|
|
|
*/ |
170
|
|
|
public function iShouldSeeCustomersInTheList($amountOfCustomers) |
171
|
|
|
{ |
172
|
|
|
Assert::eq( |
173
|
|
|
(int) $amountOfCustomers, |
174
|
|
|
$this->indexPage->countItems(), |
175
|
|
|
sprintf('Amount of customers should be equal %s, but is not.', $amountOfCustomers) |
176
|
|
|
); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @Then I should see the customer :email in the list |
181
|
|
|
*/ |
182
|
|
|
public function iShouldSeeTheCustomerInTheList($email) |
183
|
|
|
{ |
184
|
|
|
Assert::true( |
185
|
|
|
$this->indexPage->isSingleResourceOnPage(['Email' => $email]), |
186
|
|
|
sprintf('Customer with email %s should exist but it does not.', $email) |
187
|
|
|
); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @Then /^I should be notified that ([^"]+) is required$/ |
192
|
|
|
*/ |
193
|
|
|
public function iShouldBeNotifiedThatFirstNameIsRequired($elementName) |
194
|
|
|
{ |
195
|
|
|
Assert::true( |
196
|
|
|
$this->createPage->checkValidationMessageFor($elementName, sprintf('Please enter your %s.', $elementName)), |
197
|
|
|
sprintf('Customer % should be required.', $elementName) |
198
|
|
|
); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @Then the customer with email :email should not appear in the store |
203
|
|
|
*/ |
204
|
|
|
public function theCustomerShouldNotAppearInTheStore($email) |
205
|
|
|
{ |
206
|
|
|
$this->indexPage->open(); |
207
|
|
|
|
208
|
|
|
Assert::false( |
209
|
|
|
$this->indexPage->isSingleResourceOnPage(['email' => $email]), |
210
|
|
|
sprintf('Customer with email %s was created, but it should not.', $email) |
211
|
|
|
); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @When I remove its first name |
216
|
|
|
*/ |
217
|
|
|
public function iRemoveItsFirstName() |
218
|
|
|
{ |
219
|
|
|
$this->updatePage->changeFirstName(''); |
|
|
|
|
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @Then the customer :customer should still have first name :firstName |
224
|
|
|
*/ |
225
|
|
|
public function theCustomerShouldStillHaveFirstName(CustomerInterface $customer, $firstName) |
226
|
|
|
{ |
227
|
|
|
$this->updatePage->open(['id' => $customer->getId()]); |
228
|
|
|
|
229
|
|
|
Assert::eq( |
230
|
|
|
$firstName, |
231
|
|
|
$this->updatePage->getFirstName(), |
|
|
|
|
232
|
|
|
sprintf('Customer should have first name %s, but it does not.', $firstName) |
233
|
|
|
); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* @When I remove its last name |
238
|
|
|
*/ |
239
|
|
|
public function iRemoveItsLastName() |
240
|
|
|
{ |
241
|
|
|
$this->updatePage->changeLastName(''); |
|
|
|
|
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* @Then the customer :customer should still have last name :lastName |
246
|
|
|
*/ |
247
|
|
|
public function theCustomerShouldStillHaveLastName(CustomerInterface $customer, $lastName) |
248
|
|
|
{ |
249
|
|
|
$this->updatePage->open(['id' => $customer->getId()]); |
250
|
|
|
|
251
|
|
|
Assert::eq( |
252
|
|
|
$lastName, |
253
|
|
|
$this->updatePage->getLastName(), |
|
|
|
|
254
|
|
|
sprintf('Customer should have last name %s, but it does not.', $lastName) |
255
|
|
|
); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @When I remove its email |
260
|
|
|
*/ |
261
|
|
|
public function iRemoveItsEmail() |
262
|
|
|
{ |
263
|
|
|
$this->updatePage->changeEmail(''); |
|
|
|
|
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @Then I should be notified that email is not valid |
268
|
|
|
*/ |
269
|
|
|
public function iShouldBeNotifiedThatEmailIsNotValid() |
270
|
|
|
{ |
271
|
|
|
Assert::true( |
272
|
|
|
$this->createPage->checkValidationMessageFor('email', 'This email is invalid.'), |
273
|
|
|
sprintf('Customer should have required form of email.') |
274
|
|
|
); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* @Then I should be notified that email must be unique |
279
|
|
|
*/ |
280
|
|
|
public function iShouldBeNotifiedThatEmailMustBeUnique() |
281
|
|
|
{ |
282
|
|
|
Assert::true( |
283
|
|
|
$this->createPage->checkValidationMessageFor('email', 'This email is already used.'), |
284
|
|
|
sprintf('Unique email violation message should appear on page, but it does not.') |
285
|
|
|
); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* @Then there should still be only one customer with email :email |
290
|
|
|
*/ |
291
|
|
|
public function thereShouldStillBeOnlyOneCustomerWithEmail($email) |
292
|
|
|
{ |
293
|
|
|
$this->indexPage->open(); |
294
|
|
|
|
295
|
|
|
Assert::true( |
296
|
|
|
$this->indexPage->isSingleResourceOnPage(['email' => $email]), |
297
|
|
|
sprintf('Customer with email %s cannot be found.', $email) |
298
|
|
|
); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* @Given I want to enable :customer |
303
|
|
|
* @Given I want to disable :customer |
304
|
|
|
*/ |
305
|
|
|
public function iWantToChangeStatusOf(CustomerInterface $customer) |
306
|
|
|
{ |
307
|
|
|
$this->updatePage->open(['id' => $customer->getId()]); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* @When I enable their account |
312
|
|
|
*/ |
313
|
|
|
public function iEnableIt() |
314
|
|
|
{ |
315
|
|
|
$this->updatePage->enable(); |
|
|
|
|
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* @When I disable their account |
320
|
|
|
*/ |
321
|
|
|
public function iDisableIt() |
322
|
|
|
{ |
323
|
|
|
$this->updatePage->disable(); |
|
|
|
|
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* @Then /^(this customer) should be enabled$/ |
328
|
|
|
*/ |
329
|
|
|
public function thisCustomerShouldBeEnabled(CustomerInterface $customer) |
330
|
|
|
{ |
331
|
|
|
$this->indexPage->open(); |
332
|
|
|
|
333
|
|
|
Assert::eq( |
334
|
|
|
'Yes', |
335
|
|
|
$this->indexPage->getCustomerAccountStatus($customer), |
|
|
|
|
336
|
|
|
'Customer account should be enabled, but it does not.' |
337
|
|
|
); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* @Then /^(this customer) should be disabled$/ |
342
|
|
|
*/ |
343
|
|
|
public function thisCustomerShouldBeDisabled(CustomerInterface $customer) |
344
|
|
|
{ |
345
|
|
|
$this->indexPage->open(); |
346
|
|
|
|
347
|
|
|
Assert::eq( |
348
|
|
|
'No', |
349
|
|
|
$this->indexPage->getCustomerAccountStatus($customer), |
|
|
|
|
350
|
|
|
'Customer account should be disabled, but it does not.' |
351
|
|
|
); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* @When I specify its password as :password |
356
|
|
|
*/ |
357
|
|
|
public function iSpecifyItsPasswordAs($password) |
358
|
|
|
{ |
359
|
|
|
$this->createPage->specifyPassword($password); |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* @When I choose create account option |
364
|
|
|
*/ |
365
|
|
|
public function iChooseCreateAccountOption() |
366
|
|
|
{ |
367
|
|
|
$this->createPage->selectCreateAccount(); |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* @Then the customer :customer should have an account created |
372
|
|
|
* @Then /^(this customer) should have an account created$/ |
373
|
|
|
*/ |
374
|
|
|
public function theyShouldHaveAnAccountCreated(CustomerInterface $customer) |
375
|
|
|
{ |
376
|
|
|
Assert::notNull( |
377
|
|
|
$customer->getUser()->getPassword(), |
378
|
|
|
'Customer should have an account, but they do not.' |
379
|
|
|
); |
380
|
|
|
} |
381
|
|
|
} |
382
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: