Skip to content

Commit b6256e4

Browse files
32460 add tests
1 parent cc9295c commit b6256e4

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/Query/CategoryUrlPathArgsProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function process(
7070

7171
if ($collection->count() === 0) {
7272
throw new GraphQlInputException(
73-
__('No category with the provided %1 was found', ['category_url_path'])
73+
__('No category with the provided `%1` was found', ['category_url_path'])
7474
);
7575
}
7676
$category = $collection->getFirstItem();

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

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,97 @@ public function testUidAndIdUsageErrorOnProductFilteringCategory()
8484
$this->graphQlQuery($query);
8585
}
8686

87+
88+
/**
89+
* Verify that filters category url path and uid can't be used at the same time
90+
*/
91+
public function testUidAndCategoryUrlPathUsageErrorOnProductFilteringCategory()
92+
{
93+
$this->expectException(\Exception::class);
94+
$this->expectExceptionMessage('`category_uid` and `category_url_path` can\'t be used at the same time');
95+
$query = <<<QUERY
96+
{
97+
products(filter: {category_uid: {eq: "OTk5OTk5OTk="}, category_url_path: {eq: "category-1/category-1-2"}}) {
98+
filters {
99+
name
100+
}
101+
}
102+
}
103+
QUERY;
104+
$this->graphQlQuery($query);
105+
}
106+
107+
/**
108+
* Filter by category url path
109+
*
110+
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
111+
*/
112+
public function testFilterByCategoryUrlPath()
113+
{
114+
$categoryUrlPath = 'category-1/category-1-2';
115+
$query = <<<QUERY
116+
{
117+
products(filter:{
118+
category_url_path : {eq:"{$categoryUrlPath}"}
119+
}) {
120+
total_count
121+
items {
122+
name
123+
sku
124+
}
125+
}
126+
}
127+
QUERY;
128+
$response = $this->graphQlQuery($query);
129+
$this->assertEquals(2, $response['products']['total_count']);
130+
/** @var ProductRepositoryInterface $productRepository */
131+
$productRepository = ObjectManager::getInstance()->get(ProductRepositoryInterface::class);
132+
$product1 = $productRepository->get('simple');
133+
$product2 = $productRepository->get('simple-4');
134+
$filteredProducts = [$product2, $product1];
135+
$productItemsInResponse = array_map(null, $response['products']['items'], $filteredProducts);
136+
//phpcs:ignore Generic.CodeAnalysis.ForLoopWithTestFunctionCall
137+
for ($itemIndex = 0; $itemIndex < count($filteredProducts); $itemIndex++) {
138+
$this->assertNotEmpty($productItemsInResponse[$itemIndex]);
139+
//validate that correct products are returned
140+
$this->assertResponseFields(
141+
$productItemsInResponse[$itemIndex][0],
142+
[
143+
'name' => $filteredProducts[$itemIndex]->getName(),
144+
'sku' => $filteredProducts[$itemIndex]->getSku()
145+
]
146+
);
147+
}
148+
}
149+
150+
/**
151+
* Filter by wrong category url path
152+
*
153+
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
154+
*/
155+
public function testFilterByWrongCategoryUrlPath()
156+
{
157+
$categoryUrlPath = 'test';
158+
159+
$this->expectException(\Exception::class);
160+
$this->expectExceptionMessage('No category with the provided `category_url_path` was found');
161+
162+
$query = <<<QUERY
163+
{
164+
products(filter:{
165+
category_url_path : {eq:"{$categoryUrlPath}"}
166+
}) {
167+
total_count
168+
items {
169+
name
170+
sku
171+
}
172+
}
173+
}
174+
QUERY;
175+
$this->graphQlQuery($query);
176+
}
177+
87178
/**
88179
* Verify that layered navigation filters and aggregations are correct for product query
89180
*

0 commit comments

Comments
 (0)