‪TYPO3CMS  10.4
SimplePaginationTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
24 class ‪SimplePaginationTest extends UnitTestCase
25 {
29  protected ‪$paginator = [];
30 
31  protected function ‪setUp(): void
32  {
33  parent::setUp();
34 
35  $this->paginator = new ‪ArrayPaginator(range(1, 14, 1));
36  }
37 
42  {
43  $pagination = new ‪SimplePagination($this->paginator);
44 
45  self::assertSame(1, $pagination->getStartRecordNumber());
46  self::assertSame(10, $pagination->getEndRecordNumber());
47  self::assertSame(1, $pagination->getFirstPageNumber());
48  self::assertSame(2, $pagination->getLastPageNumber());
49  self::assertNull($pagination->getPreviousPageNumber());
50  self::assertSame(2, $pagination->getNextPageNumber());
51  self::assertSame([1, 2], $pagination->getAllPageNumbers());
52  }
53 
58  {
59  ‪$paginator = $this->paginator
60  ->withCurrentPageNumber(2)
61  ;
62 
63  $pagination = new SimplePagination(‪$paginator);
64 
65  self::assertSame(11, $pagination->getStartRecordNumber());
66  self::assertSame(14, $pagination->getEndRecordNumber());
67  self::assertSame(1, $pagination->getFirstPageNumber());
68  self::assertSame(2, $pagination->getLastPageNumber());
69  self::assertSame(1, $pagination->getPreviousPageNumber());
70  self::assertNull($pagination->getNextPageNumber());
71  self::assertSame([1, 2], $pagination->getAllPageNumbers());
72  }
73 
78  {
79  ‪$paginator = $this->paginator
80  ->withItemsPerPage(3)
81  ->withCurrentPageNumber(2)
82  ;
83  $pagination = new SimplePagination(‪$paginator);
84 
85  self::assertSame(4, $pagination->getStartRecordNumber());
86  self::assertSame(6, $pagination->getEndRecordNumber());
87  self::assertSame(1, $pagination->getFirstPageNumber());
88  self::assertSame(5, $pagination->getLastPageNumber());
89  self::assertSame(1, $pagination->getPreviousPageNumber());
90  self::assertSame(3, $pagination->getNextPageNumber());
91  self::assertSame([1, 2, 3, 4, 5], $pagination->getAllPageNumbers());
92  }
93 
98  {
99  ‪$paginator = $this->paginator
100  ->withItemsPerPage(50)
101  ;
102  $pagination = new SimplePagination(‪$paginator);
103 
104  self::assertSame(1, $pagination->getStartRecordNumber());
105  self::assertSame(14, $pagination->getEndRecordNumber());
106  self::assertSame(1, $pagination->getFirstPageNumber());
107  self::assertSame(1, $pagination->getLastPageNumber());
108  self::assertNull($pagination->getPreviousPageNumber());
109  self::assertNull($pagination->getNextPageNumber());
110  self::assertSame([1], $pagination->getAllPageNumbers());
111  }
112 
116  public function ‪checkPaginatorWithOutOfBoundsCurrentPage(): void
117  {
118  ‪$paginator = $this->paginator
119  ->withItemsPerPage(5)
120  ->withCurrentPageNumber(100)
121  ;
122  $pagination = new SimplePagination(‪$paginator);
123 
124  self::assertSame(11, $pagination->getStartRecordNumber());
125  self::assertSame(14, $pagination->getEndRecordNumber());
126  self::assertSame(3, ‪$paginator->getCurrentPageNumber());
127  self::assertSame(1, $pagination->getFirstPageNumber());
128  self::assertSame(2, $pagination->getPreviousPageNumber());
129  self::assertNull($pagination->getNextPageNumber());
130  self::assertSame(3, $pagination->getLastPageNumber());
131  self::assertSame([1, 2, 3], $pagination->getAllPageNumbers());
132  }
133 }
‪TYPO3\CMS\Core\Tests\Unit\Pagination\SimplePaginationTest
Definition: SimplePaginationTest.php:25
‪TYPO3\CMS\Core\Tests\Unit\Pagination\SimplePaginationTest\checkSimplePaginationWithAnIncreasedCurrentPageNumberAndItemsPerPage
‪checkSimplePaginationWithAnIncreasedCurrentPageNumberAndItemsPerPage()
Definition: SimplePaginationTest.php:76
‪TYPO3\CMS\Core\Tests\Unit\Pagination\SimplePaginationTest\checkSimplePaginationWithAPaginatorWithDefaultSettings
‪checkSimplePaginationWithAPaginatorWithDefaultSettings()
Definition: SimplePaginationTest.php:40
‪TYPO3\CMS\Core\Pagination\SimplePagination
Definition: SimplePagination.php:21
‪TYPO3\CMS\Core\Tests\Unit\Pagination
Definition: ArrayPaginatorTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Pagination\SimplePaginationTest\$paginator
‪array $paginator
Definition: SimplePaginationTest.php:28
‪TYPO3\CMS\Core\Pagination\ArrayPaginator
Definition: ArrayPaginator.php:21
‪TYPO3\CMS\Core\Tests\Unit\Pagination\SimplePaginationTest\checkPaginationWithAPaginatorThatOnlyHasOnePage
‪checkPaginationWithAPaginatorThatOnlyHasOnePage()
Definition: SimplePaginationTest.php:96
‪TYPO3\CMS\Core\Tests\Unit\Pagination\SimplePaginationTest\checkSimplePaginationWithAnIncreasedCurrentPageNumber
‪checkSimplePaginationWithAnIncreasedCurrentPageNumber()
Definition: SimplePaginationTest.php:56
‪TYPO3\CMS\Core\Tests\Unit\Pagination\SimplePaginationTest\setUp
‪setUp()
Definition: SimplePaginationTest.php:30
‪TYPO3\CMS\Core\Tests\Unit\Pagination\SimplePaginationTest\checkPaginatorWithOutOfBoundsCurrentPage
‪checkPaginatorWithOutOfBoundsCurrentPage()
Definition: SimplePaginationTest.php:115