‪TYPO3CMS  10.4
QueryResultPaginatorTest.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 
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25 
26 class ‪QueryResultPaginatorTest extends FunctionalTestCase
27 {
31  protected ‪$coreExtensionsToLoad = ['extbase', 'fluid'];
32 
36  protected ‪$testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
37 
41  protected ‪$postRepository;
42 
43  protected function ‪setUp(): void
44  {
45  parent::setUp();
46 
47  $this->importDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/posts.xml');
48 
49  $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
50  $this->postRepository = $objectManager->get(PostRepository::class);
51  }
52 
58  public function ‪integration()
59  {
60  $queryResult = $this->postRepository->findAll();
61  self::assertCount(14, $queryResult);
62  }
63 
68  {
69  $paginator = new ‪QueryResultPaginator($this->postRepository->findAll());
70 
71  self::assertSame(2, $paginator->getNumberOfPages());
72  self::assertSame(0, $paginator->getKeyOfFirstPaginatedItem());
73  self::assertSame(9, $paginator->getKeyOfLastPaginatedItem());
74  self::assertCount(10, $paginator->getPaginatedItems());
75  }
76 
81  {
82  $paginator = new ‪QueryResultPaginator(
83  $this->postRepository->findAll(),
84  1,
85  3
86  );
87 
88  self::assertSame(5, $paginator->getNumberOfPages());
89  self::assertSame(0, $paginator->getKeyOfFirstPaginatedItem());
90  self::assertSame(2, $paginator->getKeyOfLastPaginatedItem());
91  self::assertCount(3, $paginator->getPaginatedItems());
92  }
93 
98  {
99  $paginator = new ‪QueryResultPaginator(
100  $this->postRepository->findAll(),
101  3,
102  3
103  );
104 
105  self::assertSame(5, $paginator->getNumberOfPages());
106  self::assertSame(6, $paginator->getKeyOfFirstPaginatedItem());
107  self::assertSame(8, $paginator->getKeyOfLastPaginatedItem());
108  self::assertCount(3, $paginator->getPaginatedItems());
109  }
110 
115  {
116  $paginator = new ‪QueryResultPaginator(
117  $this->postRepository->findAll(),
118  5,
119  3
120  );
121 
122  self::assertSame(5, $paginator->getNumberOfPages());
123  self::assertSame(12, $paginator->getKeyOfFirstPaginatedItem());
124  self::assertSame(13, $paginator->getKeyOfLastPaginatedItem());
125  self::assertCount(2, $paginator->getPaginatedItems());
126  }
127 
132  {
133  static::expectExceptionCode(1573047338);
134 
135  $paginator = new ‪QueryResultPaginator(
136  $this->postRepository->findAll(),
137  1,
138  3
139  );
140  $paginator->withCurrentPageNumber(0);
141  }
142 
147  {
148  $paginator = new ‪QueryResultPaginator(
149  $this->postRepository->findAll(),
150  3,
151  10
152  );
153 
154  self::assertEquals(2, $paginator->getCurrentPageNumber());
155  self::assertEquals(2, $paginator->getNumberOfPages());
156  self::assertCount(4, $paginator->getPaginatedItems());
157  }
158 
163  {
164  $paginator = new ‪QueryResultPaginator(
165  $this->postRepository->findAll(),
166  1,
167  50
168  );
169 
170  self::assertSame(1, $paginator->getNumberOfPages());
171  self::assertSame(0, $paginator->getKeyOfFirstPaginatedItem());
172  self::assertSame(13, $paginator->getKeyOfLastPaginatedItem());
173  self::assertCount(14, $paginator->getPaginatedItems());
174  }
175 }
‪TYPO3\CMS\Extbase\Tests\Functional\Pagination\QueryResultPaginatorTest\withCurrentPageNumberThrowsInvalidArgumentExceptionIfCurrentPageIsLowerThanOne
‪withCurrentPageNumberThrowsInvalidArgumentExceptionIfCurrentPageIsLowerThanOne()
Definition: QueryResultPaginatorTest.php:128
‪TYPO3\CMS\Extbase\Tests\Functional\Pagination\QueryResultPaginatorTest\$postRepository
‪PostRepository $postRepository
Definition: QueryResultPaginatorTest.php:38
‪TYPO3\CMS\Extbase\Tests\Functional\Pagination\QueryResultPaginatorTest\paginatorProperlyCalculatesOnlyOnePage
‪paginatorProperlyCalculatesOnlyOnePage()
Definition: QueryResultPaginatorTest.php:159
‪TYPO3\CMS\Extbase\Tests\Functional\Pagination\QueryResultPaginatorTest\paginatorRespectsItemsPerPageConfigurationAndCurrentPage
‪paginatorRespectsItemsPerPageConfigurationAndCurrentPage()
Definition: QueryResultPaginatorTest.php:94
‪TYPO3\CMS\Extbase\Tests\Functional\Pagination\QueryResultPaginatorTest
Definition: QueryResultPaginatorTest.php:27
‪TYPO3\CMS\Extbase\Pagination\QueryResultPaginator
Definition: QueryResultPaginator.php:24
‪TYPO3\CMS\Extbase\Tests\Functional\Pagination\QueryResultPaginatorTest\checkPaginatorWithDefaultConfiguration
‪checkPaginatorWithDefaultConfiguration()
Definition: QueryResultPaginatorTest.php:64
‪TYPO3\CMS\Extbase\Tests\Functional\Pagination\QueryResultPaginatorTest\setUp
‪setUp()
Definition: QueryResultPaginatorTest.php:40
‪TYPO3\CMS\Extbase\Tests\Functional\Pagination
Definition: QueryResultPaginatorTest.php:18
‪TYPO3\CMS\Extbase\Tests\Functional\Pagination\QueryResultPaginatorTest\paginatorRespectsItemsPerPageConfiguration
‪paginatorRespectsItemsPerPageConfiguration()
Definition: QueryResultPaginatorTest.php:77
‪TYPO3\CMS\Extbase\Tests\Functional\Pagination\QueryResultPaginatorTest\integration
‪integration()
Definition: QueryResultPaginatorTest.php:55
‪TYPO3\CMS\Extbase\Tests\Functional\Pagination\QueryResultPaginatorTest\paginatorSetsCurrentPageToLastPageIfCurrentPageExceedsMaximum
‪paginatorSetsCurrentPageToLastPageIfCurrentPageExceedsMaximum()
Definition: QueryResultPaginatorTest.php:143
‪TYPO3\CMS\Extbase\Tests\Functional\Pagination\QueryResultPaginatorTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: QueryResultPaginatorTest.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪ExtbaseTeam\BlogExample\Domain\Repository\PostRepository
Definition: PostRepository.php:30
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28
‪TYPO3\CMS\Extbase\Tests\Functional\Pagination\QueryResultPaginatorTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: QueryResultPaginatorTest.php:34
‪TYPO3\CMS\Extbase\Tests\Functional\Pagination\QueryResultPaginatorTest\paginatorProperlyCalculatesLastPage
‪paginatorProperlyCalculatesLastPage()
Definition: QueryResultPaginatorTest.php:111