Skip to content

Commit 87cd878

Browse files
committed
Added functionality for throwing error when zero is set as category id
1 parent 3df7743 commit 87cd878

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/CategoryTree.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6464
return $value[$field->getName()];
6565
}
6666

67-
$rootCategoryId = !empty($args['id']) ? (int)$args['id'] :
67+
$rootCategoryId = isset($args['id']) ? (int)$args['id'] :
6868
(int)$context->getExtensionAttributes()->getStore()->getRootCategoryId();
6969
$this->checkCategoryIsActive->execute($rootCategoryId);
7070

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
namespace Magento\GraphQl\Catalog;
99

1010
use Magento\Catalog\Api\Data\CategoryInterface;
11+
use Magento\Catalog\Api\Data\ProductInterface;
12+
use Magento\Catalog\Api\ProductRepositoryInterface;
1113
use Magento\Catalog\Model\CategoryRepository;
1214
use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection;
1315
use Magento\Framework\DataObject;
16+
use Magento\TestFramework\ObjectManager;
1417
use Magento\TestFramework\TestCase\GraphQl\ResponseContainsErrorsException;
1518
use Magento\TestFramework\TestCase\GraphQlAbstract;
16-
use Magento\Catalog\Api\Data\ProductInterface;
17-
use Magento\Catalog\Api\ProductRepositoryInterface;
18-
use Magento\TestFramework\ObjectManager;
1919

2020
/**
2121
* Test loading of category tree
@@ -261,6 +261,25 @@ public function testGetDisabledCategory()
261261
$this->graphQlQuery($query);
262262
}
263263

264+
/**
265+
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
266+
* @expectedException \Exception
267+
* @expectedExceptionMessage Category doesn't exist
268+
*/
269+
public function testGetCategoryIdZero()
270+
{
271+
$categoryId = 0;
272+
$query = <<<QUERY
273+
{
274+
category(id: {$categoryId}) {
275+
id
276+
name
277+
}
278+
}
279+
QUERY;
280+
$this->graphQlQuery($query);
281+
}
282+
264283
public function testNonExistentCategoryWithProductCount()
265284
{
266285
$query = <<<QUERY
@@ -493,8 +512,7 @@ private function assertBaseFields($product, $actualResponse)
493512
['response_field' => 'attribute_set_id', 'expected_value' => $product->getAttributeSetId()],
494513
['response_field' => 'created_at', 'expected_value' => $product->getCreatedAt()],
495514
['response_field' => 'name', 'expected_value' => $product->getName()],
496-
['response_field' => 'price', 'expected_value' =>
497-
[
515+
['response_field' => 'price', 'expected_value' => [
498516
'minimalPrice' => [
499517
'amount' => [
500518
'value' => $product->getPrice(),

0 commit comments

Comments
 (0)