‪TYPO3CMS  10.4
ArrayPaginatorTest.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 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
23 class ‪ArrayPaginatorTest extends UnitTestCase
24 {
28  protected ‪$fixture = [];
29 
30  protected function ‪setUp(): void
31  {
32  parent::setUp();
33  $this->fixture = range(1, 14, 1);
34  }
35 
41  public function ‪integration()
42  {
43  self::assertCount(14, $this->fixture);
44  }
45 
50  {
51  $paginator = new ArrayPaginator($this->fixture);
52 
53  self::assertSame(2, $paginator->getNumberOfPages());
54  self::assertSame(0, $paginator->getKeyOfFirstPaginatedItem());
55  self::assertSame(9, $paginator->getKeyOfLastPaginatedItem());
56  self::assertCount(10, $paginator->getPaginatedItems());
57  }
58 
63  {
64  $paginator = new ArrayPaginator(
65  $this->fixture,
66  1,
67  3
68  );
69 
70  self::assertSame(5, $paginator->getNumberOfPages());
71  self::assertSame(0, $paginator->getKeyOfFirstPaginatedItem());
72  self::assertSame(2, $paginator->getKeyOfLastPaginatedItem());
73  self::assertCount(3, $paginator->getPaginatedItems());
74  }
75 
80  {
81  $paginator = new ArrayPaginator(
82  $this->fixture,
83  3,
84  3
85  );
86 
87  self::assertSame(5, $paginator->getNumberOfPages());
88  self::assertSame(6, $paginator->getKeyOfFirstPaginatedItem());
89  self::assertSame(8, $paginator->getKeyOfLastPaginatedItem());
90  self::assertCount(3, $paginator->getPaginatedItems());
91  }
92 
97  {
98  $paginator = new ArrayPaginator(
99  $this->fixture,
100  5,
101  3
102  );
103 
104  self::assertSame(5, $paginator->getNumberOfPages());
105  self::assertSame(12, $paginator->getKeyOfFirstPaginatedItem());
106  self::assertSame(13, $paginator->getKeyOfLastPaginatedItem());
107  self::assertCount(2, $paginator->getPaginatedItems());
108  }
109 
114  {
115  static::expectExceptionCode(1573047338);
116 
117  $paginator = new ArrayPaginator(
118  $this->fixture,
119  1,
120  3
121  );
122  $paginator->withCurrentPageNumber(0);
123  }
124 
129  {
130  $paginator = new ArrayPaginator(
131  $this->fixture,
132  3,
133  10
134  );
135 
136  self::assertEquals(2, $paginator->getCurrentPageNumber());
137  self::assertEquals(2, $paginator->getNumberOfPages());
138  self::assertCount(4, $paginator->getPaginatedItems());
139  }
140 
145  {
146  $paginator = new ArrayPaginator(
147  $this->fixture,
148  1,
149  50
150  );
151 
152  self::assertSame(1, $paginator->getNumberOfPages());
153  self::assertSame(0, $paginator->getKeyOfFirstPaginatedItem());
154  self::assertSame(13, $paginator->getKeyOfLastPaginatedItem());
155  self::assertCount(14, $paginator->getPaginatedItems());
156  }
157 }
‪TYPO3\CMS\Core\Tests\Unit\Pagination\ArrayPaginatorTest\setUp
‪setUp()
Definition: ArrayPaginatorTest.php:29
‪TYPO3\CMS\Core\Tests\Unit\Pagination\ArrayPaginatorTest\paginatorSetsCurrentPageToLastPageIfCurrentPageExceedsMaximum
‪paginatorSetsCurrentPageToLastPageIfCurrentPageExceedsMaximum()
Definition: ArrayPaginatorTest.php:127
‪TYPO3\CMS\Core\Tests\Unit\Pagination\ArrayPaginatorTest
Definition: ArrayPaginatorTest.php:24
‪TYPO3\CMS\Core\Tests\Unit\Pagination\ArrayPaginatorTest\paginatorRespectsItemsPerPageConfiguration
‪paginatorRespectsItemsPerPageConfiguration()
Definition: ArrayPaginatorTest.php:61
‪TYPO3\CMS\Core\Tests\Unit\Pagination\ArrayPaginatorTest\checkPaginatorWithDefaultConfiguration
‪checkPaginatorWithDefaultConfiguration()
Definition: ArrayPaginatorTest.php:48
‪TYPO3\CMS\Core\Tests\Unit\Pagination
Definition: ArrayPaginatorTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Pagination\ArrayPaginatorTest\paginatorProperlyCalculatesLastPage
‪paginatorProperlyCalculatesLastPage()
Definition: ArrayPaginatorTest.php:95
‪TYPO3\CMS\Core\Tests\Unit\Pagination\ArrayPaginatorTest\withCurrentPageNumberThrowsInvalidArgumentExceptionIfCurrentPageIsLowerThanOne
‪withCurrentPageNumberThrowsInvalidArgumentExceptionIfCurrentPageIsLowerThanOne()
Definition: ArrayPaginatorTest.php:112
‪TYPO3\CMS\Core\Pagination\ArrayPaginator
Definition: ArrayPaginator.php:21
‪TYPO3\CMS\Core\Tests\Unit\Pagination\ArrayPaginatorTest\integration
‪integration()
Definition: ArrayPaginatorTest.php:40
‪TYPO3\CMS\Core\Tests\Unit\Pagination\ArrayPaginatorTest\$fixture
‪array $fixture
Definition: ArrayPaginatorTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Pagination\ArrayPaginatorTest\paginatorRespectsItemsPerPageConfigurationAndCurrentPage
‪paginatorRespectsItemsPerPageConfigurationAndCurrentPage()
Definition: ArrayPaginatorTest.php:78
‪TYPO3\CMS\Core\Tests\Unit\Pagination\ArrayPaginatorTest\paginatorProperlyCalculatesOnlyOnePage
‪paginatorProperlyCalculatesOnlyOnePage()
Definition: ArrayPaginatorTest.php:143