Skip to content
This repository has been archived by the owner on Apr 29, 2019. It is now read-only.

Commit

Permalink
MAGETWO-92773: [GraphQL] Products cannot be fetched in parent/anchor …
Browse files Browse the repository at this point in the history
…category #89
  • Loading branch information
Alex Paliarush committed Jun 21, 2018
1 parent 19dbdde commit a60fd3e
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Magento\GraphQl\Catalog;

use Magento\Catalog\Api\Data\CategoryInterface;
use Magento\Framework\DataObject;
use Magento\TestFramework\TestCase\GraphQlAbstract;
use Magento\Catalog\Api\Data\ProductInterface;
Expand Down Expand Up @@ -285,10 +286,22 @@ public function testCategoryProducts()
*/
public function testAnchorCategory()
{
$categoryId = 3;
/** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $categoryCollection */
$categoryCollection = $this->objectManager->create(
\Magento\Catalog\Model\ResourceModel\Category\Collection::class
);
$categoryCollection->addFieldToFilter('name', 'Category 1');
$category = $categoryCollection->getFirstItem();
/** @var \Magento\Framework\EntityManager\MetadataPool $entityManagerMetadataPool */
$entityManagerMetadataPool = $this->objectManager->create(\Magento\Framework\EntityManager\MetadataPool::class);
$categoryLinkField = $entityManagerMetadataPool->getMetadata(CategoryInterface::class)->getLinkField();
$categoryId = $category->getData($categoryLinkField);
$this->assertNotEmpty($categoryId, "Preconditions failed: category is not available.");

$query = <<<QUERY
{
category(id: {$categoryId}) {
name
products(sort: {sku: ASC}) {
total_count
items {
Expand All @@ -302,6 +315,7 @@ public function testAnchorCategory()
$response = $this->graphQlQuery($query);
$expectedResponse = [
'category' => [
'name' => 'Category 1',
'products' => [
'total_count' => 3,
'items' => [
Expand Down

0 comments on commit a60fd3e

Please sign in to comment.