ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
PaginationTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2017 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
3
4require_once("libs/composer/vendor/autoload.php");
5require_once(__DIR__ . "/../../Base.php");
6
7use \ILIAS\UI\Component as C;
8use \ILIAS\UI\Implementation\Component as IC;
10
15{
16 public function getUIFactory()
17 {
18 $factory = new class extends NoUIFactory {
19 public function symbol() : C\Symbol\Factory
20 {
21 return new IC\Symbol\Factory(
22 new IC\Symbol\Icon\Factory(),
23 new IC\Symbol\Glyph\Factory(),
24 new IC\Symbol\Avatar\Factory()
25 );
26 }
27 public function button()
28 {
29 return new IC\Button\Factory(new SignalGenerator());
30 }
31 public function dropdown()
32 {
33 return new IC\Dropdown\Factory();
34 }
35 };
36 return $factory;
37 }
38
39 private function getFactory()
40 {
41 $sg = new SignalGenerator();
42 return new \ILIAS\UI\Implementation\Component\ViewControl\Factory($sg);
43 }
44
45 public function testConstruction()
46 {
47 $f = $this->getFactory();
48 $pagination = $f->pagination();
49 $this->assertInstanceOf(
50 "ILIAS\\UI\\Component\\ViewControl\\Pagination",
51 $pagination
52 );
53 $this->assertInstanceOf(
54 "ILIAS\\UI\\Component\\Signal",
55 $pagination->getInternalSignal()
56 );
57 }
58
59 public function testAttributes()
60 {
61 $total_entries = 111;
62 $page_size = 100;
63 $current_page = 1;
64 //$select_signal;
65 $target_url = 'http://testurl';
66 $parameter_name = "param_name";
67 $max_page_options = 10;
68
69 $f = $this->getFactory();
70 $p = $f->pagination()
71 ->withTargetURL($target_url, $parameter_name)
72 ->withTotalEntries($total_entries)
73 ->withPageSize($page_size)
74 ->withCurrentPage($current_page)
75 ->withMaxPaginationButtons($max_page_options)
76 ;
77
78 $this->assertEquals($target_url, $p->getTargetURL());
79 $this->assertEquals($parameter_name, $p->getParameterName());
80 $this->assertEquals($page_size, $p->getPageSize());
81 $this->assertEquals($current_page, $p->getCurrentPage());
82 $this->assertEquals($max_page_options, $p->getMaxPaginationButtons());
83 $this->assertEquals(2, $p->getNumberOfPages());
84 $this->assertEquals(11, $p->getPageLength());
85 }
86
87 public function testRenderUnlimited()
88 {
89 $p = $this->getFactory()->pagination()
90 ->withTotalEntries(2)
91 ->withPageSize(1);
92
93 //two entries, first one inactive
94 //browse-left disabled
95 $expected_html = <<<EOT
96<div class="il-viewcontrol-pagination">
97 <span class="browse previous">
98 <a class="glyph disabled" aria-label="back" aria-disabled="true">
99 <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
100 </a>
101 </span>
102
103 <button class="btn btn-link" data-action="?pagination_offset=0" disabled="true">1</button>
104 <button class="btn btn-link" data-action="?pagination_offset=1" id="id_1">2</button>
105
106 <span class="browse next">
107 <a class="glyph" href="?pagination_offset=1" aria-label="next">
108 <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
109 </a>
110 </span>
111</div>
112EOT;
113
114 $html = $this->getDefaultRenderer()->render($p);
115 $this->assertHTMLEquals($expected_html, $html);
116 }
117
119 {
120 $p = $this->getFactory()->pagination()
121 ->withTotalEntries(2)
122 ->withPageSize(1)
123 ->withCurrentPage(1);
124
125 //two entries, second one inactive
126 //browse-right disabled
127 $expected_html = <<<EOT
128<div class="il-viewcontrol-pagination">
129 <span class="browse previous">
130 <a class="glyph" href="?pagination_offset=0" aria-label="back">
131 <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
132 </a>
133 </span>
134
135 <button class="btn btn-link" data-action="?pagination_offset=0" id="id_1">1</button>
136 <button class="btn btn-link" data-action="?pagination_offset=1" disabled="true">2</button>
137
138 <span class="browse next">
139 <a class="glyph disabled" aria-label="next" aria-disabled="true">
140 <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
141 </a>
142 </span>
143</div>
144EOT;
145
146 $html = $this->getDefaultRenderer()->render($p);
147 $this->assertHTMLEquals($expected_html, $html);
148 }
149
150 public function testRenderLimited()
151 {
152 $p = $this->getFactory()->pagination()
153 ->withTotalEntries(3)
154 ->withPageSize(1)
155 ->withMaxPaginationButtons(1);
156
157 //one entry,
158 //browse-left disabled
159 //boundary-button right
160 $expected_html = <<<EOT
161<div class="il-viewcontrol-pagination">
162 <span class="browse previous">
163 <a class="glyph disabled" aria-label="back" aria-disabled="true">
164 <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
165 </a>
166 </span>
167
168 <button class="btn btn-link" data-action="?pagination_offset=0" disabled="true">1</button>
169
170 <span class="last">
171 <button class="btn btn-link" data-action="?pagination_offset=2" id="id_1">3</button>
172 </span>
173
174 <span class="browse next">
175 <a class="glyph" href="?pagination_offset=1" aria-label="next">
176 <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
177 </a>
178 </span>
179</div>
180EOT;
181 $html = $this->getDefaultRenderer()->render($p);
182 $this->assertHTMLEquals($expected_html, $html);
183 }
184
186 {
187 $p = $this->getFactory()->pagination()
188 ->withTotalEntries(3)
189 ->withPageSize(1)
190 ->withMaxPaginationButtons(1)
191 ->withCurrentPage(1);
192
193 //one entry,
194 //both rockers enabled
195 //both boundary-buttons
196 $expected_html = <<<EOT
197<div class="il-viewcontrol-pagination">
198 <span class="browse previous">
199 <a class="glyph" href="?pagination_offset=0" aria-label="back">
200 <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
201 </a>
202 </span>
203
204 <span class="first">
205 <button class="btn btn-link" data-action="?pagination_offset=0" id="id_1">1</button>
206 </span>
207
208 <button class="btn btn-link" data-action="?pagination_offset=1" disabled="true">2</button>
209
210 <span class="last">
211 <button class="btn btn-link" data-action="?pagination_offset=2" id="id_2">3</button>
212 </span>
213
214 <span class="browse next">
215 <a class="glyph" href="?pagination_offset=2" aria-label="next">
216 <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
217 </a>
218 </span>
219</div>
220EOT;
221 $html = $this->getDefaultRenderer()->render($p);
222 $this->assertHTMLEquals($expected_html, $html);
223 }
224
226 {
227 $p = $this->getFactory()->pagination()
228 ->withTotalEntries(3)
229 ->withPageSize(1)
230 ->withMaxPaginationButtons(1)
231 ->withCurrentPage(2);
232
233 //one entry,
234 //browse-right disabled
235 //boundary-button left only
236 $expected_html = <<<EOT
237<div class="il-viewcontrol-pagination">
238 <span class="browse previous">
239 <a class="glyph" href="?pagination_offset=1" aria-label="back">
240 <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
241 </a>
242 </span>
243 <span class="first">
244 <button class="btn btn-link" data-action="?pagination_offset=0" id="id_1">1</button>
245 </span>
246
247 <button class="btn btn-link" data-action="?pagination_offset=2" disabled="disabled">3</button>
248
249 <span class="browse next">
250 <a class="glyph disabled" aria-label="next" aria-disabled="true">
251 <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
252 </a>
253 </span>
254</div>
255EOT;
256 $html = $this->getDefaultRenderer()->render($p);
257 $this->assertHTMLEquals($expected_html, $html);
258 }
259
260
261
262 public function testRenderDropdown()
263 {
264 $p = $this->getFactory()->pagination()
265 ->withTotalEntries(3)
266 ->withPageSize(1)
267 ->withDropdownAt(1);
268
269 $expected_html = <<<EOT
270<div class="il-viewcontrol-pagination">
271 <span class="browse previous">
272 <a class="glyph disabled" aria-label="back" aria-disabled="true">
273 <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
274 </a>
275 </span>
276
277 <div class="dropdown">
278 <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">pagination_label_x_of_y <span class="caret"></span></button>
279 <ul class="dropdown-menu">
280 <li><button class="btn btn-link" data-action="?pagination_offset=0" disabled="disabled">1</button></li>
281 <li><button class="btn btn-link" data-action="?pagination_offset=1" id="id_1">2</button></li>
282 <li><button class="btn btn-link" data-action="?pagination_offset=2" id="id_2">3</button></li>
283 </ul>
284 </div>
285
286 <span class="browse next">
287 <a class="glyph" href="?pagination_offset=1" aria-label="next">
288 <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
289 </a>
290 </span>
291</div>
292EOT;
293 $html = $this->getDefaultRenderer()->render($p);
294 $this->assertHTMLEquals($expected_html, $html);
295 }
296}
disabled()
Example showing how to plug a disabled checkbox into a form.
Definition: disabled.php:5
An exception for terminatinating execution or to throw for unit testing.
Provides common functionality for UI tests.
Definition: Base.php:225
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:326
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:268
Test on Pagination view control.
testRenderLimitedWithCurrentPage2()
testRenderLimitedWithCurrentPage()
$factory
Definition: metadata.php:58