ILIAS  release_7 Revision v7.30-3-g800a261c036
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 }
85
86 public function testRenderUnlimited()
87 {
88 $p = $this->getFactory()->pagination()
89 ->withTotalEntries(2)
90 ->withPageSize(1);
91
92 //two entries, first one inactive
93 //browse-left disabled
94 $expected_html = <<<EOT
95<div class="il-viewcontrol-pagination">
96 <span class="browse previous">
97 <a class="glyph disabled" aria-label="back" aria-disabled="true">
98 <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
99 </a>
100 </span>
101
102 <button class="btn btn-link engaged" aria-pressed="true" data-action="?pagination_offset=0" id="id_1">1</button>
103 <button class="btn btn-link" data-action="?pagination_offset=1" id="id_2">2</button>
104
105 <span class="browse next">
106 <a class="glyph" href="?pagination_offset=1" aria-label="next">
107 <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
108 </a>
109 </span>
110</div>
111EOT;
112
113 $html = $this->getDefaultRenderer()->render($p);
114 $this->assertHTMLEquals($expected_html, $html);
115 }
116
118 {
119 $p = $this->getFactory()->pagination()
120 ->withTotalEntries(2)
121 ->withPageSize(1)
122 ->withCurrentPage(1);
123
124 //two entries, second one inactive
125 //browse-right disabled
126 $expected_html = <<<EOT
127<div class="il-viewcontrol-pagination">
128 <span class="browse previous">
129 <a class="glyph" href="?pagination_offset=0" aria-label="back">
130 <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
131 </a>
132 </span>
133
134 <button class="btn btn-link" data-action="?pagination_offset=0" id="id_1">1</button>
135 <button class="btn btn-link engaged" aria-pressed="true" data-action="?pagination_offset=1" id="id_2">2</button>
136
137 <span class="browse next">
138 <a class="glyph disabled" aria-label="next" aria-disabled="true">
139 <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
140 </a>
141 </span>
142</div>
143EOT;
144
145 $html = $this->getDefaultRenderer()->render($p);
146 $this->assertHTMLEquals($expected_html, $html);
147 }
148
149 public function testRenderLimited()
150 {
151 $p = $this->getFactory()->pagination()
152 ->withTotalEntries(3)
153 ->withPageSize(1)
154 ->withMaxPaginationButtons(1);
155
156 //one entry,
157 //browse-left disabled
158 //boundary-button right
159 $expected_html = <<<EOT
160<div class="il-viewcontrol-pagination">
161 <span class="browse previous">
162 <a class="glyph disabled" aria-label="back" aria-disabled="true">
163 <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
164 </a>
165 </span>
166
167 <button class="btn btn-link engaged" aria-pressed="true" data-action="?pagination_offset=0" id="id_1">1</button>
168
169 <span class="last">
170 <button class="btn btn-link" data-action="?pagination_offset=2" id="id_2">3</button>
171 </span>
172
173 <span class="browse next">
174 <a class="glyph" href="?pagination_offset=1" aria-label="next">
175 <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
176 </a>
177 </span>
178</div>
179EOT;
180 $html = $this->getDefaultRenderer()->render($p);
181 $this->assertHTMLEquals($expected_html, $html);
182 }
183
185 {
186 $p = $this->getFactory()->pagination()
187 ->withTotalEntries(3)
188 ->withPageSize(1)
189 ->withMaxPaginationButtons(1)
190 ->withCurrentPage(1);
191
192 //one entry,
193 //both rockers enabled
194 //both boundary-buttons
195 $expected_html = <<<EOT
196<div class="il-viewcontrol-pagination">
197 <span class="browse previous">
198 <a class="glyph" href="?pagination_offset=0" aria-label="back">
199 <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
200 </a>
201 </span>
202
203 <span class="first">
204 <button class="btn btn-link" data-action="?pagination_offset=0" id="id_2">1</button>
205 </span>
206
207 <button class="btn btn-link engaged" aria-pressed="true" data-action="?pagination_offset=1" id="id_1">2</button>
208
209 <span class="last">
210 <button class="btn btn-link" data-action="?pagination_offset=2" id="id_3">3</button>
211 </span>
212
213 <span class="browse next">
214 <a class="glyph" href="?pagination_offset=2" aria-label="next">
215 <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
216 </a>
217 </span>
218</div>
219EOT;
220 $html = $this->getDefaultRenderer()->render($p);
221 $this->assertHTMLEquals($expected_html, $html);
222 }
223
225 {
226 $p = $this->getFactory()->pagination()
227 ->withTotalEntries(3)
228 ->withPageSize(1)
229 ->withMaxPaginationButtons(1)
230 ->withCurrentPage(2);
231
232 //one entry,
233 //browse-right disabled
234 //boundary-button left only
235 $expected_html = <<<EOT
236<div class="il-viewcontrol-pagination">
237 <span class="browse previous">
238 <a class="glyph" href="?pagination_offset=1" aria-label="back">
239 <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
240 </a>
241 </span>
242 <span class="first">
243 <button class="btn btn-link" data-action="?pagination_offset=0" id="id_2">1</button>
244 </span>
245
246 <button class="btn btn-link engaged" aria-pressed="true" data-action="?pagination_offset=2" id="id_1">3</button>
247
248 <span class="browse next">
249 <a class="glyph disabled" aria-label="next" aria-disabled="true">
250 <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
251 </a>
252 </span>
253</div>
254EOT;
255 $html = $this->getDefaultRenderer()->render($p);
256 $this->assertHTMLEquals($expected_html, $html);
257 }
258
259
260
261 public function testRenderDropdown()
262 {
263 $p = $this->getFactory()->pagination()
264 ->withTotalEntries(3)
265 ->withPageSize(1)
266 ->withDropdownAt(1);
267
268 $expected_html = <<<EOT
269<div class="il-viewcontrol-pagination">
270 <span class="browse previous">
271 <a class="glyph disabled" aria-label="back" aria-disabled="true">
272 <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
273 </a>
274 </span>
275
276 <div class="dropdown">
277 <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>
278 <ul class="dropdown-menu">
279 <li><button class="btn btn-link engaged" aria-pressed="true" data-action="?pagination_offset=0" id="id_1">1</button></li>
280 <li><button class="btn btn-link" data-action="?pagination_offset=1" id="id_2">2</button></li>
281 <li><button class="btn btn-link" data-action="?pagination_offset=2" id="id_3">3</button></li>
282 </ul>
283 </div>
284
285 <span class="browse next">
286 <a class="glyph" href="?pagination_offset=1" aria-label="next">
287 <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
288 </a>
289 </span>
290</div>
291EOT;
292 $html = $this->getDefaultRenderer()->render($p);
293 $this->assertHTMLEquals($expected_html, $html);
294 }
295}
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:263
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:372
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
Test on Pagination view control.
testRenderLimitedWithCurrentPage2()
testRenderLimitedWithCurrentPage()
$factory
Definition: metadata.php:58