Skip to content

Commit

Permalink
Pagination: open page > pageCount get last page
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Apr 16, 2020
1 parent 8b97001 commit af0d333
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion system/Pager/Pager.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,12 @@ public function store(string $group, int $page, int $perPage = null, int $total,
$this->ensureGroup($group, $perPage);

$perPage = $perPage ?? $this->config->perPage;
$pageCount = (int)ceil($total / $perPage);
$page = $page > $pageCount ? $pageCount : $page;
$this->groups[$group]['currentPage'] = $page;
$this->groups[$group]['perPage'] = $perPage;
$this->groups[$group]['total'] = $total;
$this->groups[$group]['pageCount'] = (int)ceil($total / $perPage);
$this->groups[$group]['pageCount'] = $pageCount;

return $this;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/system/Pager/PagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,10 @@ public function testBasedURI()
$this->assertEquals((string)$expected, $this->pager->getPreviousPageURI('foo'));
}

public function testAccessPageMoreThanPageCountGetLastPage()
{
$this->pager->store('default', 11, 1, 10);
$this->assertEquals(10, $this->pager->getCurrentPage());
}

}

0 comments on commit af0d333

Please sign in to comment.