Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public function testSearchAddresses($filters, $filterGroup, $filterOrders, $expe
}

$searchBuilder->setPageSize(1);
$searchBuilder->setCurrentPage(2);
$searchBuilder->setCurrentPage(count($expectedResult));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is necessary because some of the tests only expect 1 page back. This change ensures that tests that expect 1 page do not request the second page.


$searchCriteria = $searchBuilder->create();
$searchResults = $this->repository->getList($searchCriteria);
Expand Down
5 changes: 1 addition & 4 deletions lib/internal/Magento/Framework/Data/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,8 @@ public function getCurPage($displacement = 0)
{
if ($this->_curPage + $displacement < 1) {
return 1;
} elseif ($this->_curPage + $displacement > $this->getLastPageNumber()) {
return $this->getLastPageNumber();
} else {
return $this->_curPage + $displacement;
}
return $this->_curPage + $displacement;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ public function testFlag()
public function testGetCurPage()
{
$this->_model->setCurPage(10);
$this->assertEquals(10, $this->_model->getCurPage());

$this->_model->setCurPage(-10);
$this->assertEquals(1, $this->_model->getCurPage());

$this->_model->setCurPage(0);
$this->assertEquals(1, $this->_model->getCurPage());

$this->_model->setCurPage(1);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change removes the assumption that Page 10 of 1 should return Page 1, but preserves the assumption that Pages < 1 return Page 1.

$this->assertEquals(1, $this->_model->getCurPage());
}

Expand Down