1 | <?php |
||
28 | class CreateSimpleProductPage extends BaseCreatePage implements CreateSimpleProductPageInterface |
||
|
|||
29 | { |
||
30 | use SpecifiesItsCode; |
||
31 | |||
32 | public function getRouteName(): string |
||
33 | { |
||
34 | return parent::getRouteName() . '_simple'; |
||
35 | } |
||
36 | |||
37 | public function nameItIn(string $name, string $localeCode): void |
||
38 | { |
||
39 | $this->clickTabIfItsNotActive('details'); |
||
40 | $this->activateLanguageTab($localeCode); |
||
41 | $this->getElement('name', ['%locale%' => $localeCode])->setValue($name); |
||
42 | |||
43 | if ($this->getDriver() instanceof Selenium2Driver || $this->getDriver() instanceof ChromeDriver) { |
||
44 | SlugGenerationHelper::waitForSlugGeneration( |
||
45 | $this->getSession(), |
||
46 | $this->getElement('slug', ['%locale%' => $localeCode]) |
||
47 | ); |
||
48 | } |
||
49 | } |
||
50 | |||
51 | public function specifySlugIn(?string $slug, string $locale): void |
||
52 | { |
||
53 | $this->activateLanguageTab($locale); |
||
54 | |||
55 | $this->getElement('slug', ['%locale%' => $locale])->setValue($slug); |
||
56 | } |
||
57 | |||
58 | public function specifyPrice(string $channelName, string $price): void |
||
59 | { |
||
60 | $this->getElement('price', ['%channelName%' => $channelName])->setValue($price); |
||
61 | } |
||
62 | |||
63 | public function specifyOriginalPrice(string $channelName, int $originalPrice): void |
||
64 | { |
||
65 | $this->getElement('original_price', ['%channelName%' => $channelName])->setValue($originalPrice); |
||
66 | } |
||
67 | |||
68 | public function addAttribute(string $attributeName, string $value, string $localeCode): void |
||
69 | { |
||
70 | $this->clickTabIfItsNotActive('attributes'); |
||
71 | $this->clickLocaleTabIfItsNotActive($localeCode); |
||
72 | |||
73 | $attributeOption = $this->getElement('attributes_choice')->find('css', sprintf('option:contains("%s")', $attributeName)); |
||
74 | $this->selectElementFromAttributesDropdown($attributeOption->getAttribute('value')); |
||
75 | |||
76 | $this->getDocument()->pressButton('Add attributes'); |
||
77 | $this->waitForFormElement(); |
||
78 | |||
79 | $this->getElement('attribute_value', ['%attributeName%' => $attributeName, '%localeCode%' => $localeCode])->setValue($value); |
||
80 | } |
||
81 | |||
82 | public function getAttributeValidationErrors(string $attributeName, string $localeCode): string |
||
83 | { |
||
84 | $this->clickTabIfItsNotActive('attributes'); |
||
85 | $this->clickLocaleTabIfItsNotActive($localeCode); |
||
86 | |||
87 | $validationError = $this->getElement('attribute')->find('css', '.sylius-validation-error'); |
||
88 | |||
89 | return $validationError->getText(); |
||
90 | } |
||
91 | |||
92 | public function removeAttribute(string $attributeName, string $localeCode): void |
||
93 | { |
||
94 | $this->clickTabIfItsNotActive('attributes'); |
||
95 | |||
96 | $this->getElement('attribute_delete_button', ['%attributeName%' => $attributeName, '%localeCode%' => $localeCode])->press(); |
||
97 | } |
||
98 | |||
99 | public function checkAttributeErrors($attributeName, $localeCode): void |
||
100 | { |
||
101 | $this->clickTabIfItsNotActive('attributes'); |
||
102 | $this->clickLocaleTabIfItsNotActive($localeCode); |
||
103 | } |
||
104 | |||
105 | public function selectMainTaxon(TaxonInterface $taxon): void |
||
106 | { |
||
107 | $this->openTaxonBookmarks(); |
||
108 | |||
109 | $mainTaxonElement = $this->getElement('main_taxon')->getParent(); |
||
110 | |||
111 | AutocompleteHelper::chooseValue($this->getSession(), $mainTaxonElement, $taxon->getName()); |
||
112 | } |
||
113 | |||
114 | public function isMainTaxonChosen(string $taxonName): bool |
||
115 | { |
||
116 | $this->openTaxonBookmarks(); |
||
117 | |||
118 | return $taxonName === $this->getDocument()->find('css', '.search > .text')->getText(); |
||
119 | } |
||
120 | |||
121 | public function attachImage(string $path, string $type = null): void |
||
122 | { |
||
123 | $this->clickTabIfItsNotActive('media'); |
||
124 | |||
125 | $filesPath = $this->getParameter('files_path'); |
||
126 | |||
127 | $this->getDocument()->clickLink('Add'); |
||
128 | |||
129 | $imageForm = $this->getLastImageElement(); |
||
130 | if (null !== $type) { |
||
131 | $imageForm->fillField('Type', $type); |
||
132 | } |
||
133 | |||
134 | $imageForm->find('css', 'input[type="file"]')->attachFile($filesPath . $path); |
||
135 | } |
||
136 | |||
137 | public function associateProducts(ProductAssociationTypeInterface $productAssociationType, array $productsNames): void |
||
138 | { |
||
139 | $this->clickTab('associations'); |
||
140 | |||
141 | $dropdown = $this->getElement('association_dropdown', [ |
||
142 | '%association%' => $productAssociationType->getName(), |
||
143 | ]); |
||
144 | $dropdown->click(); |
||
145 | |||
146 | foreach ($productsNames as $productName) { |
||
147 | $dropdown->waitFor(5, function () use ($productName, $productAssociationType) { |
||
148 | return $this->hasElement('association_dropdown_item', [ |
||
149 | '%association%' => $productAssociationType->getName(), |
||
150 | '%item%' => $productName, |
||
151 | ]); |
||
152 | }); |
||
153 | |||
154 | $item = $this->getElement('association_dropdown_item', [ |
||
155 | '%association%' => $productAssociationType->getName(), |
||
156 | '%item%' => $productName, |
||
157 | ]); |
||
158 | $item->click(); |
||
159 | } |
||
160 | } |
||
161 | |||
162 | public function removeAssociatedProduct(string $productName, ProductAssociationTypeInterface $productAssociationType): void |
||
172 | |||
173 | public function choosePricingCalculator(string $name): void |
||
177 | |||
178 | public function checkChannel(string $channelName): void |
||
182 | |||
183 | public function activateLanguageTab(string $locale): void |
||
184 | { |
||
185 | if (!$this->getDriver() instanceof Selenium2Driver && !$this->getDriver() instanceof ChromeDriver) { |
||
186 | return; |
||
187 | } |
||
188 | |||
189 | $languageTabTitle = $this->getElement('language_tab', ['%locale%' => $locale]); |
||
190 | if (!$languageTabTitle->hasClass('active')) { |
||
191 | $languageTabTitle->click(); |
||
192 | } |
||
193 | } |
||
194 | |||
195 | public function selectShippingCategory(string $shippingCategoryName): void |
||
199 | |||
200 | public function setShippingRequired(bool $isShippingRequired): void |
||
210 | |||
211 | protected function getElement(string $name, array $parameters = []): NodeElement |
||
219 | |||
220 | protected function getDefinedElements(): array |
||
250 | |||
251 | private function openTaxonBookmarks(): void |
||
255 | |||
256 | private function selectElementFromAttributesDropdown(string $id): void |
||
257 | { |
||
258 | $this->getDriver()->executeScript('$(\'#sylius_product_attribute_choice\').dropdown(\'show\');'); |
||
259 | $this->getDriver()->executeScript(sprintf('$(\'#sylius_product_attribute_choice\').dropdown(\'set selected\', \'%s\');', $id)); |
||
260 | } |
||
261 | |||
262 | private function waitForFormElement(int $timeout = 5): void |
||
263 | { |
||
264 | $form = $this->getElement('form'); |
||
265 | $this->getDocument()->waitFor($timeout, function () use ($form) { |
||
266 | return false === strpos($form->getAttribute('class'), 'loading'); |
||
267 | }); |
||
268 | } |
||
269 | |||
270 | private function clickTabIfItsNotActive(string $tabName): void |
||
271 | { |
||
277 | |||
278 | private function clickTab(string $tabName): void |
||
283 | |||
284 | private function clickLocaleTabIfItsNotActive(string $localeCode): void |
||
291 | |||
292 | private function getLastImageElement(): NodeElement |
||
301 | } |
||
302 |