19 declare(strict_types=1);
30 require_once(
'ViewControlTestBase.php');
37 return $this->
buildRanges($total_count, $page_limit);
53 $vc = $this->buildVCFactory()->pagination();
55 $this->assertInstanceOf(Signal::class, $vc->getInternalSignal());
56 $this->assertIsArray($vc->getLimitOptions());
57 $this->assertEquals(
'', $vc->getLabelLimit());
62 $this->expectException(\Exception::class);
63 $vc = $this->buildVCFactory()->pagination()
64 ->withValue(
'notokvalue:-2');
71 $vc = $this->buildVCFactory()->pagination();
72 $this->assertEquals($o, $vc->withLimitOptions($o)->getLimitOptions($o));
86 'expected' => [25, 25]
91 'expected' => [50, 25]
101 'expected' => [95, 5]
110 'page_size' => PHP_INT_MAX,
111 'expected' => [0, PHP_INT_MAX]
121 'expected' => [10, 5]
136 Pagination::FNAME_OFFSET => $offset,
137 Pagination::FNAME_LIMIT => $page_size
139 $input = $this->createMock(InputData::class);
140 $input->expects($this->exactly(2))
143 $this->onConsecutiveCalls($v[Pagination::FNAME_OFFSET], $v[Pagination::FNAME_LIMIT])
146 $vc = $this->buildVCFactory()->pagination()
147 ->withNameFrom($this->getNamesource())
150 $df = $this->buildDataFactory();
152 $df->ok($df->range(...$expected)),
157 [Pagination::FNAME_OFFSET => $offset, Pagination::FNAME_LIMIT => $page_size],
164 $r = $this->getDefaultRenderer();
165 $vc = $this->buildVCFactory()->pagination()
166 ->withLimitOptions([2, 5, 10])
168 ->withValue([Pagination::FNAME_OFFSET => 12, Pagination::FNAME_LIMIT => 2])
171 $expected = $this->brutallyTrimHTML(
' 172 <div class="il-viewcontrol il-viewcontrol-pagination l-bar__element" id="id_13"> 173 <div class="dropdown il-viewcontrol-pagination__sectioncontrol"> 174 <button class="btn btn-link" id="id_8"> 175 <span class="glyph" aria-label="back" role="img"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span></span> 178 <button class="btn btn-link" id="id_1">1</button> 179 <span class="il-viewcontrol-pagination__spacer">...</span> 180 <button class="btn btn-link" id="id_2">5</button> 181 <button class="btn btn-link" id="id_3">6</button> 182 <button class="btn btn-link engaged" aria-pressed="true" id="id_4">7</button> 183 <button class="btn btn-link" id="id_5">8</button> 184 <button class="btn btn-link" id="id_6">9</button> 185 <span class="il-viewcontrol-pagination__spacer">...</span> 186 <button class="btn btn-link" id="id_7">21</button> 188 <button class="btn btn-link" id="id_9"> 189 <span class="glyph" aria-label="next" role="img"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span></span> 193 <div class="dropdown il-viewcontrol-pagination__num-of-items"> 194 <button class="btn btn-ctrl dropdown-toggle" type="button" data-toggle="dropdown" aria-label="label_pagination_limit" aria-haspopup="true" aria-expanded="false" aria-controls="id_13_ctrl_limit"> 195 <span class="caret"></span> 197 <ul id="id_13_ctrl_limit" class="dropdown-menu"> 198 <li class="selected"><button class="btn btn-link" id="id_10">2</button></li> 199 <li><button class="btn btn-link" id="id_11">5</button></li> 200 <li><button class="btn btn-link" id="id_12">10</button></li> 204 <div class="il-viewcontrol-value hidden" role="none"> 205 <input id="id_14" type="hidden" value="12" /> 206 <input id="id_15" type="hidden" value="2" /> 211 $html = $this->brutallyTrimHTML(
$r->render($vc));
212 $this->assertEquals($expected, $html);
219 $this->getTemplateFactory(),
221 $this->getJavaScriptBinding(),
224 $this->getHelpTextRetriever(),
231 $r = $this->getStubRenderer();
232 $ranges =
$r->mock_buildRanges($total = 8, $pagelimit = 3);
233 $this->assertEquals(3, count($ranges));
234 $ranges =
$r->mock_buildRanges(10, 5);
235 $this->assertEquals(2, count($ranges));
236 $ranges =
$r->mock_buildRanges(101, 5);
237 $this->assertEquals(21, count($ranges));
242 $r = $this->getStubRenderer();
243 $ranges =
$r->mock_buildRanges(20, 5);
244 $this->assertEquals(0,
$r->mock_findCurrentPage($ranges, 3));
245 $this->assertEquals(1,
$r->mock_findCurrentPage($ranges, 5));
246 $this->assertEquals(1,
$r->mock_findCurrentPage($ranges, 6));
247 $this->assertEquals(2,
$r->mock_findCurrentPage($ranges, 10));
248 $this->assertEquals(3,
$r->mock_findCurrentPage($ranges, 19));
253 $r = $this->getStubRenderer();
254 $ranges =
$r->mock_buildRanges(203, 5);
255 $slices =
$r->mock_sliceRangesToVisibleEntries($ranges, $current = 6, $visible_entries = 5);
256 $this->assertEquals(5, count($slices));
257 $this->assertEquals(0, $slices[0]->getStart());
258 $this->assertEquals(25, $slices[1]->getStart());
259 $this->assertEquals(30, $slices[2]->getStart());
260 $this->assertEquals(35, $slices[3]->getStart());
261 $this->assertEquals(200, $slices[4]->getStart());
266 $this->expectException(\LogicException::class);
267 $this->buildVCFactory()->pagination()->getOnChangeSignal();
getUIFactory()
Get a UI factory.