Skip to content

Commit 088fb20

Browse files
Added Visibility and Status filter to category product grid - automated tests
1 parent 67decd0 commit 088fb20

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Edit/Section/ProductGrid.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ class ProductGrid extends Grid
2929
'name' => [
3030
'selector' => '#catalog_category_products_filter_name',
3131
],
32+
'visibility' => [
33+
'selector' => '#catalog_category_products_filter_visibility',
34+
'input' => 'select',
35+
],
36+
'status' => [
37+
'selector' => '#catalog_category_products_filter_status',
38+
'input' => 'select',
39+
],
3240
];
3341

3442
/**
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Constraint;
8+
9+
use Magento\Catalog\Test\Fixture\Category;
10+
use Magento\Catalog\Test\Page\Adminhtml\CatalogCategoryEdit;
11+
use Magento\Catalog\Test\Page\Adminhtml\CatalogCategoryIndex;
12+
use Magento\Mtf\Constraint\AbstractConstraint;
13+
14+
/**
15+
* Assert that category products grid filter works correctly.
16+
*/
17+
class AssertCategoryProductsGridFilter extends AbstractConstraint
18+
{
19+
/**
20+
* Grid columns for tests
21+
*
22+
* @var array
23+
*/
24+
private $testFilterColumns = [
25+
'visibility',
26+
];
27+
28+
/**
29+
* Assert that category products grid filter works correctly.
30+
*
31+
* @param CatalogCategoryIndex $catalogCategoryIndex
32+
* @param CatalogCategoryEdit $catalogCategoryEdit
33+
* @param Category $category
34+
* @return void
35+
*/
36+
public function processAssert(
37+
CatalogCategoryIndex $catalogCategoryIndex,
38+
CatalogCategoryEdit $catalogCategoryEdit,
39+
Category $category
40+
) {
41+
$catalogCategoryIndex->getTreeCategories()->selectCategory($category, true);
42+
$categoryProducts = $category->getDataFieldConfig('category_products')['source']->getProducts();
43+
$catalogCategoryEdit->getEditForm()->openSection('category_products');
44+
45+
foreach ($this->testFilterColumns as $field) {
46+
$this->testGridFilter($categoryProducts, $catalogCategoryEdit, $field);
47+
}
48+
}
49+
50+
/**
51+
* @param array $categoryProducts
52+
* @param CatalogCategoryEdit $catalogCategoryEdit
53+
* @param string $filterField
54+
*/
55+
private function testGridFilter(array $categoryProducts, CatalogCategoryEdit $catalogCategoryEdit, $filterField)
56+
{
57+
$productsByFilter = [];
58+
foreach ($categoryProducts as $product) {
59+
$filterValue = $product->getData($filterField);
60+
if (!isset($productsByFilter[$filterValue])) {
61+
$productsByFilter[$filterValue] = [];
62+
}
63+
$productsByFilter[$filterValue][] = $product;
64+
}
65+
66+
$productsFieldset = $catalogCategoryEdit->getEditForm()->getSection('category_products');
67+
foreach ($productsByFilter as $filterValue => $products) {
68+
$productsFieldset->getProductGrid()->search([
69+
'in_category' => 'Yes',
70+
$filterField => $filterValue,
71+
]);
72+
73+
$expectedRows = [];
74+
foreach ($products as $product) {
75+
$expectedRows[] = $product->getName();
76+
}
77+
$gridRows = $productsFieldset->getProductGrid()->getRowsData(['name']);
78+
$actualRows = array_column($gridRows, 'name');
79+
sort($expectedRows);
80+
sort($actualRows);
81+
82+
\PHPUnit_Framework_Assert::assertEquals(
83+
$expectedRows,
84+
$actualRows,
85+
"Category products grid filter '$filterField' does not work correctly"
86+
);
87+
}
88+
}
89+
90+
/**
91+
* Returns a string representation of the object.
92+
*
93+
* @return string
94+
*/
95+
public function toString()
96+
{
97+
return 'Category products grid filter works correctly';
98+
}
99+
}

dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/CreateCategoryEntityTest.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,5 +175,15 @@
175175
<constraint name="Magento\Catalog\Test\Constraint\AssertCategorySaveMessage" />
176176
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryOnCustomWebsite" />
177177
</variation>
178+
<variation name="CreateCategoryEntityTestVariation11_ProductsGridFilter" summary="Apply category products grid filter">
179+
<data name="addCategory" xsi:type="string">addSubcategory</data>
180+
<data name="category/data/parent_id/dataset" xsi:type="string">default_category</data>
181+
<data name="category/data/is_active" xsi:type="string">Yes</data>
182+
<data name="category/data/include_in_menu" xsi:type="string">Yes</data>
183+
<data name="category/data/name" xsi:type="string">Subcategory%isolation%</data>
184+
<data name="category/data/category_products/dataset" xsi:type="string">catalogProductSimple::default, catalogProductSimple::not_visible_individually</data>
185+
<constraint name="Magento\Catalog\Test\Constraint\AssertCategorySaveMessage" />
186+
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryProductsGridFilter" />
187+
</variation>
178188
</testCase>
179189
</config>

0 commit comments

Comments
 (0)