|
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\Page\Admin\ProductVariant; |
|
15
|
|
|
|
|
16
|
|
|
use Behat\Mink\Element\NodeElement; |
|
17
|
|
|
use Behat\Mink\Exception\ElementNotFoundException; |
|
18
|
|
|
use FriendsOfBehat\PageObjectExtension\Page\SymfonyPage; |
|
19
|
|
|
|
|
20
|
|
|
class GeneratePage extends SymfonyPage implements GeneratePageInterface |
|
21
|
|
|
{ |
|
22
|
|
|
public function generate(): void |
|
23
|
|
|
{ |
|
24
|
|
|
$this->getDocument()->pressButton('Generate'); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function specifyPrice(int $nth, int $price, string $channelName): void |
|
28
|
|
|
{ |
|
29
|
|
|
$this->getElement('price', ['%position%' => $nth, '%channelName%' => $channelName])->setValue($price); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function specifyCode(int $nth, string $code): void |
|
33
|
|
|
{ |
|
34
|
|
|
$this->getDocument()->fillField(sprintf('sylius_product_generate_variants_variants_%s_code', $nth), $code); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function removeVariant(int $nth): void |
|
38
|
|
|
{ |
|
39
|
|
|
$item = $this->getDocument()->find('css', sprintf('div[data-form-collection-index="%s"]', $nth)); |
|
40
|
|
|
|
|
41
|
|
|
$item->clickLink('Delete'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function getRouteName(): string |
|
45
|
|
|
{ |
|
46
|
|
|
return 'sylius_admin_product_variant_generate'; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @throws ElementNotFoundException |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getValidationMessage(string $element, int $position): string |
|
53
|
|
|
{ |
|
54
|
|
|
$foundElement = $this->getElement($element, ['%position%' => $position]); |
|
55
|
|
|
$validatedField = $this->getValidatedField($foundElement); |
|
56
|
|
|
|
|
57
|
|
|
return $validatedField->find('css', '.sylius-validation-error')->getText(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function getPricesValidationMessage(int $position): string |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->getElement('prices_validation_message', ['%position%' => $position])->getText(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
protected function getDefinedElements(): array |
|
66
|
|
|
{ |
|
67
|
|
|
return array_merge(parent::getDefinedElements(), [ |
|
68
|
|
|
'code' => '#sylius_product_generate_variants_variants_%position%_code', |
|
69
|
|
|
'price' => '#sylius_product_generate_variants_variants_%position%_channelPricings > .field:contains("%channelName%") input', |
|
70
|
|
|
'prices_validation_message' => '#sylius_product_generate_variants_variants_%position%_channelPricings ~ .sylius-validation-error', |
|
71
|
|
|
]); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @throws ElementNotFoundException |
|
76
|
|
|
*/ |
|
77
|
|
|
private function getValidatedField(NodeElement $element): NodeElement |
|
78
|
|
|
{ |
|
79
|
|
|
while (null !== $element && !$element->hasClass('field')) { |
|
80
|
|
|
$element = $element->getParent(); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return $element; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function isGenerationPossible(): bool |
|
87
|
|
|
{ |
|
88
|
|
|
$generateButton = $this->getDocument()->find('css', 'button:contains("Generate")'); |
|
89
|
|
|
|
|
90
|
|
|
return !$generateButton->hasAttribute('disabled'); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|