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\ProductAttribute; |
15
|
|
|
|
16
|
|
|
use Behat\Mink\Element\NodeElement; |
17
|
|
|
use Behat\Mink\Exception\ElementNotFoundException; |
18
|
|
|
use Sylius\Behat\Behaviour\ChecksCodeImmutability; |
19
|
|
|
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage; |
20
|
|
|
use Webmozart\Assert\Assert; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @author Anna Walasek <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class UpdatePage extends BaseUpdatePage implements UpdatePageInterface |
26
|
|
|
{ |
27
|
|
|
use ChecksCodeImmutability; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
public function changeName($name, $language) |
33
|
|
|
{ |
34
|
|
|
$this->getDocument()->fillField(sprintf('sylius_product_attribute_translations_%s_name', $language), $name); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
public function isTypeDisabled() |
41
|
|
|
{ |
42
|
|
|
return 'disabled' === $this->getElement('type')->getAttribute('disabled'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
protected function getCodeElement() |
49
|
|
|
{ |
50
|
|
|
return $this->getElement('code'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
|
|
public function changeAttributeValue(string $oldValue, string $newValue): void |
57
|
|
|
{ |
58
|
|
|
$this->getElement('attribute_choice_list_element', ['%value%' => $oldValue])->setValue($newValue); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
|
|
public function hasAttributeValue(string $value): bool |
65
|
|
|
{ |
66
|
|
|
return $this->hasElement('attribute_choice_list_element', ['%value%' => $value]); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
*/ |
72
|
|
|
public function addAttributeValue(string $value): void |
73
|
|
|
{ |
74
|
|
|
$this->getDocument()->clickLink('Add'); |
75
|
|
|
$this->getLastAttributeChoiceElement()->find('css', 'input')->setValue($value); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* {@inheritdoc} |
80
|
|
|
*/ |
81
|
|
|
public function deleteAttributeValue(string $value): void |
82
|
|
|
{ |
83
|
|
|
$attributeChoiceElement = $this->getElement('attribute_choice_list_element', ['%value%' => $value])->getParent(); |
84
|
|
|
$attributeChoiceElement->clickLink('Delete'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* {@inheritdoc} |
89
|
|
|
*/ |
90
|
|
|
protected function getDefinedElements() |
91
|
|
|
{ |
92
|
|
|
return array_merge(parent::getDefinedElements(), [ |
93
|
|
|
'attribute_choice_list_element' => 'input[value="%value%"]', |
94
|
|
|
'attribute_choices' => '#sylius_product_attribute_configuration_choices', |
95
|
|
|
'code' => '#sylius_product_attribute_code', |
96
|
|
|
'type' => '#sylius_product_attribute_type', |
97
|
|
|
'name' => '#sylius_product_attribute_translations_en_US_name', |
98
|
|
|
]); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return NodeElement[] |
103
|
|
|
*/ |
104
|
|
|
private function getAttributeChoiceElements(): array |
105
|
|
|
{ |
106
|
|
|
$attributeChoices = $this->getElement('attribute_choices'); |
107
|
|
|
|
108
|
|
|
return $attributeChoices->findAll('css', 'div[data-form-collection="item"]'); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return NodeElement |
113
|
|
|
*/ |
114
|
|
|
private function getLastAttributeChoiceElement(): NodeElement |
115
|
|
|
{ |
116
|
|
|
$elements = $this->getAttributeChoiceElements(); |
117
|
|
|
|
118
|
|
|
Assert::notEmpty($elements); |
119
|
|
|
|
120
|
|
|
return end($elements); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|