ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
PaginationTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once("vendor/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../Base.php");
23
28
33{
34 public function getUIFactory(): NoUIFactory
35 {
36 return new class () extends NoUIFactory {
37 public function symbol(): IC\Symbol\Factory
38 {
39 return new IC\Symbol\Factory(
40 new IC\Symbol\Icon\Factory(),
41 new IC\Symbol\Glyph\Factory(),
42 new IC\Symbol\Avatar\Factory()
43 );
44 }
45 public function button(): IC\Button\Factory
46 {
47 return new IC\Button\Factory();
48 }
49 public function dropdown(): IC\Dropdown\Factory
50 {
51 return new IC\Dropdown\Factory();
52 }
53 };
54 }
55
56 private function getFactory(): Factory
57 {
58 $sg = new SignalGenerator();
59 return new Factory($sg);
60 }
61
62 public function testConstruction(): void
63 {
64 $f = $this->getFactory();
65 $pagination = $f->pagination();
66 $this->assertInstanceOf("ILIAS\\UI\\Component\\ViewControl\\Pagination", $pagination);
67 $this->assertInstanceOf("ILIAS\\UI\\Component\\Signal", $pagination->getInternalSignal());
68 }
69
70 public function testAttributes(): void
71 {
72 $total_entries = 111;
73 $page_size = 100;
74 $current_page = 1;
75 //$select_signal;
76 $target_url = 'http://testurl';
77 $parameter_name = "param_name";
78 $max_page_options = 10;
79
80 $f = $this->getFactory();
81 $p = $f->pagination()
82 ->withTargetURL($target_url, $parameter_name)
83 ->withTotalEntries($total_entries)
84 ->withPageSize($page_size)
85 ->withCurrentPage($current_page)
86 ->withMaxPaginationButtons($max_page_options)
87 ;
88
89 $this->assertEquals($target_url, $p->getTargetURL());
90 $this->assertEquals($parameter_name, $p->getParameterName());
91 $this->assertEquals($page_size, $p->getPageSize());
92 $this->assertEquals($current_page, $p->getCurrentPage());
93 $this->assertEquals($max_page_options, $p->getMaxPaginationButtons());
94 $this->assertEquals(2, $p->getNumberOfPages());
95 }
96
98 {
99 $p = $this->getFactory()->pagination()
100 ->withTotalEntries(2)
101 ->withPageSize(1);
102
103 //two entries, first one inactive
104 //browse-left not rendered
105 $expected_html = <<<EOT
106<div class="il-viewcontrol-pagination l-bar__element">
107 <button class="btn btn-link engaged" aria-pressed="true" data-action="?pagination_offset=0" id="id_1">1</button>
108 <button class="btn btn-link" data-action="?pagination_offset=1" id="id_2">2</button>
109 <button class="btn btn-default" data-action="?pagination_offset=1" id="id_3">
110 <span class="glyph" aria-label="next" role="img"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span></span>
111 </button>
112</div>
113EOT;
114
115 $html = $this->getDefaultRenderer()->render($p);
116 $this->assertEquals($this->brutallyTrimHTML($expected_html), $this->brutallyTrimHTML($html));
117 }
118
119 public function testRenderWithCurrentPage(): void
120 {
121 $p = $this->getFactory()->pagination()
122 ->withTotalEntries(2)
123 ->withPageSize(1)
124 ->withCurrentPage(1);
125
126 //two entries, second one inactive
127 //browse-right not rendered
128 $expected_html = <<<EOT
129<div class="il-viewcontrol-pagination l-bar__element">
130 <button class="btn btn-default" data-action="?pagination_offset=0" id="id_3">
131 <span class="glyph" aria-label="back" role="img"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span></span>
132 </button>
133 <button class="btn btn-link" data-action="?pagination_offset=0" id="id_1">1</button>
134 <button class="btn btn-link engaged" aria-pressed="true" data-action="?pagination_offset=1" id="id_2">2</button>
135</div>
136EOT;
137
138 $html = $this->getDefaultRenderer()->render($p);
139 $this->assertHTMLEquals(
140 $this->brutallyTrimHTML($expected_html),
141 $this->brutallyTrimHTML($html)
142 );
143 }
144
145 public function testRenderLimited(): void
146 {
147 $p = $this->getFactory()->pagination()
148 ->withTotalEntries(3)
149 ->withPageSize(1)
150 ->withMaxPaginationButtons(1);
151
152 //one entry,
153 //browse-left not rendered
154 //boundary-button right
155 $expected_html = <<<EOT
156<div class="il-viewcontrol-pagination l-bar__element">
157 <button class="btn btn-link engaged" aria-pressed="true" data-action="?pagination_offset=0" id="id_1">1</button>
158 <span class="last"><button class="btn btn-link" data-action="?pagination_offset=2" id="id_2">3</button></span>
159 <button class="btn btn-default" data-action="?pagination_offset=1" id="id_3">
160 <span class="glyph" aria-label="next" role="img"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span></span>
161 </button>
162</div>
163EOT;
164 $html = $this->getDefaultRenderer()->render($p);
165 $this->assertEquals(
166 $this->brutallyTrimHTML($expected_html),
167 $this->brutallyTrimHTML($html)
168 );
169 }
170
171 public function testRenderLimitedWithCurrentPage(): void
172 {
173 $p = $this->getFactory()->pagination()
174 ->withTotalEntries(3)
175 ->withPageSize(1)
176 ->withMaxPaginationButtons(1)
177 ->withCurrentPage(1);
178
179 //one entry,
180 //both rockers enabled
181 //both boundary-buttons
182 $expected_html = <<<EOT
183<div class="il-viewcontrol-pagination l-bar__element">
184 <button class="btn btn-default" data-action="?pagination_offset=0" id="id_4">
185 <span class="glyph" aria-label="back" role="img"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span></span>
186 </button><span class="first"><button class="btn btn-link" data-action="?pagination_offset=0" id="id_2">1</button></span>
187 <button class="btn btn-link engaged" aria-pressed="true" data-action="?pagination_offset=1" id="id_1">2</button>
188 <span class="last"><button class="btn btn-link" data-action="?pagination_offset=2" id="id_3">3</button></span>
189 <button class="btn btn-default" data-action="?pagination_offset=2" id="id_5">
190 <span class="glyph" aria-label="next" role="img"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span></span>
191 </button>
192</div>
193EOT;
194 $html = $this->getDefaultRenderer()->render($p);
195 $this->assertHTMLEquals(
196 $this->brutallyTrimHTML($expected_html),
197 $this->brutallyTrimHTML($html)
198 );
199 }
200
201 public function testRenderLimitedWithCurrentPage2(): void
202 {
203 $p = $this->getFactory()->pagination()
204 ->withTotalEntries(3)
205 ->withPageSize(1)
206 ->withMaxPaginationButtons(1)
207 ->withCurrentPage(2);
208
209 //one entry,
210 //browse-right not rendered
211 //boundary-button left only
212 $expected_html = <<<EOT
213<div class="il-viewcontrol-pagination l-bar__element">
214 <button class="btn btn-default" data-action="?pagination_offset=1" id="id_3">
215 <span class="glyph" aria-label="back" role="img"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span></span>
216 </button>
217 <span class="first"><button class="btn btn-link" data-action="?pagination_offset=0" id="id_2">1</button></span>
218 <button class="btn btn-link engaged" aria-pressed="true" data-action="?pagination_offset=2" id="id_1">3</button>
219</div>
220EOT;
221 $html = $this->getDefaultRenderer()->render($p);
222 $this->assertEquals(
223 $this->brutallyTrimHTML($expected_html),
224 $this->brutallyTrimHTML($html)
225 );
226 }
227
228 public function testRenderDropdown(): void
229 {
230 $p = $this->getFactory()->pagination()
231 ->withTotalEntries(3)
232 ->withPageSize(1)
233 ->withDropdownAt(1);
234
235 $expected_html = <<<EOT
236<div class="il-viewcontrol-pagination l-bar__element">
237 <div class="dropdown" id="id_4">
238 <button class="btn btn-default dropdown-toggle" type="button" aria-haspopup="true" aria-expanded="false" aria-controls="id_4_menu">pagination_label_x_of_y<span class="caret"></span></button>
239 <ul id="id_4_menu" class="dropdown-menu">
240 <li>
241 <button class="btn btn-link engaged" aria-pressed="true" data-action="?pagination_offset=0" id="id_1">1</button>
242 </li>
243 <li>
244 <button class="btn btn-link" data-action="?pagination_offset=1" id="id_2">2</button>
245 </li>
246 <li>
247 <button class="btn btn-link" data-action="?pagination_offset=2" id="id_3">3</button>
248 </li>
249 </ul>
250 </div>
251 <button class="btn btn-default" data-action="?pagination_offset=1" id="id_5">
252 <span class="glyph" aria-label="next" role="img"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span></span>
253 </button>
254</div>
255EOT;
256 $html = $this->getDefaultRenderer()->render($p);
257 $this->assertEquals(
258 $this->brutallyTrimHTML($expected_html),
259 $this->brutallyTrimHTML($html)
260 );
261 }
262
263 public function testGetRangeOnNull(): void
264 {
265 $page_size = 0;
266 $current_page = 1;
267 $range = null;
268
269 $pagination = $this->getFactory()->pagination()
270 ->withCurrentPage($current_page)
271 ->withPageSize($page_size);
272
273 $this->assertNull($pagination->getRange());
274 $this->assertEquals($range, $pagination->getRange());
275 }
276
277 public function testRenderWithOnePageOnly(): void
278 {
279 $p = $this->getFactory()->pagination()
280 ->withTotalEntries(30)
281 ->withPageSize(30);
282 $expected_html = '';
283 $html = $this->getDefaultRenderer()->render($p);
284 $this->assertEquals($expected_html, $html);
285 }
286
287}
Provides common functionality for UI tests.
Definition: Base.php:337
Test on Pagination view control.
testRenderLimitedWithCurrentPage2()
testRenderLimitedWithCurrentPage()
testViewControlPaginationRenderUnlimited()
button(string $caption, string $cmd)