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\Admin; |
15
|
|
|
|
16
|
|
|
use Behat\Behat\Context\Context; |
17
|
|
|
use Sylius\Behat\Page\Admin\Taxon\CreateForParentPageInterface; |
18
|
|
|
use Sylius\Behat\Page\Admin\Taxon\CreatePageInterface; |
19
|
|
|
use Sylius\Behat\Page\Admin\Taxon\UpdatePageInterface; |
20
|
|
|
use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface; |
21
|
|
|
use Sylius\Behat\Service\SharedStorageInterface; |
22
|
|
|
use Sylius\Component\Core\Model\TaxonInterface; |
23
|
|
|
use Webmozart\Assert\Assert; |
24
|
|
|
|
25
|
|
|
final class ManagingTaxonsContext implements Context |
26
|
|
|
{ |
27
|
|
|
/** @var SharedStorageInterface */ |
28
|
|
|
private $sharedStorage; |
29
|
|
|
|
30
|
|
|
/** @var CreatePageInterface */ |
31
|
|
|
private $createPage; |
32
|
|
|
|
33
|
|
|
/** @var CreateForParentPageInterface */ |
34
|
|
|
private $createForParentPage; |
35
|
|
|
|
36
|
|
|
/** @var UpdatePageInterface */ |
37
|
|
|
private $updatePage; |
38
|
|
|
|
39
|
|
|
/** @var CurrentPageResolverInterface */ |
40
|
|
|
private $currentPageResolver; |
41
|
|
|
|
42
|
|
|
public function __construct( |
43
|
|
|
SharedStorageInterface $sharedStorage, |
44
|
|
|
CreatePageInterface $createPage, |
45
|
|
|
CreateForParentPageInterface $createForParentPage, |
46
|
|
|
UpdatePageInterface $updatePage, |
47
|
|
|
CurrentPageResolverInterface $currentPageResolver |
48
|
|
|
) { |
49
|
|
|
$this->sharedStorage = $sharedStorage; |
50
|
|
|
$this->createPage = $createPage; |
51
|
|
|
$this->createForParentPage = $createForParentPage; |
52
|
|
|
$this->updatePage = $updatePage; |
53
|
|
|
$this->currentPageResolver = $currentPageResolver; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @Given I want to create a new taxon |
58
|
|
|
* @Given I want to see all taxons in store |
59
|
|
|
*/ |
60
|
|
|
public function iWantToCreateANewTaxon() |
61
|
|
|
{ |
62
|
|
|
$this->createPage->open(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @Given I want to create a new taxon for :taxon |
67
|
|
|
*/ |
68
|
|
|
public function iWantToCreateANewTaxonForParent(TaxonInterface $taxon) |
69
|
|
|
{ |
70
|
|
|
$this->createForParentPage->open(['id' => $taxon->getId()]); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @Given /^I want to modify the ("[^"]+" taxon)$/ |
75
|
|
|
*/ |
76
|
|
|
public function iWantToModifyATaxon(TaxonInterface $taxon) |
77
|
|
|
{ |
78
|
|
|
$this->sharedStorage->set('taxon', $taxon); |
79
|
|
|
|
80
|
|
|
$this->updatePage->open(['id' => $taxon->getId()]); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @When I specify its code as :code |
85
|
|
|
* @When I do not specify its code |
86
|
|
|
*/ |
87
|
|
|
public function iSpecifyItsCodeAs(?string $code = null) |
88
|
|
|
{ |
89
|
|
|
$this->createPage->specifyCode($code ?? ''); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @When I name it :name in :language |
94
|
|
|
* @When I rename it to :name in :language |
95
|
|
|
* @When I do not specify its name |
96
|
|
|
*/ |
97
|
|
|
public function iNameItIn(?string $name = null, $language = 'en_US') |
98
|
|
|
{ |
99
|
|
|
$currentPage = $this->resolveCurrentPage(); |
100
|
|
|
|
101
|
|
|
$currentPage->nameIt($name ?? '', $language); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @When I set its slug to :slug |
106
|
|
|
* @When I do not specify its slug |
107
|
|
|
* @When I set its slug to :slug in :language |
108
|
|
|
*/ |
109
|
|
|
public function iSetItsSlugToIn(?string $slug = null, $language = 'en_US') |
110
|
|
|
{ |
111
|
|
|
$currentPage = $this->resolveCurrentPage(); |
112
|
|
|
|
113
|
|
|
$currentPage->specifySlug($slug ?? '', $language); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @Then the slug field should not be editable |
118
|
|
|
* @Then the slug field should (also )not be editable in :language |
119
|
|
|
*/ |
120
|
|
|
public function theSlugFieldShouldNotBeEditable($language = 'en_US') |
121
|
|
|
{ |
122
|
|
|
Assert::true($this->updatePage->isSlugReadonly($language)); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @When I enable slug modification |
127
|
|
|
* @When I enable slug modification in :language |
128
|
|
|
*/ |
129
|
|
|
public function iEnableSlugModification($language = 'en_US') |
130
|
|
|
{ |
131
|
|
|
$this->updatePage->activateLanguageTab($language); |
132
|
|
|
$this->updatePage->enableSlugModification($language); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @When I change its description to :description in :language |
137
|
|
|
*/ |
138
|
|
|
public function iChangeItsDescriptionToIn($description, $language) |
139
|
|
|
{ |
140
|
|
|
$this->updatePage->describeItAs($description, $language); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @When I describe it as :description in :language |
145
|
|
|
*/ |
146
|
|
|
public function iDescribeItAs($description, $language) |
147
|
|
|
{ |
148
|
|
|
$this->createPage->describeItAs($description, $language); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @Given /^I change its (parent taxon to "[^"]+")$/ |
153
|
|
|
*/ |
154
|
|
|
public function iChangeItsParentTaxonTo(TaxonInterface $taxon) |
155
|
|
|
{ |
156
|
|
|
$this->updatePage->chooseParent($taxon); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @When I add it |
161
|
|
|
* @When I try to add it |
162
|
|
|
*/ |
163
|
|
|
public function iAddIt() |
164
|
|
|
{ |
165
|
|
|
$this->createPage->create(); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @When I save my changes |
170
|
|
|
* @When I try to save my changes |
171
|
|
|
*/ |
172
|
|
|
public function iSaveMyChanges() |
173
|
|
|
{ |
174
|
|
|
$this->updatePage->saveChanges(); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @Then /^the ("[^"]+" taxon) should appear in the registry$/ |
179
|
|
|
*/ |
180
|
|
|
public function theTaxonShouldAppearInTheRegistry(TaxonInterface $taxon) |
181
|
|
|
{ |
182
|
|
|
$this->updatePage->open(['id' => $taxon->getId()]); |
183
|
|
|
Assert::true($this->updatePage->hasResourceValues(['code' => $taxon->getCode()])); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @Then this taxon :element should be :value |
188
|
|
|
*/ |
189
|
|
|
public function thisTaxonElementShouldBe($element, $value) |
190
|
|
|
{ |
191
|
|
|
Assert::true($this->updatePage->hasResourceValues([$element => $value])); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @Then this taxon should have slug :value in :language |
196
|
|
|
*/ |
197
|
|
|
public function thisTaxonElementShouldHaveSlugIn($value, $language = null) |
198
|
|
|
{ |
199
|
|
|
if (null !== $language) { |
200
|
|
|
$this->updatePage->activateLanguageTab($language ?? ''); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
Assert::same($this->updatePage->getSlug($language ?? ''), $value); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @Then the code field should be disabled |
208
|
|
|
*/ |
209
|
|
|
public function theCodeFieldShouldBeDisabled() |
210
|
|
|
{ |
211
|
|
|
Assert::true($this->updatePage->isCodeDisabled()); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @Then /^the slug of the ("[^"]+" taxon) should(?:| still) be "([^"]+)"$/ |
216
|
|
|
*/ |
217
|
|
|
public function productSlugShouldBe(TaxonInterface $taxon, $slug) |
218
|
|
|
{ |
219
|
|
|
$this->updatePage->open(['id' => $taxon->getId()]); |
220
|
|
|
|
221
|
|
|
Assert::true($this->updatePage->hasResourceValues(['slug' => $slug])); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @Then /^this taxon should (belongs to "[^"]+")$/ |
226
|
|
|
*/ |
227
|
|
|
public function thisTaxonShouldBelongsTo(TaxonInterface $taxon) |
228
|
|
|
{ |
229
|
|
|
Assert::true($this->updatePage->hasResourceValues(['parent' => $taxon->getCode()])); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @Given it should not belong to any other taxon |
234
|
|
|
*/ |
235
|
|
|
public function itShouldNotBelongToAnyOtherTaxon() |
236
|
|
|
{ |
237
|
|
|
Assert::isEmpty($this->updatePage->getParent()); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @Then I should be notified that taxon with this code already exists |
242
|
|
|
*/ |
243
|
|
|
public function iShouldBeNotifiedThatTaxonWithThisCodeAlreadyExists() |
244
|
|
|
{ |
245
|
|
|
$currentPage = $this->resolveCurrentPage(); |
246
|
|
|
|
247
|
|
|
Assert::same($currentPage->getValidationMessage('code'), 'Taxon with given code already exists.'); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @Then I should be notified that taxon slug must be unique |
252
|
|
|
*/ |
253
|
|
|
public function iShouldBeNotifiedThatTaxonSlugMustBeUnique() |
254
|
|
|
{ |
255
|
|
|
$currentPage = $this->resolveCurrentPage(); |
256
|
|
|
|
257
|
|
|
Assert::same($currentPage->getValidationMessage('slug'), 'Taxon slug must be unique.'); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* @Then I should be notified that :element is required |
262
|
|
|
*/ |
263
|
|
|
public function iShouldBeNotifiedThatIsRequired($element) |
264
|
|
|
{ |
265
|
|
|
$currentPage = $this->resolveCurrentPage(); |
266
|
|
|
|
267
|
|
|
Assert::same($currentPage->getValidationMessage($element), sprintf('Please enter taxon %s.', $element)); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @Then /^there should(?:| still) be only one taxon with code "([^"]+)"$/ |
272
|
|
|
*/ |
273
|
|
|
public function thereShouldStillBeOnlyOneTaxonWithCode($code) |
274
|
|
|
{ |
275
|
|
|
Assert::true($this->updatePage->hasResourceValues(['code' => $code])); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* @Then /^taxon named "([^"]+)" should not be added$/ |
280
|
|
|
* @Then the taxon named :name should no longer exist in the registry |
281
|
|
|
*/ |
282
|
|
|
public function taxonNamedShouldNotBeAdded($name) |
283
|
|
|
{ |
284
|
|
|
Assert::same($this->createPage->countTaxonsByName($name), 0); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* @Then /^I should see (\d+) taxons on the list$/ |
289
|
|
|
*/ |
290
|
|
|
public function iShouldSeeTaxonsInTheList($number) |
291
|
|
|
{ |
292
|
|
|
Assert::same($this->createPage->countTaxons(), (int) $number); |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* @Then I should see the taxon named :name in the list |
297
|
|
|
*/ |
298
|
|
|
public function iShouldSeeTheTaxonNamedInTheList($name) |
299
|
|
|
{ |
300
|
|
|
Assert::same($this->createPage->countTaxonsByName($name), 1); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* @When I attach the :path image with :type type |
305
|
|
|
* @When I attach the :path image |
306
|
|
|
*/ |
307
|
|
|
public function iAttachImageWithType($path, $type = null) |
308
|
|
|
{ |
309
|
|
|
$currentPage = $this->resolveCurrentPage(); |
310
|
|
|
|
311
|
|
|
$currentPage->attachImage($path, $type); |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* @Then /^(?:it|this taxon) should(?:| also) have an image with "([^"]*)" type$/ |
316
|
|
|
*/ |
317
|
|
|
public function thisTaxonShouldHaveAnImageWithType($type) |
318
|
|
|
{ |
319
|
|
|
Assert::true($this->updatePage->isImageWithTypeDisplayed($type)); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* @Then /^(?:this taxon|it) should not have(?:| also) any images with "([^"]*)" type$/ |
324
|
|
|
*/ |
325
|
|
|
public function thisTaxonShouldNotHaveAnImageWithType($code) |
326
|
|
|
{ |
327
|
|
|
Assert::false($this->updatePage->isImageWithTypeDisplayed($code)); |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* @When /^I(?:| also) remove an image with "([^"]*)" type$/ |
332
|
|
|
*/ |
333
|
|
|
public function iRemoveAnImageWithType($code) |
334
|
|
|
{ |
335
|
|
|
$this->updatePage->removeImageWithType($code); |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* @When I remove the first image |
340
|
|
|
*/ |
341
|
|
|
public function iRemoveTheFirstImage() |
342
|
|
|
{ |
343
|
|
|
$this->updatePage->removeFirstImage(); |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* @Then /^(this taxon) should not have any images$/ |
348
|
|
|
*/ |
349
|
|
|
public function thisTaxonShouldNotHaveAnyImages(TaxonInterface $taxon) |
350
|
|
|
{ |
351
|
|
|
$this->iWantToModifyATaxon($taxon); |
352
|
|
|
|
353
|
|
|
Assert::same($this->updatePage->countImages(), 0); |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* @When I change the image with the :type type to :path |
358
|
|
|
*/ |
359
|
|
|
public function iChangeItsImageToPathForTheType($path, $type) |
360
|
|
|
{ |
361
|
|
|
$this->updatePage->changeImageWithType($type, $path); |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
/** |
365
|
|
|
* @When I change the first image type to :type |
366
|
|
|
*/ |
367
|
|
|
public function iChangeTheFirstImageTypeTo($type) |
368
|
|
|
{ |
369
|
|
|
$this->updatePage->modifyFirstImageType($type); |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* @Then /^(this taxon) should have only one image$/ |
374
|
|
|
* @Then /^(this taxon) should(?:| still) have (\d+) images?$/ |
375
|
|
|
*/ |
376
|
|
|
public function thereShouldStillBeOnlyOneImageInThisTaxon(TaxonInterface $taxon, $count = 1) |
377
|
|
|
{ |
378
|
|
|
$this->iWantToModifyATaxon($taxon); |
379
|
|
|
|
380
|
|
|
Assert::same($this->updatePage->countImages(), (int) $count); |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* @return CreatePageInterface|CreateForParentPageInterface|UpdatePageInterface |
385
|
|
|
*/ |
386
|
|
|
private function resolveCurrentPage() |
387
|
|
|
{ |
388
|
|
|
return $this->currentPageResolver->getCurrentPageWithForm([ |
389
|
|
|
$this->createPage, |
390
|
|
|
$this->createForParentPage, |
391
|
|
|
$this->updatePage, |
392
|
|
|
]); |
393
|
|
|
} |
394
|
|
|
} |
395
|
|
|
|