Skip to content

Commit aba9ac6

Browse files
committed
MC-21542: Category query does not handle disabled children properly
- add test
1 parent 28f9faf commit aba9ac6

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,79 @@ public function testQueryChildCategoriesWithProducts()
209209
$this->assertCategoryChildren($secondChildCategory, $firstChildCategoryChildren);
210210
}
211211

212+
/**
213+
* @magentoApiDataFixture Magento/Catalog/_files/categories_disabled.php
214+
*/
215+
public function testQueryChildCategoriesWithProductsDisabled()
216+
{
217+
$query = <<<QUERY
218+
{
219+
categoryList(filters: {ids: {in: ["3"]}}){
220+
id
221+
name
222+
url_key
223+
url_path
224+
description
225+
products{
226+
total_count
227+
items{
228+
name
229+
sku
230+
}
231+
}
232+
children{
233+
name
234+
url_key
235+
description
236+
products{
237+
total_count
238+
items{
239+
name
240+
sku
241+
}
242+
}
243+
children{
244+
name
245+
}
246+
}
247+
}
248+
}
249+
QUERY;
250+
$result = $this->graphQlQuery($query);
251+
252+
$this->assertArrayNotHasKey('errors', $result);
253+
$this->assertCount(1, $result['categoryList']);
254+
$baseCategory = $result['categoryList'][0];
255+
256+
$this->assertEquals('Category 1', $baseCategory['name']);
257+
$this->assertArrayHasKey('products', $baseCategory);
258+
//Check base category products
259+
$expectedBaseCategoryProducts = [
260+
['sku' => 'simple', 'name' => 'Simple Product'],
261+
['sku' => '12345', 'name' => 'Simple Product Two'],
262+
['sku' => 'simple-4', 'name' => 'Simple Product Three']
263+
];
264+
$this->assertCategoryProducts($baseCategory, $expectedBaseCategoryProducts);
265+
//Check base category children
266+
$expectedBaseCategoryChildren = [
267+
['name' => 'Category 1.2', 'description' => 'Its a description of Test Category 1.2']
268+
];
269+
$this->assertCategoryChildren($baseCategory, $expectedBaseCategoryChildren);
270+
271+
//Check first child category
272+
$firstChildCategory = $baseCategory['children'][0];
273+
$this->assertEquals('Category 1.2', $firstChildCategory['name']);
274+
$this->assertEquals('Its a description of Test Category 1.2', $firstChildCategory['description']);
275+
276+
$firstChildCategoryExpectedProducts = [
277+
['sku' => 'simple', 'name' => 'Simple Product'],
278+
['sku' => 'simple-4', 'name' => 'Simple Product Three']
279+
];
280+
$this->assertCategoryProducts($firstChildCategory, $firstChildCategoryExpectedProducts);
281+
$firstChildCategoryChildren = [];
282+
$this->assertCategoryChildren($firstChildCategory, $firstChildCategoryChildren);
283+
}
284+
212285
/**
213286
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
214287
*/
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
include __DIR__ . '/categories.php';
8+
9+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
10+
11+
/** @var $category \Magento\Catalog\Model\Category */
12+
$category = $objectManager->create(\Magento\Catalog\Model\Category::class);
13+
14+
$category->load(4);
15+
$category->setIsActive(false);
16+
$category->save();
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
include __DIR__ . '/categories_rollback.php';

0 commit comments

Comments
 (0)