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

graphQl-527: Category Tree Contains null Leaves #529

Merged
merged 4 commits into from
Mar 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function calculate(FieldNode $fieldNode) : int
$depth = count($selections) ? 1 : 0;
$childrenDepth = [0];
foreach ($selections as $node) {
if ($node->kind === 'InlineFragment') {
if ($node->kind === 'InlineFragment' || null !== $node->alias) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Magento\GraphQl\Catalog;

use Magento\Catalog\Api\Data\CategoryInterface;
use Magento\Catalog\Model\CategoryRepository;
use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection;
use Magento\Framework\DataObject;
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
Expand All @@ -23,9 +24,15 @@ class CategoryTest extends GraphQlAbstract
*/
private $objectManager;

/**
* @var CategoryRepository
*/
private $categoryRepository;

protected function setUp()
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->categoryRepository = $this->objectManager->get(CategoryRepository::class);
}

/**
Expand Down Expand Up @@ -103,6 +110,42 @@ public function testCategoriesTree()
);
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
*/
public function testCategoriesTreeWithDisabledCategory()
{
$category = $this->categoryRepository->get(3);
$category->setIsActive(false);
$this->categoryRepository->save($category);

$rootCategoryId = 2;
$query = <<<QUERY
{
category(id: {$rootCategoryId}) {
id
name
level
description
children {
id
name
productImagePreview: products(pageSize: 1) {
items {
id
}
}
}
}
}
QUERY;
$response = $this->graphQlQuery($query);

$this->assertArrayHasKey('category', $response);
$this->assertArrayHasKey('children', $response['category']);
$this->assertSame(6, count($response['category']['children']));
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
*/
Expand Down