Skip to content

Commit

Permalink
Merge pull request #10829 from creative-commoners/pulls/4.13/fix-last…
Browse files Browse the repository at this point in the history
…-page

FIX LastPage method returns true if TotalPages equals 0
  • Loading branch information
GuySartorelli authored Jun 21, 2023
2 parents 5303e08 + ad9df97 commit ab4802c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ORM/PaginatedList.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public function NotFirstPage()
*/
public function LastPage()
{
return $this->CurrentPage() == $this->TotalPages();
return $this->CurrentPage() >= $this->TotalPages();
}

/**
Expand Down
11 changes: 11 additions & 0 deletions tests/php/ORM/PaginatedListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,20 @@ public function testLastPage()
$list = new PaginatedList(new ArrayList());
$list->setTotalItems(50);

$this->assertFalse($list->LastPage());
$list->setCurrentPage(4);
$this->assertFalse($list->LastPage());
$list->setCurrentPage(5);
$this->assertTrue($list->LastPage());
$list->setCurrentPage(6);
$this->assertTrue($list->LastPage());

$emptyList = new PaginatedList(new ArrayList());
$emptyList->setTotalItems(0);

$this->assertTrue($emptyList->LastPage());
$emptyList->setCurrentPage(1);
$this->assertTrue($emptyList->LastPage());
}

public function testNotLastPage()
Expand Down

0 comments on commit ab4802c

Please sign in to comment.