Skip to content

Commit 064a4ef

Browse files
committed
Return error when invalid currentPage is provided
Adds missing validation for the minimum page value Fixes #727
1 parent 98703f6 commit 064a4ef

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Category/Products.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ public function resolve(
6666
]
6767
];
6868
$searchCriteria = $this->searchCriteriaBuilder->build($field->getName(), $args);
69+
if ($args['currentPage'] < 1) {
70+
throw new GraphQlInputException(__('currentPage value must be greater than 0.'));
71+
}
72+
6973
$searchCriteria->setCurrentPage($args['currentPage']);
7074
$searchCriteria->setPageSize($args['pageSize']);
7175
$searchResult = $this->filterQuery->getResult($searchCriteria, $info);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ public function resolve(
7171
array $args = null
7272
) {
7373
$searchCriteria = $this->searchCriteriaBuilder->build($field->getName(), $args);
74+
if ($args['currentPage'] < 1) {
75+
throw new GraphQlInputException(__('currentPage value must be greater than 0.'));
76+
}
77+
7478
$searchCriteria->setCurrentPage($args['currentPage']);
7579
$searchCriteria->setPageSize($args['pageSize']);
7680
if (!isset($args['search']) && !isset($args['filter'])) {

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,37 @@ public function testFilterProductsThatAreOutOfStockWithConfigSettings()
11311131
$this->assertEquals(1, $response['products']['total_count']);
11321132
}
11331133

1134+
/**
1135+
* Verify that invalid page numbers return an error
1136+
*
1137+
* @magentoApiDataFixture Magento/Catalog/_files/products_with_layered_navigation_attribute.php
1138+
* @expectedException \Exception
1139+
* @expectedExceptionMessage currentPage value must be greater than 0
1140+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
1141+
*/
1142+
public function testInvalidPageNumbers()
1143+
{
1144+
$query = <<<QUERY
1145+
{
1146+
products (
1147+
filter: {
1148+
sku: {
1149+
like:"simple%"
1150+
}
1151+
}
1152+
pageSize: 4
1153+
currentPage: 0
1154+
) {
1155+
items {
1156+
sku
1157+
}
1158+
}
1159+
}
1160+
QUERY;
1161+
1162+
$this->graphQlQuery($query);
1163+
}
1164+
11341165
/**
11351166
* Asserts the different fields of items returned after search query is executed
11361167
*

0 commit comments

Comments
 (0)