Completed
Push — api ( cecea0...116a36 )
by Kamil
29:57 queued 30s
created

theCodeFieldShouldBeDisabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Crud\IndexPageInterface;
18
use Sylius\Behat\Page\Admin\ProductOption\CreatePageInterface;
19
use Sylius\Behat\Page\Admin\ProductOption\UpdatePageInterface;
20
use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface;
21
use Sylius\Component\Product\Model\ProductOptionInterface;
22
use Webmozart\Assert\Assert;
23
24
final class ManagingProductOptionsContext implements Context
25
{
26
    /** @var IndexPageInterface */
27
    private $indexPage;
28
29
    /** @var CreatePageInterface */
30
    private $createPage;
31
32
    /** @var UpdatePageInterface */
33
    private $updatePage;
34
35
    /** @var CurrentPageResolverInterface */
36
    private $currentPageResolver;
37
38
    public function __construct(
39
        IndexPageInterface $indexPage,
40
        CreatePageInterface $createPage,
41
        UpdatePageInterface $updatePage,
42
        CurrentPageResolverInterface $currentPageResolver
43
    ) {
44
        $this->indexPage = $indexPage;
45
        $this->createPage = $createPage;
46
        $this->updatePage = $updatePage;
47
        $this->currentPageResolver = $currentPageResolver;
48
    }
49
50
    /**
51
     * @Given I want to create a new product option
52
     */
53
    public function iWantToCreateANewProductOption()
54
    {
55
        $this->createPage->open();
56
    }
57
58
    /**
59
     * @Given I want to modify the :productOption product option
60
     */
61
    public function iWantToModifyAProductOption(ProductOptionInterface $productOption)
62
    {
63
        $this->updatePage->open(['id' => $productOption->getId()]);
64
    }
65
66
    /**
67
     * @When I browse product options
68
     */
69
    public function iBrowseProductOptions()
70
    {
71
        $this->indexPage->open();
72
    }
73
74
    /**
75
     * @When I add it
76
     * @When I try to add it
77
     */
78
    public function iAddIt()
79
    {
80
        $this->createPage->create();
81
    }
82
83
    /**
84
     * @When I save my changes
85
     * @When I try to save my changes
86
     */
87
    public function iSaveMyChanges()
88
    {
89
        $this->updatePage->saveChanges();
90
    }
91
92
    /**
93
     * @When I name it :name in :language
94
     */
95
    public function iNameItInLanguage($name, $language)
96
    {
97
        $this->createPage->nameItIn($name, $language);
98
    }
99
100
    /**
101
     * @When I rename it to :name in :language
102
     * @When I remove its name from :language translation
103
     */
104
    public function iRenameItToInLanguage($name = null, $language)
105
    {
106
        $this->updatePage->nameItIn($name ?? '', $language);
107
    }
108
109
    /**
110
     * @When I do not name it
111
     */
112
    public function iDoNotNameIt()
113
    {
114
        // Intentionally left blank to fulfill context expectation
115
    }
116
117
    /**
118
     * @When I specify its code as :code
119
     * @When I do not specify its code
120
     */
121
    public function iSpecifyItsCodeAs($code = null)
122
    {
123
        $this->createPage->specifyCode($code ?? '');
124
    }
125
126
    /**
127
     * @When I add the :value option value identified by :code
128
     */
129
    public function iAddTheOptionValueWithCodeAndValue($value, $code)
130
    {
131
        /** @var CreatePageInterface|UpdatePageInterface $currentPage */
132
        $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);
133
134
        $currentPage->addOptionValue($code, $value);
135
    }
136
137
    /**
138
     * @When I check (also) the :productOptionName product option
139
     */
140
    public function iCheckTheProductOption(string $productOptionName): void
141
    {
142
        $this->indexPage->checkResourceOnPage(['name' => $productOptionName]);
143
    }
144
145
    /**
146
     * @When I delete them
147
     */
148
    public function iDeleteThem(): void
149
    {
150
        $this->indexPage->bulkDelete();
151
    }
152
153
    /**
154
     * @Then I should see the product option :productOptionName in the list
155
     * @Then the product option :productOptionName should appear in the registry
156
     * @Then the product option :productOptionName should be in the registry
157
     */
158
    public function theProductOptionShouldAppearInTheRegistry(string $productOptionName): void
159
    {
160
        $this->iBrowseProductOptions();
161
162
        Assert::true($this->indexPage->isSingleResourceOnPage(['name' => $productOptionName]));
163
    }
164
165
    /**
166
     * @Then I should be notified that product option with this code already exists
167
     */
168
    public function iShouldBeNotifiedThatProductOptionWithThisCodeAlreadyExists()
169
    {
170
        Assert::same($this->createPage->getValidationMessage('code'), 'The option with given code already exists.');
171
    }
172
173
    /**
174
     * @Then there should still be only one product option with :element :value
175
     */
176
    public function thereShouldStillBeOnlyOneProductOptionWith($element, $value)
177
    {
178
        $this->iBrowseProductOptions();
179
180
        Assert::true($this->indexPage->isSingleResourceOnPage([$element => $value]));
181
    }
182
183
    /**
184
     * @Then I should be notified that :element is required
185
     */
186
    public function iShouldBeNotifiedThatElementIsRequired($element)
187
    {
188
        Assert::same($this->createPage->getValidationMessage($element), sprintf('Please enter option %s.', $element));
189
    }
190
191
    /**
192
     * @Then the product option with :element :value should not be added
193
     */
194
    public function theProductOptionWithElementValueShouldNotBeAdded($element, $value)
195
    {
196
        $this->iBrowseProductOptions();
197
198
        Assert::false($this->indexPage->isSingleResourceOnPage([$element => $value]));
199
    }
200
201
    /**
202
     * @Then /^(this product option) should still be named "([^"]+)"$/
203
     * @Then /^(this product option) name should be "([^"]+)"$/
204
     */
205
    public function thisProductOptionNameShouldStillBe(ProductOptionInterface $productOption, $productOptionName)
206
    {
207
        $this->iBrowseProductOptions();
208
209
        Assert::true($this->indexPage->isSingleResourceOnPage([
210
            'code' => $productOption->getCode(),
211
            'name' => $productOptionName,
212
        ]));
213
    }
214
215
    /**
216
     * @Then I should not be able to edit its code
217
     */
218
    public function iShouldNotBeAbleToEditItsCode(): void
219
    {
220
        Assert::true($this->updatePage->isCodeDisabled());
221
    }
222
223
    /**
224
     * @When I do not add an option value
225
     */
226
    public function iDoNotAddAnOptionValue()
227
    {
228
        // Intentionally left blank to fulfill context expectation
229
    }
230
231
    /**
232
     * @Then I should be notified that at least two option values are required
233
     */
234
    public function iShouldBeNotifiedThatAtLeastTwoOptionValuesAreRequired()
235
    {
236
        Assert::true($this->createPage->checkValidationMessageForOptionValues('Please add at least 2 option values.'));
237
    }
238
239
    /**
240
     * @Then I should see a single product option in the list
241
     * @Then I should see :amount product options in the list
242
     */
243
    public function iShouldSeeProductOptionsInTheList(int $amount = 1): void
244
    {
245
        Assert::same($this->indexPage->countItems(), $amount);
246
    }
247
248
    /**
249
     * @Then /^(this product option) should have the "([^"]*)" option value$/
250
     * @Then /^(product option "[^"]+") should have the "([^"]*)" option value$/
251
     */
252
    public function thisProductOptionShouldHaveTheOptionValue(ProductOptionInterface $productOption, $optionValue)
253
    {
254
        $this->iWantToModifyAProductOption($productOption);
255
256
        Assert::true($this->updatePage->isThereOptionValue($optionValue));
257
    }
258
259
    /**
260
     * @Then the first product option in the list should have :field :value
261
     */
262
    public function theFirstProductOptionInTheListShouldHave($field, $value)
263
    {
264
        Assert::same($this->indexPage->getColumnFields($field)[0], $value);
265
    }
266
267
    /**
268
     * @Then the last product option in the list should have :field :value
269
     */
270
    public function theLastProductOptionInTheListShouldHave($field, $value)
271
    {
272
        $values = $this->indexPage->getColumnFields($field);
273
274
        Assert::same(end($values), $value);
275
    }
276
}
277