This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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\ProductAttribute\CreatePageInterface; |
||
19 | use Sylius\Behat\Page\Admin\ProductAttribute\UpdatePageInterface; |
||
20 | use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface; |
||
21 | use Sylius\Behat\Service\SharedSecurityServiceInterface; |
||
22 | use Sylius\Component\Core\Model\AdminUserInterface; |
||
23 | use Sylius\Component\Product\Model\ProductAttributeInterface; |
||
24 | use Webmozart\Assert\Assert; |
||
25 | |||
26 | final class ManagingProductAttributesContext implements Context |
||
27 | { |
||
28 | /** |
||
29 | * @var CreatePageInterface |
||
30 | */ |
||
31 | private $createPage; |
||
32 | |||
33 | /** |
||
34 | * @var IndexPageInterface |
||
35 | */ |
||
36 | private $indexPage; |
||
37 | |||
38 | /** |
||
39 | * @var UpdatePageInterface |
||
40 | */ |
||
41 | private $updatePage; |
||
42 | |||
43 | /** |
||
44 | * @var CurrentPageResolverInterface |
||
45 | */ |
||
46 | private $currentPageResolver; |
||
47 | |||
48 | /** |
||
49 | * @var SharedSecurityServiceInterface |
||
50 | */ |
||
51 | private $sharedSecurityService; |
||
52 | |||
53 | /** |
||
54 | * @param CreatePageInterface $createPage |
||
55 | * @param IndexPageInterface $indexPage |
||
56 | * @param UpdatePageInterface $updatePage |
||
57 | * @param CurrentPageResolverInterface $currentPageResolver |
||
58 | * @param SharedSecurityServiceInterface $sharedSecurityService |
||
59 | */ |
||
60 | public function __construct( |
||
61 | CreatePageInterface $createPage, |
||
62 | IndexPageInterface $indexPage, |
||
63 | UpdatePageInterface $updatePage, |
||
64 | CurrentPageResolverInterface $currentPageResolver, |
||
65 | SharedSecurityServiceInterface $sharedSecurityService |
||
66 | ) { |
||
67 | $this->createPage = $createPage; |
||
68 | $this->indexPage = $indexPage; |
||
69 | $this->updatePage = $updatePage; |
||
70 | $this->currentPageResolver = $currentPageResolver; |
||
71 | $this->sharedSecurityService = $sharedSecurityService; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * @When I want to create a new :type product attribute |
||
76 | */ |
||
77 | public function iWantToCreateANewTextProductAttribute($type) |
||
78 | { |
||
79 | $this->createPage->open(['type' => $type]); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @When I specify its code as :code |
||
84 | * @When I do not specify its code |
||
85 | */ |
||
86 | public function iSpecifyItsCodeAs($code = null) |
||
87 | { |
||
88 | $this->createPage->specifyCode($code); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * @When I name it :name in :language |
||
93 | */ |
||
94 | public function iSpecifyItsNameAs($name, $language) |
||
95 | { |
||
96 | $this->createPage->nameIt($name, $language); |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * @When I add it |
||
101 | * @When I try to add it |
||
102 | */ |
||
103 | public function iAddIt() |
||
104 | { |
||
105 | $this->createPage->create(); |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @When I( also) add value :value in :localeCode |
||
110 | */ |
||
111 | public function iAddValue(string $value, string $localeCode): void |
||
112 | { |
||
113 | /** @var CreatePageInterface|UpdatePageInterface $currentPage */ |
||
114 | $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); |
||
115 | |||
116 | $currentPage->addAttributeValue($value, $localeCode); |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * @When I delete value :value |
||
121 | */ |
||
122 | public function iDeleteValue(string $value): void |
||
123 | { |
||
124 | $this->updatePage->deleteAttributeValue($value); |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * @When I change its value :oldValue to :newValue |
||
129 | */ |
||
130 | public function iChangeItsValueTo(string $oldValue, string $newValue): void |
||
131 | { |
||
132 | $this->updatePage->changeAttributeValue($oldValue, $newValue); |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * @Then I should see the product attribute :name in the list |
||
137 | */ |
||
138 | public function iShouldSeeTheProductAttributeInTheList($name) |
||
139 | { |
||
140 | $this->indexPage->open(); |
||
141 | |||
142 | Assert::true($this->indexPage->isSingleResourceOnPage(['name' => $name])); |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * @Then the :type attribute :name should appear in the store |
||
147 | */ |
||
148 | public function theAttributeShouldAppearInTheStore($type, $name) |
||
149 | { |
||
150 | $this->indexPage->open(); |
||
151 | |||
152 | Assert::true($this->indexPage->isSingleResourceWithSpecificElementOnPage( |
||
153 | ['name' => $name], |
||
154 | sprintf('td span.ui.label:contains("%s")', $type) |
||
155 | )); |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * @When /^I want to edit (this product attribute)$/ |
||
160 | */ |
||
161 | public function iWantToEditThisAttribute(ProductAttributeInterface $productAttribute) |
||
162 | { |
||
163 | $this->updatePage->open(['id' => $productAttribute->getId()]); |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * @When I change its name to :name in :language |
||
168 | */ |
||
169 | public function iChangeItNameToIn($name, $language) |
||
170 | { |
||
171 | $this->updatePage->changeName($name, $language); |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * @When I save my changes |
||
176 | * @When I try to save my changes |
||
177 | */ |
||
178 | public function iSaveMyChanges() |
||
179 | { |
||
180 | $this->updatePage->saveChanges(); |
||
181 | } |
||
182 | |||
183 | /** |
||
184 | * @Then the code field should be disabled |
||
185 | */ |
||
186 | public function theCodeFieldShouldBeDisabled() |
||
187 | { |
||
188 | Assert::true($this->updatePage->isCodeDisabled()); |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * @Then the type field should be disabled |
||
193 | */ |
||
194 | public function theTypeFieldShouldBeDisabled() |
||
195 | { |
||
196 | /** @var CreatePageInterface|UpdatePageInterface $currentPage */ |
||
197 | $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); |
||
198 | |||
199 | Assert::true($currentPage->isTypeDisabled()); |
||
200 | } |
||
201 | |||
202 | /** |
||
203 | * @Then I should be notified that product attribute with this code already exists |
||
204 | */ |
||
205 | public function iShouldBeNotifiedThatProductAttributeWithThisCodeAlreadyExists() |
||
206 | { |
||
207 | Assert::same($this->updatePage->getValidationMessage('code'), 'This code is already in use.'); |
||
208 | } |
||
209 | |||
210 | /** |
||
211 | * @Then there should still be only one product attribute with code :code |
||
212 | */ |
||
213 | public function thereShouldStillBeOnlyOneProductAttributeWithCode($code) |
||
214 | { |
||
215 | $this->indexPage->open(); |
||
216 | |||
217 | Assert::true($this->indexPage->isSingleResourceOnPage(['code' => $code])); |
||
218 | } |
||
219 | |||
220 | /** |
||
221 | * @When I do not name it |
||
222 | */ |
||
223 | public function iDoNotNameIt() |
||
224 | { |
||
225 | // Intentionally left blank to fulfill context expectation |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * @Then I should be notified that :element is required |
||
230 | */ |
||
231 | public function iShouldBeNotifiedThatIsRequired($element) |
||
232 | { |
||
233 | $this->assertFieldValidationMessage($element, sprintf('Please enter attribute %s.', $element)); |
||
234 | } |
||
235 | |||
236 | /** |
||
237 | * @Given the attribute with :elementName :elementValue should not appear in the store |
||
238 | */ |
||
239 | public function theAttributeWithCodeShouldNotAppearInTheStore($elementName, $elementValue) |
||
240 | { |
||
241 | $this->indexPage->open(); |
||
242 | |||
243 | Assert::false($this->indexPage->isSingleResourceOnPage([$elementName => $elementValue])); |
||
244 | } |
||
245 | |||
246 | /** |
||
247 | * @When I remove its name from :language translation |
||
248 | */ |
||
249 | public function iRemoveItsNameFromTranslation($language) |
||
250 | { |
||
251 | $this->updatePage->changeName('', $language); |
||
252 | } |
||
253 | |||
254 | /** |
||
255 | * @When I browse product attributes |
||
256 | * @When I want to see all product attributes in store |
||
257 | */ |
||
258 | public function iWantToSeeAllProductAttributesInStore() |
||
259 | { |
||
260 | $this->indexPage->open(); |
||
261 | } |
||
262 | |||
263 | /** |
||
264 | * @When /^(the administrator) changes (this product attribute)'s value "([^"]*)" to "([^"]*)"$/ |
||
265 | */ |
||
266 | public function theAdministratorChangesThisProductAttributesValueTo( |
||
267 | AdminUserInterface $user, |
||
268 | ProductAttributeInterface $productAttribute, |
||
269 | string $oldValue, |
||
270 | string $newValue |
||
271 | ): void { |
||
272 | $this->sharedSecurityService->performActionAsAdminUser( |
||
273 | $user, |
||
274 | function () use ($productAttribute, $oldValue, $newValue) { |
||
275 | $this->iWantToEditThisAttribute($productAttribute); |
||
276 | $this->iChangeItsValueTo($oldValue, $newValue); |
||
277 | $this->iSaveMyChanges(); |
||
278 | } |
||
279 | ); |
||
280 | } |
||
281 | |||
282 | /** |
||
283 | * @When I specify its min length as :min |
||
284 | * @When I specify its min entries value as :min |
||
285 | */ |
||
286 | public function iSpecifyItsMinValueAs(int $min): void |
||
287 | { |
||
288 | $this->createPage->specifyMinValue($min); |
||
289 | } |
||
290 | |||
291 | /** |
||
292 | * @When I specify its max length as :max |
||
293 | * @When I specify its max entries value as :max |
||
294 | */ |
||
295 | public function iSpecifyItsMaxLengthAs(int $max): void |
||
296 | { |
||
297 | $this->createPage->specifyMaxValue($max); |
||
298 | } |
||
299 | |||
300 | /** |
||
301 | * @When I check multiple option |
||
302 | */ |
||
303 | public function iCheckMultipleOption(): void |
||
304 | { |
||
305 | $this->createPage->checkMultiple(); |
||
306 | } |
||
307 | |||
308 | /** |
||
309 | * @When I do not check multiple option |
||
310 | */ |
||
311 | public function iDoNotCheckMultipleOption(): void |
||
312 | { |
||
313 | // Intentionally left blank to fulfill context expectation |
||
314 | } |
||
315 | |||
316 | /** |
||
317 | * @When /^(the administrator) deletes the value "([^"]+)" from (this product attribute)$/ |
||
318 | */ |
||
319 | public function theAdministratorDeletesTheValueFromThisProductAttribute( |
||
320 | AdminUserInterface $user, |
||
321 | string $value, |
||
322 | ProductAttributeInterface $productAttribute |
||
323 | ): void { |
||
324 | $this->sharedSecurityService->performActionAsAdminUser( |
||
325 | $user, |
||
326 | function () use ($productAttribute, $value) { |
||
327 | $this->iWantToEditThisAttribute($productAttribute); |
||
328 | $this->iDeleteValue($value); |
||
329 | $this->iSaveMyChanges(); |
||
330 | } |
||
331 | ); |
||
332 | } |
||
333 | |||
334 | /** |
||
335 | * @When I check (also) the :productAttributeName product attribute |
||
336 | */ |
||
337 | public function iCheckTheProductAttribute(string $productAttributeName): void |
||
338 | { |
||
339 | $this->indexPage->checkResourceOnPage(['name' => $productAttributeName]); |
||
340 | } |
||
341 | |||
342 | /** |
||
343 | * @When I delete them |
||
344 | */ |
||
345 | public function iDeleteThem(): void |
||
346 | { |
||
347 | $this->indexPage->bulkDelete(); |
||
348 | } |
||
349 | |||
350 | /** |
||
351 | * @Then I should see a single product attribute in the list |
||
352 | * @Then I should see :amountOfProductAttributes product attributes in the list |
||
353 | */ |
||
354 | public function iShouldSeeCustomersInTheList(int $amountOfProductAttributes = 1): void |
||
355 | { |
||
356 | Assert::same($this->indexPage->countItems(), $amountOfProductAttributes); |
||
357 | } |
||
358 | |||
359 | /** |
||
360 | * @When /^I delete (this product attribute)$/ |
||
361 | */ |
||
362 | public function iDeleteThisProductAttribute(ProductAttributeInterface $productAttribute) |
||
363 | { |
||
364 | $this->indexPage->open(); |
||
365 | $this->indexPage->deleteResourceOnPage(['code' => $productAttribute->getCode(), 'name' => $productAttribute->getName()]); |
||
366 | } |
||
367 | |||
368 | /** |
||
369 | * @Then /^(this product attribute) should no longer exist in the registry$/ |
||
370 | */ |
||
371 | public function thisProductAttributeShouldNoLongerExistInTheRegistry(ProductAttributeInterface $productAttribute) |
||
372 | { |
||
373 | Assert::false($this->indexPage->isSingleResourceOnPage(['code' => $productAttribute->getCode()])); |
||
374 | } |
||
375 | |||
376 | /** |
||
377 | * @Then the first product attribute on the list should have name :name |
||
378 | */ |
||
379 | public function theFirstProductAttributeOnTheListShouldHave($name) |
||
380 | { |
||
381 | $names = $this->indexPage->getColumnFields('name'); |
||
382 | |||
383 | Assert::same(reset($names), $name); |
||
384 | } |
||
385 | |||
386 | /** |
||
387 | * @Then the last product attribute on the list should have name :name |
||
388 | */ |
||
389 | public function theLastProductAttributeOnTheListShouldHave($name) |
||
390 | { |
||
391 | $names = $this->indexPage->getColumnFields('name'); |
||
392 | |||
393 | Assert::same(end($names), $name); |
||
394 | } |
||
395 | |||
396 | /** |
||
397 | * @Then /^(this product attribute) should have value "([^"]*)"/ |
||
398 | */ |
||
399 | public function theSelectAttributeShouldHaveValue(ProductAttributeInterface $productAttribute, string $value): void |
||
400 | { |
||
401 | $this->iWantToEditThisAttribute($productAttribute); |
||
402 | |||
403 | Assert::true($this->updatePage->hasAttributeValue($value)); |
||
404 | } |
||
405 | |||
406 | /** |
||
407 | * @Then I should be notified that max length must be greater or equal to the min length |
||
408 | */ |
||
409 | public function iShouldBeNotifiedThatMaxLengthMustBeGreaterOrEqualToTheMinLength(): void |
||
410 | { |
||
411 | $this->assertValidationMessage( |
||
412 | 'Configuration max length must be greater or equal to the min length.' |
||
413 | ); |
||
414 | } |
||
415 | |||
416 | /** |
||
417 | * @Then I should be notified that max entries value must be greater or equal to the min entries value |
||
418 | */ |
||
419 | public function iShouldBeNotifiedThatMaxEntriesValueMustBeGreaterOrEqualToTheMinEntriesValue(): void |
||
420 | { |
||
421 | $this->assertValidationMessage( |
||
422 | 'Configuration max entries value must be greater or equal to the min entries value.' |
||
423 | ); |
||
424 | } |
||
425 | |||
426 | /** |
||
427 | * @Then I should be notified that min entries value must be lower or equal to the number of added choices |
||
428 | */ |
||
429 | public function iShouldBeNotifiedThatMinEntriesValueMustBeLowerOrEqualToTheNumberOfAddedChoices(): void |
||
430 | { |
||
431 | $this->assertValidationMessage( |
||
432 | 'Configuration min entries value must be lower or equal to the number of added choices.' |
||
433 | ); |
||
434 | } |
||
435 | |||
436 | /** |
||
437 | * @Then I should be notified that multiple must be true if min or max entries values are specified |
||
438 | */ |
||
439 | public function iShouldBeNotifiedThatMultipleMustBeTrueIfMinOrMaxEntriesValuesAreSpecified(): void |
||
440 | { |
||
441 | $this->assertValidationMessage( |
||
442 | 'Configuration multiple must be true if min or max entries values are specified.' |
||
443 | ); |
||
444 | } |
||
445 | |||
446 | /** |
||
447 | * @Then /^(this product attribute) should not have value "([^"]*)"/ |
||
448 | */ |
||
449 | public function theSelectAttributeShouldNotHaveValue(ProductAttributeInterface $productAttribute, string $value): void |
||
450 | { |
||
451 | $this->iWantToEditThisAttribute($productAttribute); |
||
452 | |||
453 | Assert::false($this->updatePage->hasAttributeValue($value)); |
||
454 | } |
||
455 | |||
456 | /** |
||
457 | * @param string $element |
||
458 | * @param string $expectedMessage |
||
459 | * |
||
460 | * @throws \InvalidArgumentException |
||
461 | */ |
||
462 | private function assertFieldValidationMessage(string $element, string $expectedMessage): void |
||
463 | { |
||
464 | /** @var CreatePageInterface|UpdatePageInterface $currentPage */ |
||
465 | $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); |
||
466 | |||
467 | Assert::same($currentPage->getValidationMessage($element), $expectedMessage); |
||
468 | } |
||
469 | |||
470 | /** |
||
471 | * @param string $expectedMessage |
||
472 | * |
||
473 | * @throws \InvalidArgumentException |
||
474 | */ |
||
475 | private function assertValidationMessage(string $expectedMessage): void |
||
476 | { |
||
477 | /** @var CreatePageInterface|UpdatePageInterface $currentPage */ |
||
478 | $currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]); |
||
479 | |||
480 | Assert::same($currentPage->getValidationErrors(), $expectedMessage); |
||
0 ignored issues
–
show
|
|||
481 | } |
||
482 | } |
||
483 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: