Skip to content

Commit a60fd3e

Browse files
author
Alex Paliarush
committed
MAGETWO-92773: [GraphQL] Products cannot be fetched in parent/anchor category #89
1 parent 19dbdde commit a60fd3e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magento\GraphQl\Catalog;
99

10+
use Magento\Catalog\Api\Data\CategoryInterface;
1011
use Magento\Framework\DataObject;
1112
use Magento\TestFramework\TestCase\GraphQlAbstract;
1213
use Magento\Catalog\Api\Data\ProductInterface;
@@ -285,10 +286,22 @@ public function testCategoryProducts()
285286
*/
286287
public function testAnchorCategory()
287288
{
288-
$categoryId = 3;
289+
/** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $categoryCollection */
290+
$categoryCollection = $this->objectManager->create(
291+
\Magento\Catalog\Model\ResourceModel\Category\Collection::class
292+
);
293+
$categoryCollection->addFieldToFilter('name', 'Category 1');
294+
$category = $categoryCollection->getFirstItem();
295+
/** @var \Magento\Framework\EntityManager\MetadataPool $entityManagerMetadataPool */
296+
$entityManagerMetadataPool = $this->objectManager->create(\Magento\Framework\EntityManager\MetadataPool::class);
297+
$categoryLinkField = $entityManagerMetadataPool->getMetadata(CategoryInterface::class)->getLinkField();
298+
$categoryId = $category->getData($categoryLinkField);
299+
$this->assertNotEmpty($categoryId, "Preconditions failed: category is not available.");
300+
289301
$query = <<<QUERY
290302
{
291303
category(id: {$categoryId}) {
304+
name
292305
products(sort: {sku: ASC}) {
293306
total_count
294307
items {
@@ -302,6 +315,7 @@ public function testAnchorCategory()
302315
$response = $this->graphQlQuery($query);
303316
$expectedResponse = [
304317
'category' => [
318+
'name' => 'Category 1',
305319
'products' => [
306320
'total_count' => 3,
307321
'items' => [

0 commit comments

Comments
 (0)