17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
57 protected function setUp()
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,
74 $this->controller->_set(
'view', $this->createMock(\
TYPO3\CMS\
Extbase\Mvc\View\ViewInterface::class));
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'));
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'));
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'));
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'));
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'));
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'));
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'));
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'));
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'));
199 for ($i = 0; $i <= 25; $i++) {
200 $item = new \stdClass;
201 $objects->attach($item);
203 $this->controller->_set(
'objects', $objects);
204 $expectedPortion = [];
205 for ($j = 0; $j <= 9; $j++) {
206 $expectedPortion[] = $objects->toArray()[$j];
208 $this->assertSame($expectedPortion, $this->controller->_call(
'prepareObjectsSlice', 10, 0));
216 $this->controller->_set(
'currentPage', 2);
218 for ($i = 0; $i <= 55; $i++) {
219 $item = new \stdClass;
220 $objects->attach($item);
222 $this->controller->_set(
'objects', $objects);
223 $expectedPortion = [];
224 for ($j = 10; $j <= 19; $j++) {
225 $expectedPortion[] = $objects->toArray()[$j];
227 $this->assertSame($expectedPortion, $this->controller->_call(
'prepareObjectsSlice', 10, 10));
235 $this->controller->_set(
'currentPage', 3);
237 for ($i = 0; $i <= 25; $i++) {
238 $item = new \stdClass;
239 $objects->attach($item);
241 $this->controller->_set(
'objects', $objects);
242 $expectedPortion = [];
243 for ($j = 20; $j <= 25; $j++) {
244 $expectedPortion[] = $objects->toArray()[$j];
246 $this->assertSame($expectedPortion, $this->controller->_call(
'prepareObjectsSlice', 10, 20));
255 for ($i = 0; $i <= 25; $i++) {
256 $item = new \stdClass;
259 $this->controller->_set(
'objects', $objects);
260 $expectedPortion = [];
261 for ($j = 0; $j <= 9; $j++) {
262 $expectedPortion = array_slice($objects, 0, 10);
264 $this->assertSame($expectedPortion, $this->controller->_call(
'prepareObjectsSlice', 10, 0));
272 $this->controller->_set(
'currentPage', 2);
274 for ($i = 0; $i <= 55; $i++) {
275 $item = new \stdClass;
278 $this->controller->_set(
'objects', $objects);
279 $expectedPortion = [];
280 for ($j = 10; $j <= 19; $j++) {
281 $expectedPortion = array_slice($objects, 10, 10);
283 $this->assertSame($expectedPortion, $this->controller->_call(
'prepareObjectsSlice', 10, 10));