Skip to content

Commit

Permalink
Return error when invalid currentPage is provided
Browse files Browse the repository at this point in the history
Adds missing validation for the minimum page value

Fixes magento#727
  • Loading branch information
pmclain committed Jun 4, 2019
1 parent 98703f6 commit 064a4ef
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public function resolve(
]
];
$searchCriteria = $this->searchCriteriaBuilder->build($field->getName(), $args);
if ($args['currentPage'] < 1) {
throw new GraphQlInputException(__('currentPage value must be greater than 0.'));
}

$searchCriteria->setCurrentPage($args['currentPage']);
$searchCriteria->setPageSize($args['pageSize']);
$searchResult = $this->filterQuery->getResult($searchCriteria, $info);
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/CatalogGraphQl/Model/Resolver/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ public function resolve(
array $args = null
) {
$searchCriteria = $this->searchCriteriaBuilder->build($field->getName(), $args);
if ($args['currentPage'] < 1) {
throw new GraphQlInputException(__('currentPage value must be greater than 0.'));
}

$searchCriteria->setCurrentPage($args['currentPage']);
$searchCriteria->setPageSize($args['pageSize']);
if (!isset($args['search']) && !isset($args['filter'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,37 @@ public function testFilterProductsThatAreOutOfStockWithConfigSettings()
$this->assertEquals(1, $response['products']['total_count']);
}

/**
* Verify that invalid page numbers return an error
*
* @magentoApiDataFixture Magento/Catalog/_files/products_with_layered_navigation_attribute.php
* @expectedException \Exception
* @expectedExceptionMessage currentPage value must be greater than 0
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testInvalidPageNumbers()
{
$query = <<<QUERY
{
products (
filter: {
sku: {
like:"simple%"
}
}
pageSize: 4
currentPage: 0
) {
items {
sku
}
}
}
QUERY;

$this->graphQlQuery($query);
}

/**
* Asserts the different fields of items returned after search query is executed
*
Expand Down

0 comments on commit 064a4ef

Please sign in to comment.