Skip to content

Commit

Permalink
Create more tests for the page start and end, and improve the comment…
Browse files Browse the repository at this point in the history
… of the variables from the PagerRenderer class.
  • Loading branch information
murilohpucci committed Jan 4, 2025
1 parent 2aabf60 commit d9ad33b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
6 changes: 3 additions & 3 deletions system/Pager/PagerRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ class PagerRenderer
protected $pageSelector;

/**
* The number of items a page.
* The maximum number of items displayed per page.
*/
protected ?int $perPage;

/**
* The total items the current has started.
* The index of the first item on the current page.
*/
protected ?int $perPageStart;

/**
* The total items of the current page;
* The index of the last item on the current page.s
*/
protected ?int $perPageEnd;

Expand Down
28 changes: 28 additions & 0 deletions tests/system/Pager/PagerRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,9 @@ public function testGetNextPageNumberNull(): void
$this->assertNull($pager->getNextPageNumber());
}

/**
* @param array<string, array<string, mixed>> $details
*/
#[DataProvider('providePageStartEnd')]
public function testPageStartEnd(array $details, int $pageStart, int $pageEnd): void
{
Expand All @@ -631,6 +634,9 @@ public function testPageStartEnd(array $details, int $pageStart, int $pageEnd):
$this->assertSame($pager->getPerPageEnd(), $pageEnd);
}

/**
* @return array<string, array<string, mixed>> $details
*/
public static function providePageStartEnd(): iterable
{
$uri = new URI('http://example.com/foo');
Expand Down Expand Up @@ -669,6 +675,28 @@ public static function providePageStartEnd(): iterable
'pageStart' => 21,
'pageEnd' => 25,
],
'current greater last page' => [
'details' => [
'uri' => $uri,
'pageCount' => 3,
'total' => 25,
'currentPage' => 5,
'perPage' => 10,
],
'pageStart' => 41,
'pageEnd' => 50,
],
'current equal last page' => [
'details' => [
'uri' => $uri,
'pageCount' => 1,
'total' => 10,
'currentPage' => 1,
'perPage' => 10,
],
'pageStart' => 1,
'pageEnd' => 10,
],
];
}
}

0 comments on commit d9ad33b

Please sign in to comment.