ILIAS  release_8 Revision v8.23
PaginationTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
21 require_once("libs/composer/vendor/autoload.php");
22 require_once(__DIR__ . "/../../Base.php");
23 
24 use ILIAS\UI\Component as C;
28 
33 {
34  public function getUIFactory(): NoUIFactory
35  {
36  return new class () extends NoUIFactory {
37  public function symbol(): C\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(): C\Button\Factory
46  {
47  return new IC\Button\Factory();
48  }
49  public function dropdown(): C\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 
97  public function testRenderUnlimited(): void
98  {
99  $p = $this->getFactory()->pagination()
100  ->withTotalEntries(2)
101  ->withPageSize(1);
102 
103  //two entries, first one inactive
104  //browse-left disabled
105  $expected_html = <<<EOT
106 <div class="il-viewcontrol-pagination">
107  <span class="browse previous">
108  <a class="glyph disabled" aria-label="back" aria-disabled="true">
109  <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
110  </a>
111  </span>
112 
113  <button class="btn btn-link engaged" aria-pressed="true" data-action="?pagination_offset=0" id="id_1">1</button>
114  <button class="btn btn-link" data-action="?pagination_offset=1" id="id_2">2</button>
115 
116  <span class="browse next">
117  <a tabindex="0" class="glyph" href="?pagination_offset=1" aria-label="next">
118  <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
119  </a>
120  </span>
121 </div>
122 EOT;
123 
124  $html = $this->getDefaultRenderer()->render($p);
125  $this->assertHTMLEquals($expected_html, $html);
126  }
127 
128  public function testRenderWithCurrentPage(): void
129  {
130  $p = $this->getFactory()->pagination()
131  ->withTotalEntries(2)
132  ->withPageSize(1)
133  ->withCurrentPage(1);
134 
135  //two entries, second one inactive
136  //browse-right disabled
137  $expected_html = <<<EOT
138 <div class="il-viewcontrol-pagination">
139  <span class="browse previous">
140  <a tabindex="0" class="glyph" href="?pagination_offset=0" aria-label="back">
141  <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
142  </a>
143  </span>
144 
145  <button class="btn btn-link" data-action="?pagination_offset=0" id="id_1">1</button>
146  <button class="btn btn-link engaged" aria-pressed="true" data-action="?pagination_offset=1" id="id_2">2</button>
147 
148  <span class="browse next">
149  <a class="glyph disabled" aria-label="next" aria-disabled="true">
150  <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
151  </a>
152  </span>
153 </div>
154 EOT;
155 
156  $html = $this->getDefaultRenderer()->render($p);
157  $this->assertHTMLEquals($expected_html, $html);
158  }
159 
160  public function testRenderLimited(): void
161  {
162  $p = $this->getFactory()->pagination()
163  ->withTotalEntries(3)
164  ->withPageSize(1)
165  ->withMaxPaginationButtons(1);
166 
167  //one entry,
168  //browse-left disabled
169  //boundary-button right
170  $expected_html = <<<EOT
171 <div class="il-viewcontrol-pagination">
172  <span class="browse previous">
173  <a class="glyph disabled" aria-label="back" aria-disabled="true">
174  <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
175  </a>
176  </span>
177 
178  <button class="btn btn-link engaged" aria-pressed="true" data-action="?pagination_offset=0" id="id_1">1</button>
179 
180  <span class="last">
181  <button class="btn btn-link" data-action="?pagination_offset=2" id="id_2">3</button>
182  </span>
183 
184  <span class="browse next">
185  <a tabindex="0" class="glyph" href="?pagination_offset=1" aria-label="next">
186  <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
187  </a>
188  </span>
189 </div>
190 EOT;
191  $html = $this->getDefaultRenderer()->render($p);
192  $this->assertHTMLEquals($expected_html, $html);
193  }
194 
195  public function testRenderLimitedWithCurrentPage(): void
196  {
197  $p = $this->getFactory()->pagination()
198  ->withTotalEntries(3)
199  ->withPageSize(1)
200  ->withMaxPaginationButtons(1)
201  ->withCurrentPage(1);
202 
203  //one entry,
204  //both rockers enabled
205  //both boundary-buttons
206  $expected_html = <<<EOT
207 <div class="il-viewcontrol-pagination">
208  <span class="browse previous">
209  <a tabindex="0" class="glyph" href="?pagination_offset=0" aria-label="back">
210  <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
211  </a>
212  </span>
213 
214  <span class="first">
215  <button class="btn btn-link" data-action="?pagination_offset=0" id="id_2">1</button>
216  </span>
217 
218  <button class="btn btn-link engaged" aria-pressed="true" data-action="?pagination_offset=1" id="id_1">2</button>
219 
220  <span class="last">
221  <button class="btn btn-link" data-action="?pagination_offset=2" id="id_3">3</button>
222  </span>
223 
224  <span class="browse next">
225  <a tabindex="0" class="glyph" href="?pagination_offset=2" aria-label="next">
226  <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
227  </a>
228  </span>
229 </div>
230 EOT;
231  $html = $this->getDefaultRenderer()->render($p);
232  $this->assertHTMLEquals($expected_html, $html);
233  }
234 
235  public function testRenderLimitedWithCurrentPage2(): void
236  {
237  $p = $this->getFactory()->pagination()
238  ->withTotalEntries(3)
239  ->withPageSize(1)
240  ->withMaxPaginationButtons(1)
241  ->withCurrentPage(2);
242 
243  //one entry,
244  //browse-right disabled
245  //boundary-button left only
246  $expected_html = <<<EOT
247 <div class="il-viewcontrol-pagination">
248  <span class="browse previous">
249  <a tabindex="0" class="glyph" href="?pagination_offset=1" aria-label="back">
250  <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
251  </a>
252  </span>
253  <span class="first">
254  <button class="btn btn-link" data-action="?pagination_offset=0" id="id_2">1</button>
255  </span>
256 
257  <button class="btn btn-link engaged" aria-pressed="true" data-action="?pagination_offset=2" id="id_1">3</button>
258 
259  <span class="browse next">
260  <a class="glyph disabled" aria-label="next" aria-disabled="true">
261  <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
262  </a>
263  </span>
264 </div>
265 EOT;
266  $html = $this->getDefaultRenderer()->render($p);
267  $this->assertHTMLEquals($expected_html, $html);
268  }
269 
270 
271 
272  public function testRenderDropdown(): void
273  {
274  $p = $this->getFactory()->pagination()
275  ->withTotalEntries(3)
276  ->withPageSize(1)
277  ->withDropdownAt(1);
278 
279  $expected_html = <<<EOT
280 <div class="il-viewcontrol-pagination">
281  <span class="browse previous">
282  <a class="glyph disabled" aria-label="back" aria-disabled="true">
283  <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
284  </a>
285  </span>
286 
287  <div class="dropdown">
288  <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" id="id_4" aria-haspopup="true" aria-expanded="false" aria-controls="id_4_menu" >pagination_label_x_of_y <span class="caret"></span></button>
289  <ul id="id_4_menu" class="dropdown-menu">
290  <li><button class="btn btn-link engaged" aria-pressed="true" data-action="?pagination_offset=0" id="id_1">1</button></li>
291  <li><button class="btn btn-link" data-action="?pagination_offset=1" id="id_2">2</button></li>
292  <li><button class="btn btn-link" data-action="?pagination_offset=2" id="id_3">3</button></li>
293  </ul>
294  </div>
295 
296  <span class="browse next">
297  <a tabindex="0" class="glyph" href="?pagination_offset=1" aria-label="next">
298  <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
299  </a>
300  </span>
301 </div>
302 EOT;
303  $html = $this->getDefaultRenderer()->render($p);
304  $this->assertHTMLEquals($expected_html, $html);
305  }
306 
307  public function testGetRangeOnNull(): void
308  {
309  $page_size = 0;
310  $current_page = 1;
311  $range = null;
312 
313  $pagination = $this->getFactory()->pagination()
314  ->withCurrentPage($current_page)
315  ->withPageSize($page_size);
316 
317  $this->assertNull($pagination->getRange());
318  $this->assertEquals($range, $pagination->getRange());
319  }
320 }
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testRenderLimitedWithCurrentPage2()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testRenderLimitedWithCurrentPage()
Test on Pagination view control.
assertHTMLEquals(string $expected_html_as_string, string $html_as_string)
Definition: Base.php:427
Provides common functionality for UI tests.
Definition: Base.php:298
disabled()
Example showing how to plug a disabled checkbox into a form.
Definition: disabled.php:10