Skip to content

Commit

Permalink
graphQl-527: Category Tree Contains null Leaves
Browse files Browse the repository at this point in the history
  • Loading branch information
kisroman committed Mar 25, 2019
1 parent 0e8428c commit b8f5c53
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ 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

0 comments on commit b8f5c53

Please sign in to comment.