@@ -225,6 +225,92 @@ private function getGraphQlQuery(string $categoryList, string $includeDirectChil
225
225
}
226
226
}
227
227
}
228
+ QUERY ;
229
+ }
230
+
231
+ /**
232
+ * Test the categories that appear in aggregation Layered Navigation > Display Category Filter => Yes (default).
233
+ *
234
+ * @magentoApiDataFixture Magento/Catalog/_files/categories.php
235
+ * @throws \Exception
236
+ */
237
+ public function testFetchCategoriesWhenDisplayCategoryEnabled (): void
238
+ {
239
+ $ result = $ this ->aggregationWithDisplayCategorySetting ();
240
+ $ aggregationAttributeCode = [];
241
+ foreach ($ result ['products ' ]['aggregations ' ] as $ aggregation ) {
242
+ $ this ->assertArrayHasKey ('attribute_code ' , $ aggregation );
243
+ $ aggregationAttributeCode [] = $ aggregation ['attribute_code ' ];
244
+ }
245
+ $ this ->assertTrue (in_array ('category_uid ' , $ aggregationAttributeCode ));
246
+ }
247
+
248
+ /**
249
+ * Test the categories not in aggregation when Layered Navigation > Display Category Filter => No.
250
+ *
251
+ * @magentoConfigFixture catalog/layered_navigation/display_category 0
252
+ * @magentoApiDataFixture Magento/Catalog/_files/categories.php
253
+ * @throws \Exception
254
+ */
255
+ public function testDontFetchCategoriesWhenDisplayCategoryDisabled (): void
256
+ {
257
+ $ result = $ this ->aggregationWithDisplayCategorySetting ();
258
+ $ aggregationAttributeCode = [];
259
+ foreach ($ result ['products ' ]['aggregations ' ] as $ aggregation ) {
260
+ $ this ->assertArrayHasKey ('attribute_code ' , $ aggregation );
261
+ $ aggregationAttributeCode [] = $ aggregation ['attribute_code ' ];
262
+ }
263
+ $ this ->assertFalse (in_array ('category_uid ' , $ aggregationAttributeCode ));
264
+ }
265
+
266
+ /**
267
+ * @return array
268
+ * @throws \Exception
269
+ */
270
+ private function aggregationWithDisplayCategorySetting (): array
271
+ {
272
+ $ query = $ this ->getGraphQlQueryProductSearch ();
273
+ $ result = $ this ->graphQlQuery ($ query );
274
+
275
+ $ this ->assertArrayNotHasKey ('errors ' , $ result );
276
+ $ this ->assertArrayHasKey ('aggregations ' , $ result ['products ' ]);
277
+ return $ result ;
278
+ }
279
+
280
+ /**
281
+ * Get graphQl query.
282
+ *
283
+ * @return string
284
+ */
285
+ private function getGraphQlQueryProductSearch (): string
286
+ {
287
+ return <<<QUERY
288
+ {
289
+ products(
290
+ search: "simple"
291
+ pageSize: 20
292
+ currentPage: 1
293
+ sort: { }
294
+ ) {
295
+ items {
296
+ sku
297
+ canonical_url
298
+ categories{
299
+ name
300
+ path
301
+ }
302
+ }
303
+ aggregations (filter: {category: {includeDirectChildrenOnly: true}}) {
304
+ attribute_code
305
+ count
306
+ label
307
+ options {
308
+ label
309
+ value
310
+ }
311
+ }
312
+ }
313
+ }
228
314
QUERY ;
229
315
}
230
316
}
0 commit comments