‪TYPO3CMS  9.5
PaginateControllerTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18 
22 class ‪PaginateControllerTest extends UnitTestCase
23 {
27  protected ‪$query;
28 
32  protected ‪$controller;
33 
37  protected ‪$querySettings;
38 
43 
47  protected ‪$backend;
48 
52  protected ‪$dataMapper;
53 
57  protected function ‪setUp()
58  {
59  $this->query = $this->getAccessibleMock(\‪TYPO3\CMS\‪Extbase\Persistence\Generic\Query::class, ['dummy'], ['someType']);
60  $this->querySettings = $this->createMock(\‪TYPO3\CMS\‪Extbase\Persistence\Generic\QuerySettingsInterface::class);
61  $this->query->_set('querySettings', $this->querySettings);
62  $this->persistenceManager = $this->createMock(\‪TYPO3\CMS\‪Extbase\Persistence\PersistenceManagerInterface::class);
63  $this->backend = $this->createMock(\‪TYPO3\CMS\‪Extbase\Persistence\Generic\BackendInterface::class);
64  $this->query->_set('persistenceManager', $this->persistenceManager);
65  $this->dataMapper = $this->createMock(\‪TYPO3\CMS\‪Extbase\Persistence\Generic\Mapper\DataMapper::class);
66  $this->query->_set('dataMapper', $this->dataMapper);
67  $this->controller = $this->getAccessibleMock(
68  \‪TYPO3\CMS\Fluid\ViewHelpers\Widget\Controller\PaginateController::class,
69  ['dummy'],
70  [],
71  '',
72  false
73  );
74  $this->controller->_set('view', $this->createMock(\‪TYPO3\CMS\‪Extbase\Mvc\View\ViewInterface::class));
75  }
76 
81  {
82  $this->controller->_set('maximumNumberOfLinks', 8);
83  $this->controller->_set('numberOfPages', 100);
84  $this->controller->_set('currentPage', 50);
85  $this->controller->_call('calculateDisplayRange');
86  $this->assertSame(46, $this->controller->_get('displayRangeStart'));
87  $this->assertSame(53, $this->controller->_get('displayRangeEnd'));
88  }
89 
94  {
95  $this->controller->_set('maximumNumberOfLinks', 7);
96  $this->controller->_set('numberOfPages', 100);
97  $this->controller->_set('currentPage', 50);
98  $this->controller->_call('calculateDisplayRange');
99  $this->assertSame(47, $this->controller->_get('displayRangeStart'));
100  $this->assertSame(53, $this->controller->_get('displayRangeEnd'));
101  }
102 
107  {
108  $this->controller->_set('maximumNumberOfLinks', 8);
109  $this->controller->_set('numberOfPages', 100);
110  $this->controller->_set('currentPage', 1);
111  $this->controller->_call('calculateDisplayRange');
112  $this->assertSame(1, $this->controller->_get('displayRangeStart'));
113  $this->assertSame(8, $this->controller->_get('displayRangeEnd'));
114  }
115 
120  {
121  $this->controller->_set('maximumNumberOfLinks', 7);
122  $this->controller->_set('numberOfPages', 100);
123  $this->controller->_set('currentPage', 1);
124  $this->controller->_call('calculateDisplayRange');
125  $this->assertSame(1, $this->controller->_get('displayRangeStart'));
126  $this->assertSame(7, $this->controller->_get('displayRangeEnd'));
127  }
128 
133  {
134  $this->controller->_set('maximumNumberOfLinks', 8);
135  $this->controller->_set('numberOfPages', 100);
136  $this->controller->_set('currentPage', 100);
137  $this->controller->_call('calculateDisplayRange');
138  $this->assertSame(93, $this->controller->_get('displayRangeStart'));
139  $this->assertSame(100, $this->controller->_get('displayRangeEnd'));
140  }
141 
146  {
147  $this->controller->_set('maximumNumberOfLinks', 7);
148  $this->controller->_set('numberOfPages', 100);
149  $this->controller->_set('currentPage', 100);
150  $this->controller->_call('calculateDisplayRange');
151  $this->assertSame(94, $this->controller->_get('displayRangeStart'));
152  $this->assertSame(100, $this->controller->_get('displayRangeEnd'));
153  }
154 
159  {
160  $mockQueryResult = $this->createMock(\‪TYPO3\CMS\‪Extbase\Persistence\QueryResultInterface::class);
161  $mockQuery = $this->createMock(\‪TYPO3\CMS\‪Extbase\Persistence\QueryInterface::class);
162  $mockQueryResult->expects($this->any())->method('getQuery')->will($this->returnValue($mockQuery));
163  $this->controller->_set('objects', $mockQueryResult);
164  $this->controller->_set('widgetConfiguration', ['as' => 'paginatedObjects']);
165  $this->controller->indexAction();
166  $this->assertSame($mockQueryResult, $this->controller->_get('objects'));
167  }
168 
172  public function ‪acceptArrayAsObjects()
173  {
174  $objects = [];
175  $this->controller->_set('objects', $objects);
176  $this->controller->_set('widgetConfiguration', ['as' => 'paginatedObjects']);
177  $this->controller->indexAction();
178  $this->assertSame($objects, $this->controller->_get('objects'));
179  }
180 
184  public function ‪acceptObjectStorageAsObjects()
185  {
186  $objects = new ‪ObjectStorage();
187  $this->controller->_set('objects', $objects);
188  $this->controller->_set('widgetConfiguration', ['as' => 'paginatedObjects']);
189  $this->controller->indexAction();
190  $this->assertSame($objects, $this->controller->_get('objects'));
191  }
192 
197  {
198  $objects = new ‪ObjectStorage();
199  for ($i = 0; $i <= 25; $i++) {
200  $item = new \stdClass;
201  $objects->attach($item);
202  }
203  $this->controller->_set('objects', $objects);
204  $expectedPortion = [];
205  for ($j = 0; $j <= 9; $j++) {
206  $expectedPortion[] = $objects->toArray()[$j];
207  }
208  $this->assertSame($expectedPortion, $this->controller->_call('prepareObjectsSlice', 10, 0));
209  }
210 
215  {
216  $this->controller->_set('currentPage', 2);
217  $objects = new ‪ObjectStorage();
218  for ($i = 0; $i <= 55; $i++) {
219  $item = new \stdClass;
220  $objects->attach($item);
221  }
222  $this->controller->_set('objects', $objects);
223  $expectedPortion = [];
224  for ($j = 10; $j <= 19; $j++) {
225  $expectedPortion[] = $objects->toArray()[$j];
226  }
227  $this->assertSame($expectedPortion, $this->controller->_call('prepareObjectsSlice', 10, 10));
228  }
229 
234  {
235  $this->controller->_set('currentPage', 3);
236  $objects = new ‪ObjectStorage();
237  for ($i = 0; $i <= 25; $i++) {
238  $item = new \stdClass;
239  $objects->attach($item);
240  }
241  $this->controller->_set('objects', $objects);
242  $expectedPortion = [];
243  for ($j = 20; $j <= 25; $j++) {
244  $expectedPortion[] = $objects->toArray()[$j];
245  }
246  $this->assertSame($expectedPortion, $this->controller->_call('prepareObjectsSlice', 10, 20));
247  }
248 
253  {
254  $objects = [];
255  for ($i = 0; $i <= 25; $i++) {
256  $item = new \stdClass;
257  $objects[] = $item;
258  }
259  $this->controller->_set('objects', $objects);
260  $expectedPortion = [];
261  for ($j = 0; $j <= 9; $j++) {
262  $expectedPortion = array_slice($objects, 0, 10);
263  }
264  $this->assertSame($expectedPortion, $this->controller->_call('prepareObjectsSlice', 10, 0));
265  }
266 
271  {
272  $this->controller->_set('currentPage', 2);
273  $objects = [];
274  for ($i = 0; $i <= 55; $i++) {
275  $item = new \stdClass;
276  $objects[] = $item;
277  }
278  $this->controller->_set('objects', $objects);
279  $expectedPortion = [];
280  for ($j = 10; $j <= 19; $j++) {
281  $expectedPortion = array_slice($objects, 10, 10);
282  }
283  $this->assertSame($expectedPortion, $this->controller->_call('prepareObjectsSlice', 10, 10));
284  }
285 }
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest\calculateDisplayRangeDeterminesCorrectDisplayRangeStartAndEndForOddMaximumNumberOfLinksWhenOnFirstPage
‪calculateDisplayRangeDeterminesCorrectDisplayRangeStartAndEndForOddMaximumNumberOfLinksWhenOnFirstPage()
Definition: PaginateControllerTest.php:113
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest\calculateDisplayRangeDeterminesCorrectDisplayRangeStartAndEndForEvenMaximumNumberOfLinksWhenOnFirstPage
‪calculateDisplayRangeDeterminesCorrectDisplayRangeStartAndEndForEvenMaximumNumberOfLinksWhenOnFirstPage()
Definition: PaginateControllerTest.php:100
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest\prepareObjectsSliceReturnsCorrectPortionForArrayAndFirstPage
‪prepareObjectsSliceReturnsCorrectPortionForArrayAndFirstPage()
Definition: PaginateControllerTest.php:246
‪TYPO3
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest\calculateDisplayRangeDeterminesCorrectDisplayRangeStartAndEndForEvenMaximumNumberOfLinksWhenOnLastPage
‪calculateDisplayRangeDeterminesCorrectDisplayRangeStartAndEndForEvenMaximumNumberOfLinksWhenOnLastPage()
Definition: PaginateControllerTest.php:126
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest\$backend
‪TYPO3 CMS Extbase Persistence Generic BackendInterface $backend
Definition: PaginateControllerTest.php:42
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller
Definition: PaginateControllerTest.php:2
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest\calculateDisplayRangeDeterminesCorrectDisplayRangeStartAndEndForEvenMaximumNumberOfLinks
‪calculateDisplayRangeDeterminesCorrectDisplayRangeStartAndEndForEvenMaximumNumberOfLinks()
Definition: PaginateControllerTest.php:74
‪TYPO3\CMS\Extbase\Persistence\ObjectStorage
Definition: ObjectStorage.php:26
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest\prepareObjectsSliceReturnsCorrectPortionForArrayAndSecondPage
‪prepareObjectsSliceReturnsCorrectPortionForArrayAndSecondPage()
Definition: PaginateControllerTest.php:264
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest\acceptArrayAsObjects
‪acceptArrayAsObjects()
Definition: PaginateControllerTest.php:166
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest\$persistenceManager
‪TYPO3 CMS Extbase Persistence PersistenceManagerInterface $persistenceManager
Definition: PaginateControllerTest.php:38
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest\calculateDisplayRangeDeterminesCorrectDisplayRangeStartAndEndForOddMaximumNumberOfLinks
‪calculateDisplayRangeDeterminesCorrectDisplayRangeStartAndEndForOddMaximumNumberOfLinks()
Definition: PaginateControllerTest.php:87
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest\prepareObjectsSliceReturnsCorrectPortionForObjectStorageAndSecondPage
‪prepareObjectsSliceReturnsCorrectPortionForObjectStorageAndSecondPage()
Definition: PaginateControllerTest.php:208
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest\prepareObjectsSliceReturnsCorrectPortionForObjectStorageAndLastPage
‪prepareObjectsSliceReturnsCorrectPortionForObjectStorageAndLastPage()
Definition: PaginateControllerTest.php:227
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest\acceptObjectStorageAsObjects
‪acceptObjectStorageAsObjects()
Definition: PaginateControllerTest.php:178
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest\prepareObjectsSliceReturnsCorrectPortionForObjectStorageAndFirstPage
‪prepareObjectsSliceReturnsCorrectPortionForObjectStorageAndFirstPage()
Definition: PaginateControllerTest.php:190
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest\$controller
‪TYPO3 CMS Fluid ViewHelpers Widget Controller PaginateController PHPUnit_Framework_MockObject_MockObject TYPO3 TestingFramework Core AccessibleObjectInterface $controller
Definition: PaginateControllerTest.php:30
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest\setUp
‪setUp()
Definition: PaginateControllerTest.php:51
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest\$query
‪TYPO3 CMS Extbase Persistence Generic Query $query
Definition: PaginateControllerTest.php:26
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest\$querySettings
‪TYPO3 CMS Extbase Persistence Generic QuerySettingsInterface $querySettings
Definition: PaginateControllerTest.php:34
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest\$dataMapper
‪TYPO3 CMS Extbase Persistence Generic Mapper DataMapper $dataMapper
Definition: PaginateControllerTest.php:46
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest\acceptQueryResultInterfaceAsObjects
‪acceptQueryResultInterfaceAsObjects()
Definition: PaginateControllerTest.php:152
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest\calculateDisplayRangeDeterminesCorrectDisplayRangeStartAndEndForOddMaximumNumberOfLinksWhenOnLastPage
‪calculateDisplayRangeDeterminesCorrectDisplayRangeStartAndEndForOddMaximumNumberOfLinksWhenOnLastPage()
Definition: PaginateControllerTest.php:139
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller\PaginateControllerTest
Definition: PaginateControllerTest.php:23