13
13
use Magento \Catalog \Test \Fixture \CatalogProductAttribute ;
14
14
use Magento \Mtf \Client \Element \SimpleElement ;
15
15
use Magento \Catalog \Test \Block \Adminhtml \Product \Edit \ProductTab ;
16
- use Magento \Catalog \Test \Fixture \Product ;
17
16
use Magento \Mtf \Client \Element ;
18
17
use Magento \Mtf \Client \Locator ;
19
18
use Magento \Mtf \Fixture \DataFixture ;
20
19
use Magento \Mtf \Fixture \FixtureInterface ;
21
20
use Magento \Mtf \Fixture \InjectableFixture ;
21
+ use Magento \Catalog \Test \Fixture \Category ;
22
22
23
23
/**
24
24
* Product form on backend product page.
@@ -60,41 +60,6 @@ class ProductForm extends FormTabs
60
60
*/
61
61
protected $ customTab = './/*/a[contains(@id,"product_info_tabs_%s")] ' ;
62
62
63
- /**
64
- * Button "New Category".
65
- *
66
- * @var string
67
- */
68
- protected $ buttonNewCategory = '#add_category_button ' ;
69
-
70
- /**
71
- * Dialog box "Create Category".
72
- *
73
- * @var string
74
- */
75
- protected $ createCategoryDialog = './/ancestor::body//*[contains(@class,"mage-new-category-dialog")] ' ;
76
-
77
- /**
78
- * "Parent Category" block on dialog box.
79
- *
80
- * @var string
81
- */
82
- protected $ parentCategoryBlock = '//*[contains(@class,"field-new_category_parent")] ' ;
83
-
84
- /**
85
- * Field "Category Name" on dialog box.
86
- *
87
- * @var string
88
- */
89
- protected $ fieldNewCategoryName = '//input[@id="new_category_name"] ' ;
90
-
91
- /**
92
- * Button "Create Category" on dialog box.
93
- *
94
- * @var string
95
- */
96
- protected $ createCategoryButton = '//button[contains(@class,"action-create")] ' ;
97
-
98
63
/**
99
64
* Tabs title css selector.
100
65
*
@@ -148,13 +113,11 @@ public function fill(FixtureInterface $product, SimpleElement $element = null, F
148
113
} else {
149
114
$ tabs = $ this ->getFieldsByTabs ($ product );
150
115
116
+ //TODO: Remove after old product fixture will be deleted
151
117
if (null === $ category && $ product instanceof DataFixture) {
152
118
$ categories = $ product ->getCategories ();
153
119
$ category = reset ($ categories );
154
120
}
155
- if ($ category ) {
156
- $ tabs ['product-details ' ]['category_ids ' ]['value ' ] = $ category ->getName ();
157
- }
158
121
159
122
$ this ->showAdvancedSettings ();
160
123
$ this ->fillTabs ($ tabs , $ element );
@@ -164,9 +127,41 @@ public function fill(FixtureInterface $product, SimpleElement $element = null, F
164
127
}
165
128
}
166
129
130
+ //TODO: Remove "!($product instanceof DataFixture)" after old product fixture will be deleted
131
+ $ category = !($ product instanceof DataFixture) && $ product ->hasData ('category_ids ' )
132
+ ? $ product ->getDataFieldConfig ('category_ids ' )['source ' ]->getCategories ()
133
+ : [$ category ];
134
+ if ($ category [0 ]) {
135
+ $ this ->fillCategory ($ category , $ element );
136
+ }
137
+
167
138
return $ this ;
168
139
}
169
140
141
+ /**
142
+ * Fill category data from product fixture.
143
+ *
144
+ * @param array|null $categoryList
145
+ * @param SimpleElement|null $element
146
+ * @return void
147
+ */
148
+ public function fillCategory ($ categoryList , $ element )
149
+ {
150
+ /** @var Category $category */
151
+ foreach ($ categoryList as $ category ) {
152
+ if ($ category ->hasData ('id ' )) {
153
+ $ tabs ['product-details ' ]['category_ids ' ]['value ' ] = $ category ->getName ();
154
+ $ this ->fillTabs ($ tabs , $ element );
155
+ } else {
156
+ $ this ->openTab ('product-details ' );
157
+ $ this ->blockFactory ->create (
158
+ 'Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Tab\ProductDetails\NewCategoryIds ' ,
159
+ ['element ' => $ this ->browser ->find ('body ' )]
160
+ )->addNewCategory ($ category );
161
+ }
162
+ }
163
+ }
164
+
170
165
/**
171
166
* Create custom attribute.
172
167
*
@@ -226,43 +221,6 @@ public function openTab($tabName)
226
221
return parent ::openTab ($ tabName );
227
222
}
228
223
229
- /**
230
- * Save new category.
231
- *
232
- * @param Product $fixture
233
- * @return void
234
- */
235
- public function addNewCategory (Product $ fixture )
236
- {
237
- $ this ->openTab ('product-details ' );
238
- $ this ->openNewCategoryDialog ();
239
- $ this ->_rootElement ->find (
240
- $ this ->createCategoryDialog . $ this ->fieldNewCategoryName ,
241
- Locator::SELECTOR_XPATH
242
- )->setValue ($ fixture ->getNewCategoryName ());
243
-
244
- $ this ->clearCategorySelect ();
245
- $ this ->selectParentCategory ();
246
-
247
- $ buttonCreateCategory = $ this ->createCategoryDialog . $ this ->createCategoryButton ;
248
- $ this ->_rootElement ->find ($ buttonCreateCategory , Locator::SELECTOR_XPATH )->click ();
249
- $ this ->waitForElementNotVisible ($ buttonCreateCategory , Locator::SELECTOR_XPATH );
250
- }
251
-
252
- /**
253
- * Select parent category for new one.
254
- *
255
- * @return void
256
- */
257
- protected function selectParentCategory ()
258
- {
259
- $ this ->_rootElement ->find (
260
- $ this ->createCategoryDialog . $ this ->parentCategoryBlock ,
261
- Locator::SELECTOR_XPATH ,
262
- '\Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Tab\ProductDetails\ParentCategoryIds '
263
- )->setValue ('Default Category ' );
264
- }
265
-
266
224
/**
267
225
* Clear category field.
268
226
*
@@ -276,17 +234,6 @@ public function clearCategorySelect()
276
234
}
277
235
}
278
236
279
- /**
280
- * Open new category dialog.
281
- *
282
- * @return void
283
- */
284
- protected function openNewCategoryDialog ()
285
- {
286
- $ this ->_rootElement ->find ($ this ->buttonNewCategory )->click ();
287
- $ this ->waitForElementVisible ($ this ->createCategoryDialog , Locator::SELECTOR_XPATH );
288
- }
289
-
290
237
/**
291
238
* Check visibility of the attribute on the product page.
292
239
*
0 commit comments