2 namespace TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\Widget\Controller;
57 $this->query = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Query::class, array(
'dummy'), array(
'someType'));
58 $this->querySettings = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface::class);
59 $this->query->_set(
'querySettings', $this->querySettings);
60 $this->persistenceManager = $this->getMock(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface::class);
61 $this->backend = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface::class);
62 $this->backend->expects($this->any())->method(
'getQomFactory')->will($this->returnValue(null));
63 $this->persistenceManager->expects($this->any())->method(
'getBackend')->will($this->returnValue($this->backend));
64 $this->query->_set(
'persistenceManager', $this->persistenceManager);
65 $this->dataMapper = $this->getMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper::class);
66 $this->query->_set(
'dataMapper', $this->dataMapper);
67 $this->controller = $this->getAccessibleMock(\TYPO3\CMS\
Fluid\ViewHelpers\Widget\Controller\PaginateController::class,
68 array(
'dummy'), array(),
'',
false);
69 $this->controller->_set(
'view', $this->getMock(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface::class));
77 $this->controller->_set(
'maximumNumberOfLinks', 8);
78 $this->controller->_set(
'numberOfPages', 100);
79 $this->controller->_set(
'currentPage', 50);
80 $this->controller->_call(
'calculateDisplayRange');
81 $this->assertSame(46, $this->controller->_get(
'displayRangeStart'));
82 $this->assertSame(53, $this->controller->_get(
'displayRangeEnd'));
90 $this->controller->_set(
'maximumNumberOfLinks', 7);
91 $this->controller->_set(
'numberOfPages', 100);
92 $this->controller->_set(
'currentPage', 50);
93 $this->controller->_call(
'calculateDisplayRange');
94 $this->assertSame(47, $this->controller->_get(
'displayRangeStart'));
95 $this->assertSame(53, $this->controller->_get(
'displayRangeEnd'));
103 $this->controller->_set(
'maximumNumberOfLinks', 8);
104 $this->controller->_set(
'numberOfPages', 100);
105 $this->controller->_set(
'currentPage', 1);
106 $this->controller->_call(
'calculateDisplayRange');
107 $this->assertSame(1, $this->controller->_get(
'displayRangeStart'));
108 $this->assertSame(8, $this->controller->_get(
'displayRangeEnd'));
116 $this->controller->_set(
'maximumNumberOfLinks', 7);
117 $this->controller->_set(
'numberOfPages', 100);
118 $this->controller->_set(
'currentPage', 1);
119 $this->controller->_call(
'calculateDisplayRange');
120 $this->assertSame(1, $this->controller->_get(
'displayRangeStart'));
121 $this->assertSame(7, $this->controller->_get(
'displayRangeEnd'));
129 $this->controller->_set(
'maximumNumberOfLinks', 8);
130 $this->controller->_set(
'numberOfPages', 100);
131 $this->controller->_set(
'currentPage', 100);
132 $this->controller->_call(
'calculateDisplayRange');
133 $this->assertSame(93, $this->controller->_get(
'displayRangeStart'));
134 $this->assertSame(100, $this->controller->_get(
'displayRangeEnd'));
142 $this->controller->_set(
'maximumNumberOfLinks', 7);
143 $this->controller->_set(
'numberOfPages', 100);
144 $this->controller->_set(
'currentPage', 100);
145 $this->controller->_call(
'calculateDisplayRange');
146 $this->assertSame(94, $this->controller->_get(
'displayRangeStart'));
147 $this->assertSame(100, $this->controller->_get(
'displayRangeEnd'));
155 $mockQueryResult = $this->getMock(\TYPO3\CMS\Extbase\Persistence\QueryResultInterface::class);
156 $mockQuery = $this->getMock(\TYPO3\CMS\Extbase\Persistence\QueryInterface::class);
157 $mockQueryResult->expects($this->any())->method(
'getQuery')->will($this->returnValue($mockQuery));
158 $this->controller->_set(
'objects', $mockQueryResult);
159 $this->controller->indexAction();
160 $this->assertSame($mockQueryResult, $this->controller->_get(
'objects'));
169 $this->controller->_set(
'objects', $objects);
170 $this->controller->indexAction();
171 $this->assertSame($objects, $this->controller->_get(
'objects'));
180 $this->controller->_set(
'objects', $objects);
181 $this->controller->indexAction();
182 $this->assertSame($objects, $this->controller->_get(
'objects'));
191 for ($i = 0; $i <= 25; $i++) {
192 $item = new \StdClass;
193 $objects->attach($item);
195 $this->controller->_set(
'objects', $objects);
196 $expectedPortion = array();
197 for ($j = 0; $j <= 9; $j++) {
198 $expectedPortion[] = $objects->toArray()[$j];
200 $this->assertSame($expectedPortion, $this->controller->_call(
'prepareObjectsSlice', 10, 0));
208 $this->controller->_set(
'currentPage', 2);
210 for ($i = 0; $i <= 55; $i++) {
211 $item = new \StdClass;
212 $objects->attach($item);
214 $this->controller->_set(
'objects', $objects);
215 $expectedPortion = array();
216 for ($j = 10; $j <= 19; $j++) {
217 $expectedPortion[] = $objects->toArray()[$j];
219 $this->assertSame($expectedPortion, $this->controller->_call(
'prepareObjectsSlice', 10, 10));
228 for ($i = 0; $i <= 25; $i++) {
229 $item = new \StdClass;
232 $this->controller->_set(
'objects', $objects);
233 $expectedPortion = array();
234 for ($j = 0; $j <= 9; $j++) {
235 $expectedPortion = array_slice($objects, 0, 10);
237 $this->assertSame($expectedPortion, $this->controller->_call(
'prepareObjectsSlice', 10, 0));
245 $this->controller->_set(
'currentPage', 2);
247 for ($i = 0; $i <= 55; $i++) {
248 $item = new \StdClass;
251 $this->controller->_set(
'objects', $objects);
252 $expectedPortion = array();
253 for ($j = 10; $j <= 19; $j++) {
254 $expectedPortion = array_slice($objects, 10, 10);
256 $this->assertSame($expectedPortion, $this->controller->_call(
'prepareObjectsSlice', 10, 10));