Skip to content

Commit 4e39ad9

Browse files
committed
MTA-552: Re-factor Test for Create Product with New Category
1 parent 97a887e commit 4e39ad9

File tree

14 files changed

+262
-469
lines changed

14 files changed

+262
-469
lines changed

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88

99
use Magento\Backend\Test\Block\Widget\Tab;
1010
use Magento\Backend\Test\Block\Widget\FormTabs;
11+
use Magento\Mtf\Client\BrowserInterface;
1112
use Magento\Mtf\Client\Element\SimpleElement;
1213
use Magento\Mtf\Client\Element;
1314
use Magento\Mtf\Client\Locator;
1415
use Magento\Mtf\Fixture\FixtureInterface;
16+
use Magento\Mtf\Block\BlockFactory;
17+
use Magento\Mtf\Block\Mapper;
18+
use Magento\Mtf\Util\XmlConverter;
1519

1620
/**
1721
* Edit attribute form on catalog product edit page.
@@ -32,6 +36,28 @@ class AttributeForm extends FormTabs
3236
*/
3337
protected $saveButton = '#save';
3438

39+
/**
40+
* @constructor
41+
* @param SimpleElement $element
42+
* @param Mapper $mapper
43+
* @param BlockFactory $blockFactory
44+
* @param BrowserInterface $browser
45+
* @param XmlConverter $xmlConverter
46+
* @param array $config
47+
*/
48+
public function __construct(
49+
SimpleElement $element,
50+
Mapper $mapper,
51+
BlockFactory $blockFactory,
52+
BrowserInterface $browser,
53+
XmlConverter $xmlConverter,
54+
array $config = []
55+
)
56+
{
57+
parent::__construct($element, $mapper, $blockFactory, $browser, $xmlConverter, $config);
58+
$this->browser->switchToFrame(new Locator($this->iFrame));
59+
}
60+
3561
/**
3662
* Fill the attribute form.
3763
*
@@ -41,7 +67,6 @@ class AttributeForm extends FormTabs
4167
*/
4268
public function fill(FixtureInterface $fixture, SimpleElement $element = null)
4369
{
44-
$this->browser->switchToFrame(new Locator($this->iFrame));
4570
$browser = $this->browser;
4671
$selector = $this->saveButton;
4772
$this->browser->waitUntil(
@@ -65,8 +90,6 @@ public function openTab($tabName)
6590
? $this->tabs[$tabName]['strategy']
6691
: Locator::SELECTOR_CSS;
6792
$tab = $this->_rootElement->find($selector, $strategy);
68-
$target = $this->browser->find('.page-footer-wrapper'); // Handle menu overlap problem
69-
$this->_rootElement->dragAndDrop($target);
7093
$tab->click();
7194

7295
return $this;

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Tab/ProductDetails.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ class ProductDetails extends \Magento\Catalog\Test\Block\Adminhtml\Product\Edit\
3838
public function fillFormTab(array $fields, SimpleElement $element = null)
3939
{
4040
$data = $this->dataMapping($fields);
41-
42-
if (isset($data['category_ids'])) {
43-
/* Fix browser behavior for click by hidden list result of suggest(category) element */
44-
$this->scrollToCategory();
45-
$this->_fill([$data['category_ids']], $element);
46-
unset($data['category_ids']);
47-
}
4841
$this->_fill($data, $element);
4942

5043
return $this;

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Tab/ProductDetails/CategoryIds.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
namespace Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Tab\ProductDetails;
88

9-
use Magento\Mtf\Client\Locator;
109
use Magento\Mtf\Client\Element\MultisuggestElement;
1110

1211
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Tab\ProductDetails;
8+
9+
use Magento\Mtf\Client\Locator;
10+
use Magento\Mtf\Fixture\FixtureInterface;
11+
use Magento\Catalog\Test\Fixture\Category;
12+
use Magento\Backend\Test\Block\Widget\FormTabs;
13+
14+
/**
15+
* Create new category.
16+
*/
17+
class NewCategoryIds extends FormTabs
18+
{
19+
/**
20+
* Button "New Category".
21+
*
22+
* @var string
23+
*/
24+
protected $buttonNewCategory = '#add_category_button';
25+
26+
/**
27+
* Dialog box "Create Category".
28+
*
29+
* @var string
30+
*/
31+
protected $createCategoryDialog = './/ancestor::body//*[contains(@class,"mage-new-category-dialog")]';
32+
33+
/**
34+
* "Parent Category" block on dialog box.
35+
*
36+
* @var string
37+
*/
38+
protected $parentCategoryBlock = '//*[contains(@class,"field-new_category_parent")]';
39+
40+
/**
41+
* Field "Category Name" on dialog box.
42+
*
43+
* @var string
44+
*/
45+
protected $fieldNewCategoryName = '//input[@id="new_category_name"]';
46+
47+
/**
48+
* Button "Create Category" on dialog box.
49+
*
50+
* @var string
51+
*/
52+
protected $createCategoryButton = '//button[contains(@class,"action-create")]';
53+
54+
/**
55+
* Save new category.
56+
*
57+
* @param FixtureInterface $fixture
58+
* @return void
59+
*/
60+
public function addNewCategory(FixtureInterface $fixture)
61+
{
62+
$categoryName = $fixture->getName();
63+
$parentCategory = $fixture->getDataFieldConfig('parent_id')['source']->getParentCategory()->getName();
64+
65+
$this->openNewCategoryDialog();
66+
$this->_rootElement->find(
67+
$this->createCategoryDialog . $this->fieldNewCategoryName,
68+
Locator::SELECTOR_XPATH
69+
)->setValue($categoryName);
70+
71+
$this->selectParentCategory($parentCategory);
72+
73+
$buttonCreateCategory = $this->createCategoryDialog . $this->createCategoryButton;
74+
$this->_rootElement->find($buttonCreateCategory, Locator::SELECTOR_XPATH)->click();
75+
$this->waitForElementNotVisible($buttonCreateCategory, Locator::SELECTOR_XPATH);
76+
}
77+
78+
/**
79+
* Select parent category for new one.
80+
*
81+
* @param string $categoryName
82+
* @return void
83+
*/
84+
protected function selectParentCategory($categoryName)
85+
{
86+
$this->_rootElement->find(
87+
$this->createCategoryDialog . $this->parentCategoryBlock,
88+
Locator::SELECTOR_XPATH,
89+
'\Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Tab\ProductDetails\ParentCategoryIds'
90+
)->setValue($categoryName);
91+
}
92+
93+
/**
94+
* Open new category dialog.
95+
*
96+
* @return void
97+
*/
98+
protected function openNewCategoryDialog()
99+
{
100+
$this->_rootElement->find($this->buttonNewCategory)->click();
101+
$this->waitForElementVisible($this->createCategoryDialog, Locator::SELECTOR_XPATH);
102+
}
103+
}

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

Lines changed: 32 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
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;
19-
use Magento\Mtf\Fixture\DataFixture;
2018
use Magento\Mtf\Fixture\FixtureInterface;
2119
use Magento\Mtf\Fixture\InjectableFixture;
20+
use Magento\Catalog\Test\Fixture\Category;
2221

2322
/**
2423
* Product form on backend product page.
@@ -60,41 +59,6 @@ class ProductForm extends FormTabs
6059
*/
6160
protected $customTab = './/*/a[contains(@id,"product_info_tabs_%s")]';
6261

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-
9862
/**
9963
* Tabs title css selector.
10064
*
@@ -148,14 +112,6 @@ public function fill(FixtureInterface $product, SimpleElement $element = null, F
148112
} else {
149113
$tabs = $this->getFieldsByTabs($product);
150114

151-
if (null === $category && $product instanceof DataFixture) {
152-
$categories = $product->getCategories();
153-
$category = reset($categories);
154-
}
155-
if ($category) {
156-
$tabs['product-details']['category_ids']['value'] = $category->getName();
157-
}
158-
159115
$this->showAdvancedSettings();
160116
$this->fillTabs($tabs, $element);
161117

@@ -164,9 +120,40 @@ public function fill(FixtureInterface $product, SimpleElement $element = null, F
164120
}
165121
}
166122

123+
$category = $product->hasData('category_ids')
124+
? $product->getDataFieldConfig('category_ids')['source']->getCategories()
125+
: [$category];
126+
if ($category[0]) {
127+
$this->fillCategory($category, $element);
128+
}
129+
167130
return $this;
168131
}
169132

133+
/**
134+
* Fill category data from product fixture.
135+
*
136+
* @param array|null $categoryList
137+
* @param SimpleElement|null $element
138+
* @return void
139+
*/
140+
public function fillCategory($categoryList, $element)
141+
{
142+
/** @var Category $category */
143+
foreach ($categoryList as $category) {
144+
if ($category->hasData('id')) {
145+
$tabs['product-details']['category_ids']['value'] = $category->getName();
146+
$this->fillTabs($tabs, $element);
147+
} else {
148+
$this->openTab('product-details');
149+
$this->blockFactory->create(
150+
'Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Tab\ProductDetails\NewCategoryIds',
151+
['element' => $this->browser->find('body')]
152+
)->addNewCategory($category);
153+
}
154+
}
155+
}
156+
170157
/**
171158
* Create custom attribute.
172159
*
@@ -226,43 +213,6 @@ public function openTab($tabName)
226213
return parent::openTab($tabName);
227214
}
228215

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-
266216
/**
267217
* Clear category field.
268218
*
@@ -276,17 +226,6 @@ public function clearCategorySelect()
276226
}
277227
}
278228

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-
290229
/**
291230
* Check visibility of the attribute on the product page.
292231
*

dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductForm.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ class AssertProductForm extends AbstractAssertForm
3030
'checkout_data',
3131
];
3232

33+
/**
34+
* Skipped fields for verify data.
35+
*
36+
* @var array
37+
*/
38+
protected $skippedFields = [
39+
'is_searchable',
40+
'is_visible_in_advanced_search',
41+
'is_filterable',
42+
'is_filterable_in_search',
43+
];
44+
3345
/**
3446
* Sort fields for fixture and form data
3547
*

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ public function __construct(
5858
$presets = explode(',', $data['presets']);
5959
foreach ($presets as $preset) {
6060
$category = $fixtureFactory->createByCode('category', ['dataSet' => $preset]);
61-
$category->persist();
61+
if ($data['persist'] !== 'no') {
62+
$category->persist();
63+
}
6264

6365
/** @var Category $category */
6466
$this->data[] = $category->getName();

0 commit comments

Comments
 (0)