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