Skip to content

Commit d8e5aba

Browse files
committed
MTA-554: Re-factor Test for Unassign Products from Category
1 parent 97a887e commit d8e5aba

File tree

4 files changed

+40
-88
lines changed

4 files changed

+40
-88
lines changed

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/ProductForm.php

Lines changed: 34 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
use Magento\Catalog\Test\Fixture\CatalogProductAttribute;
1414
use Magento\Mtf\Client\Element\SimpleElement;
1515
use Magento\Catalog\Test\Block\Adminhtml\Product\Edit\ProductTab;
16-
use Magento\Catalog\Test\Fixture\Product;
1716
use Magento\Mtf\Client\Element;
1817
use Magento\Mtf\Client\Locator;
1918
use Magento\Mtf\Fixture\DataFixture;
2019
use Magento\Mtf\Fixture\FixtureInterface;
2120
use Magento\Mtf\Fixture\InjectableFixture;
21+
use Magento\Catalog\Test\Fixture\Category;
2222

2323
/**
2424
* Product form on backend product page.
@@ -60,41 +60,6 @@ class ProductForm extends FormTabs
6060
*/
6161
protected $customTab = './/*/a[contains(@id,"product_info_tabs_%s")]';
6262

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-
9863
/**
9964
* Tabs title css selector.
10065
*
@@ -148,13 +113,11 @@ public function fill(FixtureInterface $product, SimpleElement $element = null, F
148113
} else {
149114
$tabs = $this->getFieldsByTabs($product);
150115

116+
//TODO: Remove after old product fixture will be deleted
151117
if (null === $category && $product instanceof DataFixture) {
152118
$categories = $product->getCategories();
153119
$category = reset($categories);
154120
}
155-
if ($category) {
156-
$tabs['product-details']['category_ids']['value'] = $category->getName();
157-
}
158121

159122
$this->showAdvancedSettings();
160123
$this->fillTabs($tabs, $element);
@@ -164,9 +127,41 @@ public function fill(FixtureInterface $product, SimpleElement $element = null, F
164127
}
165128
}
166129

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+
167138
return $this;
168139
}
169140

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+
170165
/**
171166
* Create custom attribute.
172167
*
@@ -226,43 +221,6 @@ public function openTab($tabName)
226221
return parent::openTab($tabName);
227222
}
228223

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-
266224
/**
267225
* Clear category field.
268226
*
@@ -276,17 +234,6 @@ public function clearCategorySelect()
276234
}
277235
}
278236

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-
290237
/**
291238
* Check visibility of the attribute on the product page.
292239
*

dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/CategoryIds.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public function __construct(
5757
} elseif (isset($data['presets'])) {
5858
$presets = explode(',', $data['presets']);
5959
foreach ($presets as $preset) {
60+
if ($preset == "") {
61+
$this->data[] = '';
62+
continue;
63+
}
6064
$category = $fixtureFactory->createByCode('category', ['dataSet' => $preset]);
6165
$category->persist();
6266

dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/UpdateSimpleProductEntityTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function test(CatalogProductSimple $initialProduct, CatalogProductSimple
8080
$initialCategory = $initialProduct->hasData('category_ids')
8181
? $initialProduct->getDataFieldConfig('category_ids')['source']->getCategories()[0]
8282
: null;
83-
$category = $product->hasData('category_ids')
83+
$category = $product->hasData('category_ids') && $product->getCategoryIds()[0]
8484
? $product->getDataFieldConfig('category_ids')['source']->getCategories()[0]
8585
: $initialCategory;
8686

dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/UpdateSimpleProductEntityTest/test.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
"Update product status to offline";"product_with_category";"-";"Test simple product %isolation%";"test_simple_product_%isolation%";"74.00";"87.0000";"-";"test-simple-product-%isolation%";"333.0000";"-";"Product offline";"assertProductSaveMessage, assertProductForm, assertProductIsNotDisplayingOnFrontend"
88
"Update category";"product_with_category";"default";"Test simple product %isolation%";"test_simple_product_%isolation%";"74.00";"87.0000";"-";"test-simple-product-%isolation%";"333.0000";"-";"-";"assertProductSaveMessage, assertProductForm, assertUrlRewriteUpdatedProductInGrid, assertProductVisibleInCategory"
99
"MAGETWO-12428: Edit Simple Product";"product_with_category";"default";"Test simple product %isolation%";"test_simple_product_%isolation%";"133.00";"-";"-";"test-simple-product-%isolation%";"-";"-";"-";"assertProductSaveMessage, assertProductPage"
10+
"MAGETWO-12417: Unassign Products from the Category";"product_with_category";"";"-";"-";"-";"-";"-";"-";"-";"-";"-";"assertProductSaveMessage, assertProductNotVisibleInCategory"

0 commit comments

Comments
 (0)