Skip to content

Commit 42c0fd7

Browse files
committed
MC-43010: GraphQL query throws an error when the category is scheduled
1 parent 2bbdf22 commit 42c0fd7

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,38 @@ public function testCategoriesTree()
132132
);
133133
}
134134

135+
/**
136+
* @magentoApiDataFixture Magento/Catalog/_files/category_with_parent_anchor.php
137+
*/
138+
public function testCategoryTree()
139+
{
140+
$rootCategoryId = 2;
141+
$query = <<<QUERY
142+
{
143+
category(id: {$rootCategoryId}) {
144+
children {
145+
id
146+
name
147+
children {
148+
id
149+
name
150+
}
151+
}
152+
}
153+
}
154+
QUERY;
155+
$response = $this->graphQlQuery($query);
156+
$responseDataObject = new DataObject($response);
157+
self::assertEquals(
158+
'Parent category',
159+
$responseDataObject->getData('category/children/0/name')
160+
);
161+
self::assertEquals(
162+
'Child category',
163+
$responseDataObject->getData('category/children/0/children/0/name')
164+
);
165+
}
166+
135167
/**
136168
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
137169
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)

dev/tests/integration/testsuite/Magento/Catalog/_files/category_with_parent_anchor.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@
2727
'is_anchor' => true,
2828
];
2929
$parentCategory->setData($parentCategoryData);
30-
$parentCategoryId = $categoryRepository->save($parentCategory)->getId();
30+
$parentCategory = $categoryRepository->save($parentCategory);
3131

3232
$category = $categoryFactory->create();
3333
$category->isObjectNew(true);
3434
$categoryData = [
3535
'name' => 'Child category',
3636
'attribute_set_id' => $attributeSetId,
37-
'parent_id' => $parentCategoryId,
37+
'parent_id' => $parentCategory->getId(),
3838
'is_active' => true,
3939
];
4040
$category->setData($categoryData);
4141
$categoryRepository->save($category);
42+
43+
//save parent category to set "children" attribute
44+
$categoryRepository->save($parentCategory);

0 commit comments

Comments
 (0)