Skip to content

Commit e3b2501

Browse files
committed
MTA-552: Re-factor Test for Create Product with New Category
- Fixed fill category
1 parent 829f071 commit e3b2501

File tree

13 files changed

+62
-91
lines changed

13 files changed

+62
-91
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ public function __construct(
5252
BrowserInterface $browser,
5353
XmlConverter $xmlConverter,
5454
array $config = []
55-
)
56-
{
55+
){
5756
parent::__construct($element, $mapper, $blockFactory, $browser, $xmlConverter, $config);
5857
$this->browser->switchToFrame(new Locator($this->iFrame));
5958
}

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

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

9-
use Magento\Mtf\Client\Element\SimpleElement;
109
use Magento\Mtf\Client\Locator;
10+
use Magento\Catalog\Test\Fixture\Category;
11+
use Magento\Mtf\Client\Element\SimpleElement;
12+
use Magento\Catalog\Test\Block\Adminhtml\Product\Edit\ProductTab;
1113

1214
/**
1315
* Product details tab.
1416
*/
15-
class ProductDetails extends \Magento\Catalog\Test\Block\Adminhtml\Product\Edit\ProductTab
17+
class ProductDetails extends ProductTab
1618
{
1719
/**
1820
* Locator for preceding sibling of category element.
@@ -38,6 +40,21 @@ class ProductDetails extends \Magento\Catalog\Test\Block\Adminhtml\Product\Edit\
3840
public function fillFormTab(array $fields, SimpleElement $element = null)
3941
{
4042
$data = $this->dataMapping($fields);
43+
if (isset($data['category_ids'])) {
44+
/* Fix browser behavior for click by hidden list result of suggest(category) element */
45+
$this->scrollToCategory();
46+
if (isset($fields['category_ids']['source'])
47+
&& !$fields['category_ids']['source']->getCategories()[0]->hasData('id')
48+
) {
49+
$this->blockFactory->create(
50+
'Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Tab\ProductDetails\NewCategoryIds',
51+
['element' => $this->browser->find('body')]
52+
)->addNewCategory($fields['category_ids']['source']->getCategories()[0]);
53+
} else {
54+
$this->_fill([$data['category_ids']], $element);
55+
}
56+
unset($data['category_ids']);
57+
}
4158
$this->_fill($data, $element);
4259

4360
return $this;

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

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
namespace Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Tab\ProductDetails;
88

99
use Magento\Mtf\Client\Locator;
10-
use Magento\Mtf\Fixture\FixtureInterface;
1110
use Magento\Catalog\Test\Fixture\Category;
12-
use Magento\Backend\Test\Block\Widget\FormTabs;
11+
use Magento\Backend\Test\Block\Widget\Form;
1312

1413
/**
1514
* Create new category.
1615
*/
17-
class NewCategoryIds extends FormTabs
16+
class NewCategoryIds extends Form
1817
{
1918
/**
2019
* Button "New Category".
@@ -28,51 +27,39 @@ class NewCategoryIds extends FormTabs
2827
*
2928
* @var string
3029
*/
31-
protected $createCategoryDialog = './/ancestor::body//*[contains(@class,"mage-new-category-dialog")]';
30+
protected $createCategoryDialog = '.mage-new-category-dialog';
3231

3332
/**
3433
* "Parent Category" block on dialog box.
3534
*
3635
* @var string
3736
*/
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"]';
37+
protected $parentCategoryBlock = '.field-new_category_parent';
4638

4739
/**
4840
* Button "Create Category" on dialog box.
4941
*
5042
* @var string
5143
*/
52-
protected $createCategoryButton = '//button[contains(@class,"action-create")]';
44+
protected $createCategoryButton = '.action-create';
5345

5446
/**
55-
* Save new category.
47+
* Add new category to product.
5648
*
57-
* @param FixtureInterface $fixture
49+
* @param Category $category
5850
* @return void
5951
*/
60-
public function addNewCategory(FixtureInterface $fixture)
52+
public function addNewCategory(Category $category)
6153
{
62-
$categoryName = $fixture->getName();
63-
$parentCategory = $fixture->getDataFieldConfig('parent_id')['source']->getParentCategory()->getName();
54+
$parentCategory = $category->getDataFieldConfig('parent_id')['source']->getParentCategory()->getName();
6455

6556
$this->openNewCategoryDialog();
66-
$this->_rootElement->find(
67-
$this->createCategoryDialog . $this->fieldNewCategoryName,
68-
Locator::SELECTOR_XPATH
69-
)->setValue($categoryName);
57+
$this->fill($category);
7058

7159
$this->selectParentCategory($parentCategory);
7260

73-
$buttonCreateCategory = $this->createCategoryDialog . $this->createCategoryButton;
74-
$this->_rootElement->find($buttonCreateCategory, Locator::SELECTOR_XPATH)->click();
75-
$this->waitForElementNotVisible($buttonCreateCategory, Locator::SELECTOR_XPATH);
61+
$this->_rootElement->find($this->createCategoryButton)->click();
62+
$this->waitForElementNotVisible($this->createCategoryButton);
7663
}
7764

7865
/**
@@ -84,8 +71,8 @@ public function addNewCategory(FixtureInterface $fixture)
8471
protected function selectParentCategory($categoryName)
8572
{
8673
$this->_rootElement->find(
87-
$this->createCategoryDialog . $this->parentCategoryBlock,
88-
Locator::SELECTOR_XPATH,
74+
$this->parentCategoryBlock,
75+
Locator::SELECTOR_CSS,
8976
'\Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Tab\ProductDetails\ParentCategoryIds'
9077
)->setValue($categoryName);
9178
}
@@ -98,6 +85,6 @@ protected function selectParentCategory($categoryName)
9885
protected function openNewCategoryDialog()
9986
{
10087
$this->_rootElement->find($this->buttonNewCategory)->click();
101-
$this->waitForElementVisible($this->createCategoryDialog, Locator::SELECTOR_XPATH);
88+
$this->waitForElementVisible($this->createCategoryDialog);
10289
}
10390
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" ?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<mapping strict="0">
9+
<fields>
10+
<name>
11+
<selector>[name="new_category_name"]</selector>
12+
</name>
13+
</fields>
14+
</mapping>

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

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ public function fill(FixtureInterface $product, SimpleElement $element = null, F
118118
$categories = $product->getCategories();
119119
$category = reset($categories);
120120
}
121-
121+
if ($category) {
122+
$tabs['product-details']['category_ids']['value'] = $category->getName();
123+
}
122124
$this->showAdvancedSettings();
123125
$this->fillTabs($tabs, $element);
124126

@@ -127,41 +129,9 @@ public function fill(FixtureInterface $product, SimpleElement $element = null, F
127129
}
128130
}
129131

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-
138132
return $this;
139133
}
140134

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-
165135
/**
166136
* Create custom attribute.
167137
*

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@ 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-
4533
/**
4634
* Sort fields for fixture and form data
4735
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function __construct(
5858
$presets = explode(',', $data['presets']);
5959
foreach ($presets as $preset) {
6060
$category = $fixtureFactory->createByCode('category', ['dataSet' => $preset]);
61-
if (!isset($data['persist']) || $data['persist'] !== 'no') {
61+
if (!isset($data['new_category']) || $data['new_category'] !== 'no') {
6262
$category->persist();
6363
}
6464

dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/CreateSimpleProductEntityTest/testCreate.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"description";"configData";"product/data/category_ids/persist";"product/data/category_ids/presets";"product/data/url_key";"product/data/name";"product/data/sku";"product/data/tax_class_id/dataSet";"product/data/price/value";"product/data/special_price";"product/data/short_description";"product/data/description";"product/data/weight";"product/data/quantity_and_stock_status/qty";"product/data/quantity_and_stock_status/is_in_stock";"product/data/visibility";"product/data/custom_options/preset";"product/data/checkout_data/preset";"product/data/custom_options/import_products";"product/data/price/preset";"product/data/group_price/preset";"product/data/tier_price/preset";"product/data/cross_sell_products/presets";"product/data/up_sell_products/presets";"product/data/related_products/presets";"constraint";"tag"
1+
"description";"configData";"product/data/category_ids/new_category";"product/data/category_ids/presets";"product/data/url_key";"product/data/name";"product/data/sku";"product/data/tax_class_id/dataSet";"product/data/price/value";"product/data/special_price";"product/data/short_description";"product/data/description";"product/data/weight";"product/data/quantity_and_stock_status/qty";"product/data/quantity_and_stock_status/is_in_stock";"product/data/visibility";"product/data/custom_options/preset";"product/data/checkout_data/preset";"product/data/custom_options/import_products";"product/data/price/preset";"product/data/group_price/preset";"product/data/tier_price/preset";"product/data/cross_sell_products/presets";"product/data/up_sell_products/presets";"product/data/related_products/presets";"constraint";"tag"
22
"Create product with custom options(fixed price)";"-";"-";"-";"simple-product-%isolation%";"Simple Product %isolation%";"simple_sku_%isolation%";"-";"10000";"-";"Simple Product short_description %isolation%";"Simple Product description %isolation%";"50";"657";"-";"-";"drop_down_with_one_option_fixed_price";"drop_down_with_one_option_fixed_price";"-";"drop_down_with_one_option_fixed_price";"-";"-";"-";"-";"-";"assertProductSaveMessage, assertProductInGrid, assertProductInCategory, assertProductPage, assertProductInCart";""
33
"Create product with custom options(percent price)";"-";"-";"-";"simple-product-%isolation%";"Simple Product %isolation%";"simple_sku_%isolation%";"-";"10001";"-";"Simple Product short_description %isolation%";"Simple Product description %isolation%";"51";"658";"-";"-";"drop_down_with_one_option_percent_price";"drop_down_with_one_option_percent_price";"-";"drop_down_with_one_option_percent_price";"-";"-";"-";"-";"-";"assertProductSaveMessage, assertProductInGrid, assertProductInCategory, assertProductPage, assertProductInCart";""
44
"Create product with special price and custom options(fixed price)";"-";"-";"-";"simple-product-%isolation%";"Simple Product %isolation%";"simple_sku_%isolation%";"-";"10002";"90";"Simple Product short_description %isolation%";"Simple Product description %isolation%";"52";"659";"-";"-";"drop_down_with_one_option_fixed_price";"drop_down_with_one_option_fixed_price";"-";"MAGETWO-23029";"-";"-";"-";"-";"-";"assertProductSaveMessage, assertProductInGrid, assertProductInCategory, assertProductPage, assertProductInCart";""
@@ -21,4 +21,4 @@
2121
"Create product with up-sell products";"-";"-";"-";"simple-product-%isolation%";"Simple Product %isolation%";"simple_sku_%isolation%";"-";"10019";"-";"Simple Product short_description %isolation%";"Simple Product description %isolation%";"59";"75";"In Stock";"-";"-";"-";"-";"-";"-";"-";"-";"catalogProductSimple::default, configurableProductInjectable::default";"-";"assertProductSaveMessage, assertProductInGrid, assertProductForm, assertProductUpSells";""
2222
"Create product with related products";"-";"-";"-";"simple-product-%isolation%";"Simple Product %isolation%";"simple_sku_%isolation%";"-";"10020";"-";"Simple Product short_description %isolation%";"Simple Product description %isolation%";"59";"75";"In Stock";"-";"-";"-";"-";"-";"-";"-";"-";"-";"catalogProductSimple::default, configurableProductInjectable::default";"assertProductSaveMessage, assertProductInGrid, assertProductForm, assertProductRelatedProducts";""
2323
"MAGETWO-12423: Can't Add Out of Stock Products to Shopping Cart";"display_out_of_stock";"-";"-";"simple-product-%isolation%";"Simple Product %isolation%";"simple_sku_%isolation%";"-";"10021";"-";"-";"-";"68";"0";"Out of Stock";"-";"-";"-";"-";"-";"-";"-";"-";"-";"-";"assertProductSaveMessage, assertAddToCartButtonAbsent";"test_type:acceptance_test"
24-
"MAGETWO-13345: Create Simple Product with Creating New Category (Required Fields Only)";"-";"no";"default_subcategory";"simple%isolation%";"simple%isolation%";"simple%isolation%";"-";"10";"-";"-";"-";"-";"-";"-";"-";"-";"-";"-";"-";"-";"-";"-";"-";"-";"assertProductSaveMessage, assertProductInCategory, assertProductPage";"test_type:acceptance_test"
24+
"MAGETWO-13345: Create Simple Product with Creating New Category (Required Fields Only)";"-";"no";"default_subcategory";"simple%isolation%";"simple%isolation%";"simple%isolation%";"-";"10";"-";"-";"-";"-";"-";"-";"-";"-";"-";"-";"-";"-";"-";"-";"-";"-";"assertProductSaveMessage, assertProductInCategory, assertProductPage";""

dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Block/Adminhtml/Product/Edit/Tab/Super/Config.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ class Config extends Tab
9191
*/
9292
public function fillFormTab(array $fields, SimpleElement $element = null)
9393
{
94-
$attributes = isset($fields['configurable_attributes_data']['value'])
94+
$attributes = isset($fields['configurable_attributes_data']['source'])
9595
? $fields['configurable_attributes_data']['value']
9696
: [];
9797

9898
$this->showContent();
99-
100-
if (!empty($attributes['attributes_data'])) {
101-
$this->getAttributeBlock()->fillAttributes($attributes['attributes_data']);
102-
}
99+
$attributesValue = isset($fields['configurable_attributes_data']['source'])
100+
? $fields['configurable_attributes_data']['source']->getAttributesData()
101+
: [];
102+
$this->getAttributeBlock()->fillAttributes($attributesValue);
103103
if (!empty($attributes['matrix'])) {
104104
$this->generateVariations();
105105
$this->getVariationsBlock()->fillVariations($attributes['matrix']);

dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Block/Adminhtml/Product/Edit/Tab/Super/Config/Attribute.php

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

77
namespace Magento\ConfigurableProduct\Test\Block\Adminhtml\Product\Edit\Tab\Super\Config;
88

9-
use Magento\Mtf\ObjectManager;
109
use Magento\Mtf\Client\Locator;
1110
use Magento\Backend\Test\Block\Widget\Form;
1211
use Magento\Mtf\Client\Element\SimpleElement;

0 commit comments

Comments
 (0)