Skip to content

Commit fcaa729

Browse files
30349: Product filter with category_id does not work as expected - added API functional test
1 parent dd159ef commit fcaa729

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1448,11 +1448,12 @@ public function testFilterProductsForExactMatchingName()
14481448
*/
14491449
public function testFilteringForProductsFromMultipleCategories()
14501450
{
1451+
$categoriesIds = ["4","5","12"];
14511452
$query
14521453
= <<<QUERY
14531454
{
14541455
products(filter:{
1455-
category_id :{in:["4","5","12"]}
1456+
category_id :{in:["{$categoriesIds[0]}","{$categoriesIds[1]}","{$categoriesIds[2]}"]}
14561457
})
14571458
{
14581459
items
@@ -1478,6 +1479,20 @@ public function testFilteringForProductsFromMultipleCategories()
14781479
$response = $this->graphQlQuery($query);
14791480
/** @var ProductRepositoryInterface $productRepository */
14801481
$this->assertEquals(3, $response['products']['total_count']);
1482+
$actualProducts = [];
1483+
foreach ($categoriesIds as $categoriesId) {
1484+
/** @var CategoryLinkManagement $productLinks */
1485+
$productLinks = ObjectManager::getInstance()->get(CategoryLinkManagement::class);
1486+
$links = $productLinks->getAssignedProducts($categoriesId);
1487+
$links = array_reverse($links);
1488+
foreach ($links as $linkProduct) {
1489+
$productRepository = ObjectManager::getInstance()->get(ProductRepositoryInterface::class);
1490+
/** @var ProductInterface $product */
1491+
$product = $productRepository->get($linkProduct->getSku());
1492+
$actualProducts[$linkProduct->getSku()] = $product->getName();
1493+
}
1494+
}
1495+
$this->assertEquals(array_column($response['products']['items'],"name","sku"), $actualProducts);
14811496
}
14821497

14831498
/**

0 commit comments

Comments
 (0)