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\Bundle\WebBundle\Behat; |
13
|
|
|
|
14
|
|
|
use Behat\Behat\Context\SnippetAcceptingContext; |
15
|
|
|
use Behat\Gherkin\Node\TableNode; |
16
|
|
|
use Behat\Mink\Element\DocumentElement; |
17
|
|
|
use Behat\Mink\Element\NodeElement; |
18
|
|
|
use Behat\Mink\Exception\ElementNotFoundException; |
19
|
|
|
use Behat\Mink\Exception\UnsupportedDriverActionException; |
20
|
|
|
use Sylius\Bundle\ResourceBundle\Behat\WebContext as BaseWebContext; |
21
|
|
|
use Symfony\Component\Intl\Intl; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Web context. |
25
|
|
|
* |
26
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class WebContext extends BaseWebContext implements SnippetAcceptingContext |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @Given /^I am on user login page?$/ |
32
|
|
|
* @When /^I go to user login page?$/ |
33
|
|
|
*/ |
34
|
|
|
public function iAmOnTheLoginPage() |
35
|
|
|
{ |
36
|
|
|
$this->getSession()->visit($this->generatePageUrl('sylius_user_security_login')); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @Then /^I should (?:|still )be on user login page$/ |
41
|
|
|
* @Then /^I should be redirected to user login page$/ |
42
|
|
|
*/ |
43
|
|
|
public function iShouldBeOnTheLoginPage() |
44
|
|
|
{ |
45
|
|
|
$this->assertRoute('sylius_user_security_login'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @Given /^(?:|I )go to "([^""]*)" tab$/ |
50
|
|
|
*/ |
51
|
|
|
public function goToTab($tabLabel) |
52
|
|
|
{ |
53
|
|
|
$tabContainer = $this->getSession()->getPage()->find('css', sprintf('.nav-tabs li:contains("%s")', $tabLabel)); |
54
|
|
|
$tabContainer->find('css', 'a')->click(); |
55
|
|
|
|
56
|
|
|
$this->waitForTabToActivate($tabContainer); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param NodeElement $tabContainer |
61
|
|
|
*/ |
62
|
|
|
protected function waitForTabToActivate($tabContainer) |
63
|
|
|
{ |
64
|
|
|
$this->waitFor(function () use ($tabContainer) { |
65
|
|
|
return false !== strpos($tabContainer->getAttribute('class'), 'active'); |
66
|
|
|
}); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @Then /^the page title should be "([^""]*)"$/ |
71
|
|
|
*/ |
72
|
|
|
public function thePageTitleShouldBe($title) |
73
|
|
|
{ |
74
|
|
|
$this->assertSession()->elementTextContains('css', 'title', $title); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @When /^I go to the website root$/ |
79
|
|
|
*/ |
80
|
|
|
public function iGoToTheWebsiteRoot() |
81
|
|
|
{ |
82
|
|
|
$this->getSession()->visit('/'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @Then /^I should (?:|still )be on the store homepage$/ |
87
|
|
|
* @Then /^I should be redirected to the store homepage$/ |
88
|
|
|
*/ |
89
|
|
|
public function iShouldBeOnTheStoreHomepage() |
90
|
|
|
{ |
91
|
|
|
$this->assertRoute('sylius_homepage'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @Given /^I am on the store homepage$/ |
96
|
|
|
*/ |
97
|
|
|
public function iAmOnTheStoreHomepage() |
98
|
|
|
{ |
99
|
|
|
$this->getSession()->visit($this->generateUrl('sylius_homepage')); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @Given /^I am on my account homepage$/ |
104
|
|
|
*/ |
105
|
|
|
public function iAmOnMyAccountHomepage() |
106
|
|
|
{ |
107
|
|
|
$this->getSession()->visit($this->generatePageUrl('sylius_account_profile_show')); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @Then /^I should (?:|still )be on my account homepage$/ |
112
|
|
|
*/ |
113
|
|
|
public function iShouldBeOnMyAccountHomepage() |
114
|
|
|
{ |
115
|
|
|
$this->assertRoute('sylius_account_profile_show'); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @Given /^I am on my account password page$/ |
120
|
|
|
*/ |
121
|
|
|
public function iAmOnMyAccountPasswordPage() |
122
|
|
|
{ |
123
|
|
|
$this->getSession()->visit($this->generatePageUrl('sylius_account_change_password')); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @Then /^I should (?:|still )be on my account password page$/ |
128
|
|
|
*/ |
129
|
|
|
public function iShouldBeOnMyAccountPasswordPage() |
130
|
|
|
{ |
131
|
|
|
$this->assertRoute('sylius_account_change_password'); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @Given /^I am on my account profile edition page$/ |
136
|
|
|
*/ |
137
|
|
|
public function iAmOnMyAccountProfileEditionPage() |
138
|
|
|
{ |
139
|
|
|
$this->getSession()->visit($this->generatePageUrl('sylius_account_profile_update')); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @Then /^I should (?:|still )be on my account profile edition page$/ |
144
|
|
|
*/ |
145
|
|
|
public function iShouldBeOnMyProfileEditionPage() |
146
|
|
|
{ |
147
|
|
|
$this->assertRoute('sylius_account_profile_update'); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @Then /^I should (?:|still )be on my account profile page$/ |
152
|
|
|
*/ |
153
|
|
|
public function iShouldBeOnMyProfilePage() |
154
|
|
|
{ |
155
|
|
|
$this->assertRoute('sylius_account_profile_show'); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @Then /^I should be on my account orders page$/ |
160
|
|
|
*/ |
161
|
|
|
public function iShouldBeOnMyAccountOrdersPage() |
162
|
|
|
{ |
163
|
|
|
$this->assertRoute('sylius_account_order_index'); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @Given /^I am on my account orders page$/ |
168
|
|
|
*/ |
169
|
|
|
public function iAmOnMyAccountOrdersPage() |
170
|
|
|
{ |
171
|
|
|
$this->getSession()->visit($this->generatePageUrl('sylius_account_order_index')); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @Given /^I am on my account addresses page$/ |
176
|
|
|
*/ |
177
|
|
|
public function iAmOnMyAccountAddressesPage() |
178
|
|
|
{ |
179
|
|
|
$this->getSession()->visit($this->generatePageUrl('sylius_account_address_index')); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @Then /^I should (?:|still )be on my account addresses page$/ |
184
|
|
|
*/ |
185
|
|
|
public function iShouldBeOnMyAccountAddressesPage() |
186
|
|
|
{ |
187
|
|
|
$this->assertRoute('sylius_account_address_index'); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @Given /^I am on my account address creation page$/ |
192
|
|
|
*/ |
193
|
|
|
public function iAmOnMyAccountAddressCreationPage() |
194
|
|
|
{ |
195
|
|
|
$this->getSession()->visit($this->generatePageUrl('sylius_account_address_create')); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @Then /^I should (?:|still )be on my account address creation page$/ |
200
|
|
|
*/ |
201
|
|
|
public function iShouldBeOnMyAccountAddressCreationPage() |
202
|
|
|
{ |
203
|
|
|
$this->assertRoute('sylius_account_address_create'); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @Then /^I should (?:|still )be on registration page$/ |
208
|
|
|
*/ |
209
|
|
|
public function iShouldBeOnRegistrationPage() |
210
|
|
|
{ |
211
|
|
|
$this->assertRoute('sylius_user_registration'); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @Given /^I am on the shipment page with method "([^""]*)"$/ |
216
|
|
|
*/ |
217
|
|
|
public function iAmOnTheShipmentPage($value) |
218
|
|
|
{ |
219
|
|
|
$shippingMethod = $this->findOneBy('shipping_method', ['name' => $value]); |
220
|
|
|
$shipment = $this->findOneBy('shipment', ['method' => $shippingMethod]); |
221
|
|
|
|
222
|
|
|
$this->getSession()->visit($this->generatePageUrl('backend_shipment_show', ['id' => $shipment->getId()])); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @Then /^I should be on the shipment page with method "([^"]*)"$/ |
227
|
|
|
*/ |
228
|
|
|
public function iShouldBeOnTheShipmentPageWithMethod($value) |
229
|
|
|
{ |
230
|
|
|
$shippingMethod = $this->findOneBy('shipping_method', ['name' => $value]); |
231
|
|
|
$shipment = $this->findOneBy('shipment', ['method' => $shippingMethod]); |
232
|
|
|
|
233
|
|
|
$this->assertSession()->addressEquals($this->generatePageUrl('backend_shipment_show', ['id' => $shipment->getId()])); |
234
|
|
|
$this->assertStatusCodeEquals(200); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @Given /^I remove property choice number (\d+)$/ |
239
|
|
|
*/ |
240
|
|
|
public function iRemovePropertyChoiceInput($number) |
241
|
|
|
{ |
242
|
|
|
$this |
243
|
|
|
->getSession() |
244
|
|
|
->getPage() |
245
|
|
|
->find('css', sprintf('.sylius_property_choices_%d_delete', $number)) |
246
|
|
|
->click() |
247
|
|
|
; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @Given /^I am creating variant of "([^""]*)"$/ |
252
|
|
|
*/ |
253
|
|
|
public function iAmCreatingVariantOf($name) |
254
|
|
|
{ |
255
|
|
|
$product = $this->findOneByName('product', $name); |
256
|
|
|
|
257
|
|
|
$this->getSession()->visit($this->generatePageUrl('sylius_backend_product_variant_create', ['productId' => $product->getId()])); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* @Given /^I should be creating variant of "([^""]*)"$/ |
262
|
|
|
*/ |
263
|
|
|
public function iShouldBeCreatingVariantOf($name) |
264
|
|
|
{ |
265
|
|
|
$product = $this->findOneByName('product', $name); |
266
|
|
|
|
267
|
|
|
$this->assertSession()->addressEquals($this->generatePageUrl('sylius_backend_product_variant_create', ['productId' => $product->getId()])); |
268
|
|
|
$this->assertStatusCodeEquals(200); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* @Given /^I added product "([^""]*)" to cart$/ |
273
|
|
|
*/ |
274
|
|
|
public function iAddedProductToCart($productName) |
275
|
|
|
{ |
276
|
|
|
$this->iAmOnTheProductPage($productName); |
277
|
|
|
$this->pressButton('Add to cart'); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* @Given /^I fill in province name with "([^"]*)"$/ |
282
|
|
|
*/ |
283
|
|
|
public function iFillInProvinceNameWith($value) |
284
|
|
|
{ |
285
|
|
|
$this->fillField('sylius_country[provinces][0][name]', $value); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* @Given /^I fill in the (billing|shipping) address to (.+)$/ |
290
|
|
|
*/ |
291
|
|
|
public function iFillInCheckoutAddress($type, $country) |
292
|
|
|
{ |
293
|
|
|
$base = sprintf('sylius_checkout_addressing[%sAddress]', $type); |
294
|
|
|
|
295
|
|
|
$this->iFillInAddressFields($base, $country); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* @Given /^I fill in the users (billing|shipping) address to (.+)$/ |
300
|
|
|
*/ |
301
|
|
|
public function iFillInUserAddress($type, $country) |
302
|
|
|
{ |
303
|
|
|
$base = sprintf('%s[%sAddress]', 'sylius_user', $type); |
304
|
|
|
$this->iFillInAddressFields($base, $country); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* @Given /^I fill in the users account address to (.+)$/ |
309
|
|
|
*/ |
310
|
|
|
public function iFillInUserAccountAddress($country) |
311
|
|
|
{ |
312
|
|
|
$this->iFillInAddressFields('sylius_address', $country); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
protected function iFillInAddressFields($base, $country) |
316
|
|
|
{ |
317
|
|
|
$this->fillField($base.'[firstName]', 'John'); |
318
|
|
|
$this->fillField($base.'[lastName]', 'Doe'); |
319
|
|
|
$this->fillField($base.'[street]', 'Pvt. Street 15'); |
320
|
|
|
$this->fillField($base.'[city]', 'Lodz'); |
321
|
|
|
$this->fillField($base.'[postcode]', '95-253'); |
322
|
|
|
$this->selectOption($base.'[countryCode]', $country); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* @Given /^I select the "(?P<field>([^""]|\\")*)" radio button$/ |
327
|
|
|
*/ |
328
|
|
|
public function iSelectTheRadioButton($field) |
329
|
|
|
{ |
330
|
|
|
$field = str_replace('\\"', '"', $field); |
331
|
|
|
$radio = $this->getSession()->getPage()->findField($field); |
332
|
|
|
|
333
|
|
|
if (null === $radio) { |
334
|
|
|
throw new ElementNotFoundException( |
335
|
|
|
$this->getSession(), 'form field', 'id|name|label|value', $field |
336
|
|
|
); |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
$this->fillField($radio->getAttribute('name'), $radio->getAttribute('value')); |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
/** |
343
|
|
|
* @Then I should not see :position in the menu |
344
|
|
|
*/ |
345
|
|
|
public function iShouldNotSeeInTheMenu($position) |
346
|
|
|
{ |
347
|
|
|
$this->assertSession()->elementNotContains('css', sprintf('.sidebar-nav'), $position); |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* @Then I should see :position in the menu |
352
|
|
|
*/ |
353
|
|
|
public function iShouldSeeInTheMenu($position) |
354
|
|
|
{ |
355
|
|
|
$this->assertSession()->elementContains('css', sprintf('.sidebar-nav'), $position); |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
/** |
359
|
|
|
* @Then I should not see :button button |
360
|
|
|
*/ |
361
|
|
|
public function iShouldNotSeeButton($button) |
362
|
|
|
{ |
363
|
|
|
$this->assertSession()->elementNotExists('css', '.delete-action-form input[value="'.strtoupper($button).'"]'); |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
/** |
367
|
|
|
* @Then I should not see :button button near :user in :table table |
368
|
|
|
*/ |
369
|
|
|
public function iShouldNotSeeButtonInColumnInTable($button, $customer, $table) |
370
|
|
|
{ |
371
|
|
|
$this->assertSession()->elementExists('css', '#'.$table." tr[data-customer='$customer']"); |
372
|
|
|
$this->assertSession()->elementNotExists('css', '#'.$table." tr[data-customer='$customer'] form input[value=".strtoupper($button).']'); |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
/** |
376
|
|
|
* @Then /^I should see product prices in "([^"]*)"$/ |
377
|
|
|
*/ |
378
|
|
|
public function iShouldSeeProductPricesIn($code) |
379
|
|
|
{ |
380
|
|
|
$symbol = Intl::getCurrencyBundle()->getCurrencySymbol($code); |
381
|
|
|
$this->assertSession()->pageTextContains($symbol); |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
/** |
385
|
|
|
* @Then I should see :count available currencies |
386
|
|
|
*/ |
387
|
|
|
public function iShouldSeeAvailableCurrencies($count) |
388
|
|
|
{ |
389
|
|
|
$this->assertSession()->elementsCount('css', '.currency-menu ul li', $count); |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* @When I change the currency to :currency |
394
|
|
|
*/ |
395
|
|
|
public function iChangeTheCurrencyTo($code) |
396
|
|
|
{ |
397
|
|
|
$symbol = Intl::getCurrencyBundle()->getCurrencySymbol($code); |
398
|
|
|
$this->clickLink($symbol); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* @Then I should see :count available locales |
403
|
|
|
*/ |
404
|
|
|
public function iShouldSeeAvailableLocales($count) |
405
|
|
|
{ |
406
|
|
|
$this->assertSession()->elementsCount('css', '.locale-menu ul li', $count); |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
/** |
410
|
|
|
* @When I change the locale to :locale |
411
|
|
|
*/ |
412
|
|
|
public function iChangeTheLocaleTo($name) |
413
|
|
|
{ |
414
|
|
|
$this->clickLink($name); |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
/** |
418
|
|
|
* @Then I should browse the store in :locale |
419
|
|
|
*/ |
420
|
|
|
public function iShouldBrowseTheStoreInLocale($name) |
421
|
|
|
{ |
422
|
|
|
$text = 'Welcome to Sylius'; |
423
|
|
|
|
424
|
|
|
switch ($name) { |
425
|
|
|
case 'Polish': |
426
|
|
|
case 'Polish (Poland)': |
427
|
|
|
$text = 'Witaj w Sylius'; |
428
|
|
|
break; |
429
|
|
|
case 'German': |
430
|
|
|
case 'German (Germany)': |
431
|
|
|
$text = 'Englisch'; |
432
|
|
|
break; |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
$this->assertSession()->pageTextContains($text); |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
/** |
439
|
|
|
* For example: I should see 10 products. |
440
|
|
|
* |
441
|
|
|
* @Then /^I should see there (\d+) products/ |
442
|
|
|
*/ |
443
|
|
|
public function iShouldSeeThatMuchProducts($amount) |
444
|
|
|
{ |
445
|
|
|
$this->assertSession()->elementsCount('css', '.product', $amount); |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
/** |
449
|
|
|
* @Given /^I am on the product page for "([^"]*)"$/ |
450
|
|
|
* @Given /^I go to the product page for "([^"]*)"$/ |
451
|
|
|
*/ |
452
|
|
|
public function iAmOnTheProductPage($name) |
453
|
|
|
{ |
454
|
|
|
$product = $this->findOneBy('product', ['name' => $name]); |
455
|
|
|
|
456
|
|
|
$this->getSession()->visit($this->generatePageUrl($product)); |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
/** |
460
|
|
|
* @Then /^I should be on the product page for "([^"]*)"$/ |
461
|
|
|
* @Then /^I should still be on the product page for "([^"]*)"$/ |
462
|
|
|
*/ |
463
|
|
|
public function iShouldBeOnTheProductPage($name) |
464
|
|
|
{ |
465
|
|
|
$product = $this->findOneBy('product', ['name' => $name]); |
466
|
|
|
|
467
|
|
|
$this->assertSession()->addressEquals($this->generateUrl($product)); |
|
|
|
|
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
/** |
471
|
|
|
* @Given /^I am on the order ([^""]*) page for (\d+)$/ |
472
|
|
|
* @Given /^I go to the order ([^""]*) page for (\d+)$/ |
473
|
|
|
*/ |
474
|
|
|
public function iAmOnTheOrderPage($action, $number) |
475
|
|
|
{ |
476
|
|
|
$order = $this->findOneBy('order', ['number' => $number]); |
477
|
|
|
|
478
|
|
|
$this->getSession()->visit($this->generatePageUrl('sylius_account_order_'.$action, ['number' => $order->getNumber()])); |
479
|
|
|
} |
480
|
|
|
|
481
|
|
|
/** |
482
|
|
|
* @Then /^I should be on the order ([^""]*) page for (\d+)$/ |
483
|
|
|
* @Then /^I should still be on the order ([^""]*) page for (\d+)$/ |
484
|
|
|
*/ |
485
|
|
|
public function iShouldBeOnTheOrderPage($action, $number) |
486
|
|
|
{ |
487
|
|
|
$this->assertSession()->addressEquals($this->generatePageUrl('sylius_account_order_'.$action, ['number' => $number])); |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
/** |
491
|
|
|
* @Given /^I am not authenticated$/ |
492
|
|
|
* @Given /^I am not logged in anymore$/ |
493
|
|
|
*/ |
494
|
|
|
public function iAmNotAuthenticated() |
495
|
|
|
{ |
496
|
|
|
$this->getTokenStorage()->setToken(null); |
497
|
|
|
$this->getContainer()->get('session')->invalidate(); |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
/** |
501
|
|
|
* @Given /^I log in with "([^""]*)" and "([^""]*)"$/ |
502
|
|
|
*/ |
503
|
|
|
public function iLogInWith($email, $password) |
504
|
|
|
{ |
505
|
|
|
$this->getSession()->visit($this->generatePageUrl('sylius_user_security_login')); |
506
|
|
|
|
507
|
|
|
$this->fillField('Email', $email); |
508
|
|
|
$this->fillField('Password', $password); |
509
|
|
|
$this->pressButton('Login'); |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
/** |
513
|
|
|
* @Given /^I add following option values:$/ |
514
|
|
|
*/ |
515
|
|
|
public function iAddFollowingOptionValues(TableNode $table) |
516
|
|
|
{ |
517
|
|
|
foreach ($table->getRows() as $value) { |
518
|
|
|
$newItem = $this->addNewItemToFormCollection($this->getSession()->getPage(), 'option_values'); |
519
|
|
|
$newItem->fillField('Value', $value[1]); |
520
|
|
|
$newItem->fillField('Code', $value[0]); |
521
|
|
|
} |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
/** |
525
|
|
|
* @When /^I add option value "([^""]*)"$/ |
526
|
|
|
*/ |
527
|
|
|
public function iAddOptionValue($optionValue) |
528
|
|
|
{ |
529
|
|
|
$newItem = $this->addNewItemToFormCollection($this->getSession()->getPage(), 'option_values'); |
530
|
|
|
$newItem->fillField('Value', $optionValue); |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
/** |
534
|
|
|
* @Given /^I add choice "([^""]*)"$/ |
535
|
|
|
*/ |
536
|
|
|
public function iAddChoice($value) |
537
|
|
|
{ |
538
|
|
|
$newItem = $this->addNewItemToFormCollection($this->getSession()->getPage(), 'choices'); |
539
|
|
|
$newItem->find('css', 'input')->setValue($value); |
540
|
|
|
} |
541
|
|
|
|
542
|
|
|
/** |
543
|
|
|
* @When I want to create a :type zone |
544
|
|
|
*/ |
545
|
|
|
public function iWantToCreateZoneOfType($type) |
546
|
|
|
{ |
547
|
|
|
$this->selectOption('zone_type', $type); |
548
|
|
|
} |
549
|
|
|
|
550
|
|
|
/** |
551
|
|
|
* @When /^I add zone member "([^"]+)"$/ |
552
|
|
|
*/ |
553
|
|
|
public function iAddZoneMember($zoneMember) |
554
|
|
|
{ |
555
|
|
|
$newItem = $this->addNewItemToFormCollection($this->getSession()->getPage(), 'zone_members'); |
556
|
|
|
$select = $newItem->find('css', 'select'); |
557
|
|
|
|
558
|
|
|
if (null === $select) { |
559
|
|
|
throw new \Exception('There is no select field available!'); |
560
|
|
|
} |
561
|
|
|
|
562
|
|
|
$select->selectOption($zoneMember); |
563
|
|
|
} |
564
|
|
|
|
565
|
|
|
/** |
566
|
|
|
* @Given /^I remove first choice$/ |
567
|
|
|
*/ |
568
|
|
|
public function iRemoveFirstChoice() |
569
|
|
|
{ |
570
|
|
|
$collection = $this->getFormCollectionDiv($this->getSession()->getPage(), 'choices'); |
571
|
|
|
|
572
|
|
|
/** @var NodeElement $firstItem */ |
573
|
|
|
$firstItem = current($collection->findAll('css', 'div[data-form-collection="item"]')); |
574
|
|
|
|
575
|
|
|
$firstItem->clickLink('Delete'); |
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
/** |
579
|
|
|
* @When /^I click the login with (.+) button$/ |
580
|
|
|
* @When /^I press the login with (.+) button$/ |
581
|
|
|
*/ |
582
|
|
|
public function iClickTheLoginWithButton($provider) |
583
|
|
|
{ |
584
|
|
|
$loginButton = $this->getSession()->getPage()->find('css', sprintf('a.oauth-login-%s', strtolower($provider))); |
585
|
|
|
$loginButton->click(); |
586
|
|
|
|
587
|
|
|
// Re-set default session |
588
|
|
|
$currentUrl = $this->getSession()->getCurrentUrl(); |
589
|
|
|
$this->getMink()->setDefaultSessionName('goutte'); |
590
|
|
|
$this->getSession()->visit($currentUrl); |
591
|
|
|
} |
592
|
|
|
|
593
|
|
|
/** |
594
|
|
|
* @Given /^I added product "([^""]*)" to cart, with quantity "([^""]*)"$/ |
595
|
|
|
* @When /^I add product "([^""]*)" to cart, with quantity "([^""]*)"$/ |
596
|
|
|
*/ |
597
|
|
|
public function iAddedProductToCartWithQuantity($productName, $quantity) |
598
|
|
|
{ |
599
|
|
|
$this->iAmOnTheProductPage($productName); |
600
|
|
|
$this->fillField('Quantity', $quantity); |
601
|
|
|
$this->pressButton('Add to cart'); |
602
|
|
|
} |
603
|
|
|
|
604
|
|
|
/** |
605
|
|
|
* @Given /^I finish the checkout process$/ |
606
|
|
|
*/ |
607
|
|
|
public function iFinishTheCheckoutProcess() |
608
|
|
|
{ |
609
|
|
|
$this->iFillInCheckoutAddress('shipping', 'United Kingdom'); |
610
|
|
|
$this->pressButton('Continue'); |
611
|
|
|
$this->iSelectTheRadioButton('DHL Express'); |
612
|
|
|
$this->pressButton('Continue'); |
613
|
|
|
$this->iSelectTheRadioButton('Credit Card'); |
614
|
|
|
$this->pressButton('Continue'); |
615
|
|
|
$this->iClick('Place order'); |
616
|
|
|
$this->assertSession()->pageTextContains('Thank you'); |
617
|
|
|
} |
618
|
|
|
|
619
|
|
|
/** |
620
|
|
|
* @Then /^I should see ([^""]*) "([^""]*)" for "([^""]*)"$/ |
621
|
|
|
*/ |
622
|
|
|
public function iShouldSeeQuantityFor($property, $expectedValue, $item) |
623
|
|
|
{ |
624
|
|
|
$tr = $this->assertSession()->elementExists('css', sprintf('table tbody tr:contains("%s")', $item)); |
625
|
|
|
$rows = $this->getSession()->getPage()->findAll('css', 'table thead tr th'); |
626
|
|
|
|
627
|
|
|
$column = null; |
628
|
|
|
foreach ($rows as $key => $row) { |
629
|
|
|
if (strtolower(trim($row->getText())) === strtolower(trim($property))) { |
630
|
|
|
$column = $key; |
631
|
|
|
break; |
632
|
|
|
} |
633
|
|
|
} |
634
|
|
|
|
635
|
|
|
$cols = $tr->findAll('css', 'td'); |
636
|
|
|
|
637
|
|
|
\PHPUnit_Framework_Assert::assertEquals($expectedValue, $cols[$column]->getText()); |
638
|
|
|
} |
639
|
|
|
|
640
|
|
|
/** |
641
|
|
|
* @Given I view deleted elements |
642
|
|
|
*/ |
643
|
|
|
public function iViewDeletedElements() |
644
|
|
|
{ |
645
|
|
|
$this->clickLink('Show deleted'); |
646
|
|
|
} |
647
|
|
|
|
648
|
|
|
/** |
649
|
|
|
* @Given I registered with email :email and password :password |
650
|
|
|
*/ |
651
|
|
|
public function iRegisteredWithEmailAndPassword($email, $password) |
652
|
|
|
{ |
653
|
|
|
$this->getSession()->visit($this->generatePageUrl('sylius_user_registration')); |
654
|
|
|
|
655
|
|
|
$this->fillField('First name', $this->faker->firstName); |
656
|
|
|
$this->fillField('Last name', $this->faker->lastName); |
657
|
|
|
$this->fillField('Email', $email); |
658
|
|
|
$this->fillField('Password', $password); |
659
|
|
|
$this->fillField('Verification', $password); |
660
|
|
|
$this->pressButton('Register'); |
661
|
|
|
} |
662
|
|
|
|
663
|
|
|
/** |
664
|
|
|
* @When /^(?:|I )fill in guest email with "(?P<value>(?:[^"]|\\")*)"$/ |
665
|
|
|
*/ |
666
|
|
|
public function fillGuestEmail($value) |
667
|
|
|
{ |
668
|
|
|
$value = $this->fixStepArgument($value); |
669
|
|
|
$this->getSession()->getPage()->fillField('sylius_customer_guest[email]', $value); |
670
|
|
|
} |
671
|
|
|
|
672
|
|
|
/** |
673
|
|
|
* @When /^I display ([^""]*)$/ |
674
|
|
|
*/ |
675
|
|
|
public function iDisplayPage($page) |
676
|
|
|
{ |
677
|
|
|
$pageMapping = [ |
678
|
|
|
'my orders history' => 'sylius_account_order_index', |
679
|
|
|
'my address book' => 'sylius_account_address_index', |
680
|
|
|
]; |
681
|
|
|
|
682
|
|
|
$this->getSession()->visit($this->generatePageUrl($pageMapping[$page])); |
683
|
|
|
} |
684
|
|
|
|
685
|
|
|
/** |
686
|
|
|
* @When I restart my browser |
687
|
|
|
*/ |
688
|
|
|
public function iRestartMyBrowser() |
689
|
|
|
{ |
690
|
|
|
$session = $this->getSession(); |
691
|
|
|
$cookie = $session->getCookie('REMEMBERME'); |
692
|
|
|
|
693
|
|
|
$session->restart(); |
694
|
|
|
$session->setCookie('REMEMBERME', $cookie); |
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
/** |
698
|
|
|
* @Given /^I go to page for product with empty slug$/ |
699
|
|
|
*/ |
700
|
|
|
public function iGoToPageForProductWithEmptySlug() |
701
|
|
|
{ |
702
|
|
|
$this->visitPath('/p/'); |
703
|
|
|
} |
704
|
|
|
|
705
|
|
|
/** |
706
|
|
|
* @Given /^I have changed my account password to "([^""]*)"$/ |
707
|
|
|
* @When /^I change my account password to "([^""]*)"$/ |
708
|
|
|
*/ |
709
|
|
|
public function iChangeMyPasswordTo($newPassword) |
710
|
|
|
{ |
711
|
|
|
$this->getSession()->visit($this->generatePageUrl('sylius_account_change_password')); |
712
|
|
|
$this->fillField('Current password', 'sylius'); |
713
|
|
|
$this->fillField('New password', $newPassword); |
714
|
|
|
$this->fillField('Confirmation', $newPassword); |
715
|
|
|
$this->pressButton('Save changes'); |
716
|
|
|
} |
717
|
|
|
|
718
|
|
|
/** |
719
|
|
|
* @Then the code field should be disabled |
720
|
|
|
* @Then I should see disabled code field |
721
|
|
|
*/ |
722
|
|
|
public function theCodeFieldShouldBeDisabled() |
723
|
|
|
{ |
724
|
|
|
$this->assertSession()->elementAttributeContains('css', '[id$="code"]', 'disabled', 'disabled'); |
725
|
|
|
} |
726
|
|
|
|
727
|
|
|
/** |
728
|
|
|
* @Then the customer should have username :username |
729
|
|
|
*/ |
730
|
|
|
public function theCustomerWithEmailShouldHaveUsername($username) |
731
|
|
|
{ |
732
|
|
|
$this->assertSession()->elementContains('css', '#username', $username); |
733
|
|
|
} |
734
|
|
|
|
735
|
|
|
/** |
736
|
|
|
* @Then the customer should be enabled |
737
|
|
|
*/ |
738
|
|
|
public function theCustomerShouldBeEnabled() |
739
|
|
|
{ |
740
|
|
|
$this->assertSession()->elementContains('css', '#enabled', 'yes'); |
741
|
|
|
} |
742
|
|
|
|
743
|
|
|
private function assertRoute($route) |
744
|
|
|
{ |
745
|
|
|
$this->assertSession()->addressEquals($this->generatePageUrl($route)); |
746
|
|
|
|
747
|
|
|
try { |
748
|
|
|
$this->assertStatusCodeEquals(200); |
749
|
|
|
} catch (UnsupportedDriverActionException $e) { |
750
|
|
|
} |
751
|
|
|
} |
752
|
|
|
|
753
|
|
|
/** |
754
|
|
|
* @param DocumentElement $page |
755
|
|
|
* @param string $collectionName |
756
|
|
|
* |
757
|
|
|
* @return NodeElement |
758
|
|
|
*/ |
759
|
|
|
protected function getFormCollectionDiv(DocumentElement $page, $collectionName) |
760
|
|
|
{ |
761
|
|
|
return $page->find('css', 'div[data-form-type="collection"][id*="'.$collectionName.'"]'); |
762
|
|
|
} |
763
|
|
|
|
764
|
|
|
/** |
765
|
|
|
* @param DocumentElement $page |
766
|
|
|
* @param string $collectionName |
767
|
|
|
* |
768
|
|
|
* @return NodeElement |
769
|
|
|
*/ |
770
|
|
|
protected function addNewItemToFormCollection(DocumentElement $page, $collectionName) |
771
|
|
|
{ |
772
|
|
|
$collection = $this->getFormCollectionDiv($page, $collectionName); |
773
|
|
|
|
774
|
|
|
$collection->find('css', 'a[data-form-collection="add"]')->click(); |
775
|
|
|
|
776
|
|
|
$items = $collection->findAll('css', 'div[data-form-collection="item"]'); |
777
|
|
|
|
778
|
|
|
return end($items); |
779
|
|
|
} |
780
|
|
|
} |
781
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: