Skip to content

Commit b5163a5

Browse files
committed
MC-42795: GraphQl products query layered navigation filters return incorrect child categories list
1 parent 86cdf38 commit b5163a5

File tree

1 file changed

+23
-39
lines changed

1 file changed

+23
-39
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/ProductSearchCategoryAggregationsTest.php

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,67 +18,51 @@ class ProductSearchCategoryAggregationsTest extends GraphQlAbstract
1818
/**
1919
* Test category_id aggregation on filter by "eq" category ID condition.
2020
*
21-
* @throws Exception
22-
*
2321
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
2422
*/
2523
public function testAggregationEqCategory()
2624
{
2725
$filterValue = '{category_id: {eq: "2"}}';
28-
$categoryAggregation = $this->aggregationCategoryTesting($filterValue);
29-
26+
$categoryAggregation = $this->aggregationCategoryTesting($filterValue, "true");
3027
$this->assertEquals(4, $categoryAggregation['count']);
31-
3228
$expectedOptions = $this->getCategoryTwoOptions();
33-
3429
$this->assertEquals($expectedOptions, $categoryAggregation['options']);
3530
}
3631

3732
/**
3833
* Test category_id aggregation on filter by "in" category ID condition.
3934
*
40-
* @throws Exception
41-
*
4235
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
4336
*/
4437
public function testAggregationInCategory()
4538
{
4639
$filterValue = '{category_id: {in: ["3","2"]}}';
47-
$categoryAggregation = $this->aggregationCategoryTesting($filterValue);
48-
40+
$categoryAggregation = $this->aggregationCategoryTesting($filterValue, "true");
4941
$this->assertEquals(6, $categoryAggregation['count']);
50-
5142
$expectedOptions = array_merge($this->getCategoryThreeOptions(), $this->getCategoryTwoOptions());
52-
5343
$this->assertEquals($expectedOptions, $categoryAggregation['options']);
5444
}
5545

5646
/**
5747
* @param string $filterValue
5848
*
5949
* @return array
60-
*
61-
* @throws Exception
6250
*/
63-
private function aggregationCategoryTesting(string $filterValue): array
51+
private function aggregationCategoryTesting(string $filterValue, string $includeSubcategoriesOnly): array
6452
{
65-
$query = $this->getGraphQlQuery($filterValue);
53+
$query = $this->getGraphQlQuery($filterValue, $includeSubcategoriesOnly);
6654
$result = $this->graphQlQuery($query);
67-
6855
$this->assertArrayNotHasKey('errors', $result);
6956
$this->assertArrayHasKey('aggregations', $result['products']);
70-
7157
$categoryAggregation = array_filter(
7258
$result['products']['aggregations'],
7359
function ($a) {
7460
return $a['attribute_code'] == 'category_id';
7561
}
7662
);
77-
7863
$this->assertNotEmpty($categoryAggregation);
7964
$categoryAggregation = reset($categoryAggregation);
8065
$this->assertEquals('Category', $categoryAggregation['label']);
81-
8266
return $categoryAggregation;
8367
}
8468

@@ -114,28 +98,28 @@ private function getCategoryThreeOptions(): array
11498
* Get graphQl query.
11599
*
116100
* @param string $categoryList
117-
*
101+
* @param string $includeSubcategoriesOnly
118102
* @return string
119103
*/
120-
private function getGraphQlQuery(string $categoryList): string
104+
private function getGraphQlQuery(string $categoryList, string $includeSubcategoriesOnly): string
121105
{
122106
return <<<QUERY
123-
{
124-
products(filter: {$categoryList}) {
125-
total_count
126-
items { sku }
127-
aggregations {
128-
attribute_code
129-
count
130-
label
131-
options {
132-
count
133-
label
134-
value
135-
}
136-
}
137-
}
138-
}
139-
QUERY;
107+
{
108+
products(filter: {$categoryList}) {
109+
total_count
110+
items { sku }
111+
aggregations (filter: {includeSubcategoriesOnly: {$includeSubcategoriesOnly}}) {
112+
attribute_code
113+
count
114+
label
115+
options {
116+
count
117+
label
118+
value
119+
}
120+
}
121+
}
122+
}
123+
QUERY;
140124
}
141125
}

0 commit comments

Comments
 (0)