Skip to content

Commit 239b0dd

Browse files
committed
MC-32388: Add url_path as a possible filter in categoryList query
1 parent 7c4cbef commit 239b0dd

File tree

2 files changed

+110
-1
lines changed

2 files changed

+110
-1
lines changed

app/code/Magento/CatalogGraphQl/etc/schema.graphqls

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,9 @@ input ProductAttributeFilterInput @doc(description: "ProductAttributeFilterInput
307307
input CategoryFilterInput @doc(description: "CategoryFilterInput defines the filters to be used in the search. A filter contains at least one attribute, a comparison operator, and the value that is being searched for.")
308308
{
309309
ids: FilterEqualTypeInput @doc(description: "Filter by category ID that uniquely identifies the category.")
310-
url_key: FilterEqualTypeInput @doc(description: "Filter by the part of the URL that identifies the category")
310+
url_key: FilterEqualTypeInput @doc(description: "Filter by the part of the URL that identifies the category.")
311311
name: FilterMatchTypeInput @doc(description: "Filter by the display name of the category.")
312+
url_path: FilterEqualTypeInput @doc(description: "Filter by the URL path for the category.")
312313
}
313314

314315
input ProductFilterInput @doc(description: "ProductFilterInput is deprecated, use @ProductAttributeFilterInput instead. ProductFilterInput defines the filters to be used in the search. A filter contains at least one attribute, a comparison operator, and the value that is being searched for.") {

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

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,114 @@ public function testCategoryImageName()
422422
$this->assertEquals($expectedImageUrl, $categoryList[0]['image']);
423423
}
424424

425+
/**
426+
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
427+
*/
428+
public function testFilterByUrlPathTopLevelCategory()
429+
{
430+
$urlPath = 'category-1';
431+
$query = <<<QUERY
432+
{
433+
categoryList(filters: {url_path: {eq: "$urlPath"}}){
434+
id
435+
name
436+
url_key
437+
url_path
438+
path
439+
position
440+
}
441+
}
442+
QUERY;
443+
444+
$response = $this->graphQlQuery($query);
445+
$this->assertArrayNotHasKey('errors', $response);
446+
$categoryList = $response['categoryList'];
447+
$this->assertCount(1, $categoryList);
448+
$this->assertEquals($urlPath, $categoryList[0]['url_path']);
449+
$this->assertEquals('Category 1', $categoryList[0]['name']);
450+
}
451+
452+
/**
453+
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
454+
*/
455+
public function testFilterByUrlPathNestedCategory()
456+
{
457+
$urlPath = 'category-1/category-1-1/category-1-1-1';
458+
$query = <<<QUERY
459+
{
460+
categoryList(filters: {url_path: {eq: "$urlPath"}}){
461+
id
462+
name
463+
url_key
464+
url_path
465+
path
466+
position
467+
}
468+
}
469+
QUERY;
470+
471+
$response = $this->graphQlQuery($query);
472+
$this->assertArrayNotHasKey('errors', $response);
473+
$categoryList = $response['categoryList'];
474+
$this->assertCount(1, $categoryList);
475+
$this->assertEquals($urlPath, $categoryList[0]['url_path']);
476+
$this->assertEquals('Category 1.1.1', $categoryList[0]['name']);
477+
}
478+
479+
/**
480+
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
481+
*/
482+
public function testFilterByUrlPathMultipleCategories()
483+
{
484+
$urlPaths = ['category-1/category-1-1', 'inactive', 'movable-position-2'];
485+
$urlPathsString = '"' . implode('", "', $urlPaths) . '"';
486+
$query = <<<QUERY
487+
{
488+
categoryList(filters: {url_path: {in: [$urlPathsString]}}){
489+
id
490+
name
491+
url_key
492+
url_path
493+
path
494+
position
495+
}
496+
}
497+
QUERY;
498+
499+
$response = $this->graphQlQuery($query);
500+
$this->assertArrayNotHasKey('errors', $response);
501+
$categoryList = $response['categoryList'];
502+
$this->assertCount(2, $categoryList);
503+
$this->assertEquals($urlPaths[0], $categoryList[0]['url_path']);
504+
$this->assertEquals('Category 1.1', $categoryList[0]['name']);
505+
$this->assertEquals($urlPaths[2], $categoryList[1]['url_path']);
506+
$this->assertEquals('Movable Position 2', $categoryList[1]['name']);
507+
}
508+
509+
/**
510+
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
511+
*/
512+
public function testFilterByUrlPathNoResults()
513+
{
514+
$query = <<<QUERY
515+
{
516+
categoryList(filters: {url_path: {in: ["not-a-category url path"]}}){
517+
id
518+
name
519+
url_key
520+
url_path
521+
path
522+
position
523+
}
524+
}
525+
QUERY;
526+
527+
$response = $this->graphQlQuery($query);
528+
$this->assertArrayNotHasKey('errors', $response);
529+
$categoryList = $response['categoryList'];
530+
$this->assertCount(0, $categoryList);
531+
}
532+
425533
/**
426534
* @return array
427535
*/

0 commit comments

Comments
 (0)