Completed
Push — locale-in-url ( c8ed20...ec55a8 )
by Kamil
46:19 queued 21:47
created

theSlugFieldShouldNotBeEditable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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