FIX When setting the page sizes, reset items per page to the first value

This commit is contained in:
Robbie Averill 2017-08-31 14:35:52 +12:00
parent f80fc03bbb
commit 58200f847f
2 changed files with 18 additions and 0 deletions

View File

@ -159,6 +159,10 @@ class GridFieldConfigurablePaginator extends GridFieldPaginator
public function setPageSizes(array $pageSizes)
{
$this->pageSizes = $pageSizes;
// Reset items per page
$this->setItemsPerPage(current($pageSizes));
return $this;
}

View File

@ -80,6 +80,20 @@ class GridFieldConfigurablePaginatorTest extends SapphireTest
$this->assertSame(3, $paginator->getTotalPages());
}
public function testItemsPerPageIsSetToFirstInPageSizesListWhenChanged()
{
$paginator = new GridFieldConfigurablePaginator(20, array(20, 40, 60));
$paginator->setGridField($this->gridField);
// Initial state, should be what was provided to the constructor
$this->assertSame(20, $paginator->getItemsPerPage());
$paginator->setPageSizes(array(50, 100, 200));
// Set via public API, should now be set to 50
$this->assertSame(50, $paginator->getItemsPerPage());
}
public function testGetCurrentPreviousAndNextPages()
{
$paginator = new GridFieldConfigurablePaginator(20, array(20, 40, 60));