@@ -18,67 +18,51 @@ class ProductSearchCategoryAggregationsTest extends GraphQlAbstract
18
18
/**
19
19
* Test category_id aggregation on filter by "eq" category ID condition.
20
20
*
21
- * @throws Exception
22
- *
23
21
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
24
22
*/
25
23
public function testAggregationEqCategory ()
26
24
{
27
25
$ filterValue = '{category_id: {eq: "2"}} ' ;
28
- $ categoryAggregation = $ this ->aggregationCategoryTesting ($ filterValue );
29
-
26
+ $ categoryAggregation = $ this ->aggregationCategoryTesting ($ filterValue , "true " );
30
27
$ this ->assertEquals (4 , $ categoryAggregation ['count ' ]);
31
-
32
28
$ expectedOptions = $ this ->getCategoryTwoOptions ();
33
-
34
29
$ this ->assertEquals ($ expectedOptions , $ categoryAggregation ['options ' ]);
35
30
}
36
31
37
32
/**
38
33
* Test category_id aggregation on filter by "in" category ID condition.
39
34
*
40
- * @throws Exception
41
- *
42
35
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
43
36
*/
44
37
public function testAggregationInCategory ()
45
38
{
46
39
$ filterValue = '{category_id: {in: ["3","2"]}} ' ;
47
- $ categoryAggregation = $ this ->aggregationCategoryTesting ($ filterValue );
48
-
40
+ $ categoryAggregation = $ this ->aggregationCategoryTesting ($ filterValue , "true " );
49
41
$ this ->assertEquals (6 , $ categoryAggregation ['count ' ]);
50
-
51
42
$ expectedOptions = array_merge ($ this ->getCategoryThreeOptions (), $ this ->getCategoryTwoOptions ());
52
-
53
43
$ this ->assertEquals ($ expectedOptions , $ categoryAggregation ['options ' ]);
54
44
}
55
45
56
46
/**
57
47
* @param string $filterValue
58
48
*
59
49
* @return array
60
- *
61
- * @throws Exception
62
50
*/
63
- private function aggregationCategoryTesting (string $ filterValue ): array
51
+ private function aggregationCategoryTesting (string $ filterValue, string $ includeSubcategoriesOnly ): array
64
52
{
65
- $ query = $ this ->getGraphQlQuery ($ filterValue );
53
+ $ query = $ this ->getGraphQlQuery ($ filterValue, $ includeSubcategoriesOnly );
66
54
$ result = $ this ->graphQlQuery ($ query );
67
-
68
55
$ this ->assertArrayNotHasKey ('errors ' , $ result );
69
56
$ this ->assertArrayHasKey ('aggregations ' , $ result ['products ' ]);
70
-
71
57
$ categoryAggregation = array_filter (
72
58
$ result ['products ' ]['aggregations ' ],
73
59
function ($ a ) {
74
60
return $ a ['attribute_code ' ] == 'category_id ' ;
75
61
}
76
62
);
77
-
78
63
$ this ->assertNotEmpty ($ categoryAggregation );
79
64
$ categoryAggregation = reset ($ categoryAggregation );
80
65
$ this ->assertEquals ('Category ' , $ categoryAggregation ['label ' ]);
81
-
82
66
return $ categoryAggregation ;
83
67
}
84
68
@@ -114,28 +98,28 @@ private function getCategoryThreeOptions(): array
114
98
* Get graphQl query.
115
99
*
116
100
* @param string $categoryList
117
- *
101
+ * @param string $includeSubcategoriesOnly
118
102
* @return string
119
103
*/
120
- private function getGraphQlQuery (string $ categoryList ): string
104
+ private function getGraphQlQuery (string $ categoryList, string $ includeSubcategoriesOnly ): string
121
105
{
122
106
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 ;
140
124
}
141
125
}
0 commit comments