|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | */
|
6 | 6 |
|
| 7 | +declare(strict_types=1); |
| 8 | + |
7 | 9 | namespace Magento\Catalog\Test\Constraint;
|
8 | 10 |
|
9 | 11 | use Magento\Catalog\Test\Fixture\Category;
|
@@ -51,48 +53,42 @@ public function processAssert(
|
51 | 53 | * @param array $categoryProducts
|
52 | 54 | * @param CatalogCategoryEdit $catalogCategoryEdit
|
53 | 55 | * @param string $filterField
|
| 56 | + * @return void |
54 | 57 | */
|
55 | 58 | private function testGridFilter(array $categoryProducts, CatalogCategoryEdit $catalogCategoryEdit, $filterField)
|
56 | 59 | {
|
57 |
| - $productsByFilter = []; |
| 60 | + $expectedProducts = []; |
58 | 61 | foreach ($categoryProducts as $product) {
|
59 |
| - $filterValue = $product->getData($filterField); |
60 |
| - if (!isset($productsByFilter[$filterValue])) { |
61 |
| - $productsByFilter[$filterValue] = []; |
62 |
| - } |
63 |
| - $productsByFilter[$filterValue][] = $product; |
| 62 | + $expectedProducts[$product->getData('name')] = [ |
| 63 | + 'filter' => $filterField, |
| 64 | + 'value' => $product->getData($filterField) |
| 65 | + ]; |
64 | 66 | }
|
65 | 67 |
|
| 68 | + $actualProducts = []; |
| 69 | + /** @var \Magento\Catalog\Test\Block\Adminhtml\Category\Edit\CategoryForm $productsFieldset */ |
66 | 70 | $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 |
| - ); |
| 71 | + $gridRows = $productsFieldset->getProductGrid()->getRowsData(['name', $filterField]); |
| 72 | + foreach ($gridRows as $row) { |
| 73 | + $actualProducts[$row['name']] = [ |
| 74 | + 'filter' => $filterField, |
| 75 | + 'value' => $row[$filterField] |
| 76 | + ]; |
87 | 77 | }
|
| 78 | + |
| 79 | + \PHPUnit\Framework\Assert::assertEquals( |
| 80 | + $expectedProducts, |
| 81 | + $actualProducts, |
| 82 | + "Category products grid filter '$filterField' does not work correctly" |
| 83 | + ); |
88 | 84 | }
|
89 | 85 |
|
90 | 86 | /**
|
91 | 87 | * Returns a string representation of the object.
|
92 | 88 | *
|
93 | 89 | * @return string
|
94 | 90 | */
|
95 |
| - public function toString() |
| 91 | + public function toString() : string |
96 | 92 | {
|
97 | 93 | return 'Category products grid filter works correctly';
|
98 | 94 | }
|
|
0 commit comments