ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
DataRendererTest Class Reference

Tests for the Renderer of DataTables. More...

+ Inheritance diagram for DataRendererTest:
+ Collaboration diagram for DataRendererTest:

Public Member Functions

 testDataTableGetMultiActionHandler ()
 
 testDataTableGetActionRegistration ()
 
 testDataTableMultiActionsDropdown ()
 
 testDataTableSingleActionsDropdown ()
 
 testDataTableRenderTableHeader ()
 
 testDataTableRenderHeaderWithoutSortableColums ()
 
 testDataTableRenderHeaderWithActions ()
 
 testDataTableRowBuilder ()
 
 testDataTableDataRowFromBuilder (array $params)
 testDataTableRowBuilder More...
 
 testDataTableRenderStandardRow (I\Table\DataRow $row)
 testDataTableDataRowFromBuilder More...
 
 testRenderEmptyDataCell ()
 
- Public Member Functions inherited from TableRendererTestBase
 getDataFactory ()
 
 getUIFactory ()
 

Private Member Functions

 getRenderer ()
 

Additional Inherited Members

- Protected Member Functions inherited from TableRendererTestBase
 getActionFactory ()
 
 getColumnFactory ()
 
 getDummyRequest ()
 
- Protected Member Functions inherited from TableTestBase
 buildFieldFactory ()
 
 buildRefinery ()
 
 getViewControlFactory ()
 
 getViewControlContainerFactory ()
 
 getTableFactory ()
 
 getMockStorage ()
 

Detailed Description

Tests for the Renderer of DataTables.

Definition at line 77 of file DataRendererTest.php.

Member Function Documentation

◆ getRenderer()

DataRendererTest::getRenderer ( )
private

Definition at line 79 of file DataRendererTest.php.

References getLanguage().

80  {
81  return new DTRenderer(
82  $this->getUIFactory(),
83  $this->getTemplateFactory(),
84  $this->getLanguage(),
85  $this->getJavaScriptBinding(),
86  new ilImagePathResolver(),
87  new \ILIAS\Data\Factory(),
88  new \ILIAS\UI\Help\TextRetriever\Echoing(),
89  $this->getUploadLimitResolver()
90  );
91  }
Interface Observer Contains several chained tasks and infos about them.
getLanguage()
wrapper around the renderer to expose protected functions
Builds data types.
Definition: Factory.php:35
+ Here is the call graph for this function:

◆ testDataTableDataRowFromBuilder()

DataRendererTest::testDataTableDataRowFromBuilder ( array  $params)

testDataTableRowBuilder

Definition at line 400 of file DataRendererTest.php.

References $params.

400  : I\Table\DataRow
401  {
402  list($rb, $columns, $actions) = $params;
403  $record = [
404  'f1' => 'v1',
405  'f2' => 'v2',
406  'f3' => 3
407  ];
408  $row = $rb->buildDataRow('row_id-1', $record);
409 
410  $this->assertEquals(
411  $columns,
412  $row->getColumns()
413  );
414  $this->assertEquals(
415  $actions,
416  $row->getActions()
417  );
418  $this->assertEquals(
419  $record['f2'],
420  $row->getCellContent('f2')
421  );
422 
423  return $row;
424  }
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31

◆ testDataTableGetActionRegistration()

DataRendererTest::testDataTableGetActionRegistration ( )

Definition at line 108 of file DataRendererTest.php.

References Vendor\Package\$f, $renderer, $token, $url, and ILIAS\UI\Implementation\Component\Input\getDataFactory().

109  {
110  $renderer = $this->getRenderer();
111  $f = $this->getActionFactory();
112  $url = $this->getDataFactory()->uri('http://wwww.ilias.de?ref_id=1');
113  $url_builder = new URLBuilder($url);
114  list($builder, $token) = $url_builder->acquireParameter(['namespace'], 'param');
115 
116  $action = $f->standard('label', $builder, $token);
117  $closure = $renderer->p_getActionRegistration('action_id', $action);
118 
119  $actual = $this->brutallyTrimHTML($closure('component_id'));
120  $url = $url->__toString();
121  $expected = $this->brutallyTrimHTML(
122  'il.UI.table.data.get(\'component_id\').registerAction(\'action_id\', false, new il.UI.core.URLBuilder(new URL("http://wwww.ilias.de?ref_id=1&namespace_param="), new Map([["namespace_param",new il.UI.core.URLBuilderToken(["namespace"], "param",'
123  );
124  $this->assertStringStartsWith($expected, $actual);
125  }
$renderer
$url
Definition: shib_logout.php:63
$token
Definition: xapitoken.php:67
URLBuilder.
Definition: URLBuilder.php:39
+ Here is the call graph for this function:

◆ testDataTableGetMultiActionHandler()

DataRendererTest::testDataTableGetMultiActionHandler ( )

Definition at line 93 of file DataRendererTest.php.

References $renderer.

94  {
95  $renderer = $this->getRenderer();
96  $signal = new I\Signal('signal_id');
97  $closure = $renderer->p_getMultiActionHandler($signal);
98  $actual = $this->brutallyTrimHTML($closure('component_id'));
99  $expected = $this->brutallyTrimHTML(
100  "$(document).on('signal_id', function(event, signal_data) {
101  il.UI.table.data.get('component_id').doMultiAction(signal_data);
102  return false;
103  });"
104  );
105  $this->assertEquals($expected, $actual);
106  }
$renderer

◆ testDataTableMultiActionsDropdown()

DataRendererTest::testDataTableMultiActionsDropdown ( )

Definition at line 127 of file DataRendererTest.php.

References Vendor\Package\$f, $renderer, $token, $url, and ILIAS\UI\Implementation\Component\Input\getDataFactory().

128  {
129  $renderer = $this->getRenderer();
130  $f = $this->getActionFactory();
131  $signal1 = new I\Signal('signal_id');
132  $signal2 = new I\Signal('signal_id2');
133  $url = $this->getDataFactory()->uri('http://wwww.ilias.de?ref_id=1');
134  $url_builder = new URLBuilder($url);
135  list($builder, $token) = $url_builder->acquireParameter(['namespace'], 'param');
136  $actions = [
137  $f->standard('label1', $builder, $token),
138  $f->standard('label2', $builder, $token)
139  ];
140  $this->assertNull(
141  $renderer->p_buildMultiActionsDropdown([], $signal1, $signal2)
142  );
143  $this->assertEquals(
144  4, //2 actions, 1 divider, one all-action
145  count($renderer->p_buildMultiActionsDropdown($actions, $signal1, $signal2)->getItems())
146  );
147  }
$renderer
$url
Definition: shib_logout.php:63
$token
Definition: xapitoken.php:67
URLBuilder.
Definition: URLBuilder.php:39
+ Here is the call graph for this function:

◆ testDataTableRenderHeaderWithActions()

DataRendererTest::testDataTableRenderHeaderWithActions ( )

Definition at line 321 of file DataRendererTest.php.

References $data, Vendor\Package\$f, ILIAS\UI\Implementation\Component\Table\$range, $renderer, $token, and $url.

321  : void
322  {
323  $renderer = $this->getRenderer();
324  $data_factory = new \ILIAS\Data\Factory();
325  $tpl = $this->getTemplateFactory()->getTemplate("components/ILIAS/UI/src/templates/default/Table/tpl.datatable.html", true, true);
326  $f = $this->getColumnFactory();
327 
328  $url = $data_factory->uri('http://wwww.ilias.de?ref_id=1');
329  $url_builder = new URLBuilder($url);
330  list($builder, $token) = $url_builder->acquireParameter(['namespace'], 'param');
331  $actions = [
332  'a2' => $this->getActionFactory()->standard('some action', $builder, $token)
333  ];
334 
335  $data = new class () implements ILIAS\UI\Component\Table\DataRetrieval {
336  public function getRows(
337  Component\Table\DataRowBuilder $row_builder,
338  array $visible_column_ids,
339  Data\Range $range,
340  Data\Order $order,
341  ?array $filter_data,
342  ?array $additional_parameters
343  ): \Generator {
344  yield $row_builder->buldDataRow('', []);
345  }
346  public function getTotalRowCount(
347  ?array $filter_data,
348  ?array $additional_parameters
349  ): ?int {
350  return null;
351  }
352  };
353  $columns = [
354  'f1' => $f->text("Field 1")->withIsSortable(false),
355  ];
356 
357  $sortation_signal = null;
358 
359  $table = $this->getUIFactory()->table()->data('', $columns, $data)
360  ->withActions($actions)
361  ->withRequest($this->getDummyRequest());
362  $renderer->p_renderActionsHeader($this->getDefaultRenderer(), $table, $tpl);
363  $actual = $this->brutallyTrimHTML($tpl->get());
364 
365  $expected = '<th class="c-table-data__header c-table-data__cell c-table-data__header__rowaction" aria-colindex="2">actions</th>';
366  $this->assertStringContainsString($expected, $actual);
367  }
$renderer
Interface Observer Contains several chained tasks and infos about them.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$url
Definition: shib_logout.php:63
Both the subject and the direction need to be specified when expressing an order. ...
Definition: Order.php:12
$token
Definition: xapitoken.php:67
URLBuilder.
Definition: URLBuilder.php:39
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:28

◆ testDataTableRenderHeaderWithoutSortableColums()

DataRendererTest::testDataTableRenderHeaderWithoutSortableColums ( )

Definition at line 248 of file DataRendererTest.php.

References $data, Vendor\Package\$f, ILIAS\UI\Implementation\Component\Table\$range, $renderer, ILIAS\Repository\button(), and ILIAS\Repository\form().

248  : void
249  {
250  $renderer = $this->getRenderer();
251  $data_factory = new \ILIAS\Data\Factory();
252  $tpl = $this->getTemplateFactory()->getTemplate("components/ILIAS/UI/src/templates/default/Table/tpl.datatable.html", true, true);
253  $f = $this->getColumnFactory();
254  $data = new class () implements ILIAS\UI\Component\Table\DataRetrieval {
255  public function getRows(
256  Component\Table\DataRowBuilder $row_builder,
257  array $visible_column_ids,
258  Data\Range $range,
259  Data\Order $order,
260  ?array $filter_data,
261  ?array $additional_parameters
262  ): \Generator {
263  yield $row_builder->buldDataRow('', []);
264  }
265  public function getTotalRowCount(
266  ?array $filter_data,
267  ?array $additional_parameters
268  ): ?int {
269  return null;
270  }
271  };
272  $columns = [
273  'f1' => $f->text("Field 1")->withIsSortable(false),
274  'f2' => $f->text("Field 2")->withIsSortable(false)
275  ];
276 
277  $sortation_signal = null;
278 
279  $table = $this->getUIFactory()->table()->data('', $columns, $data)
280  ->withRequest($this->getDummyRequest());
281  $renderer->p_renderTableHeader($this->getDefaultRenderer(), $table, $tpl, $sortation_signal);
282  $actual = $this->brutallyTrimHTML($tpl->get());
283  $expected = <<<EOT
284 <div class="c-table-data" id="{ID}">
285  <div class="viewcontrols">{VIEW_CONTROLS}</div>
286  <div class="c-table-data__table-wrapper">
287  <table class="c-table-data__table" aria-labelledby="{ID}_label" aria-colcount="{COL_COUNT}" role="grid">
288  <thead>
289  <tr class="c-table-data__header c-table-data__row">
290  <th class="c-table-data__header c-table-data__cell c-table-data__cell--text" tabindex="-1" aria-colindex="1">
291  <div class="c-table-data__header__resize-wrapper">Field 1</div>
292  </th>
293  <th class="c-table-data__header c-table-data__cell c-table-data__cell--text" tabindex="-1" aria-colindex="2">
294  <div class="c-table-data__header__resize-wrapper">Field 2</div>
295  </th>
296  </tr>
297  </thead>
298  <tbody class="c-table-data__body"></tbody>
299  </table>
300  </div>
301  <div class="c-table-data__async_modal_container"></div>
302  <dialog class="c-table-data__async_message c-modal" id="{ID}_msgmodal">
303  <div class="modal-dialog" role="document">
304  <div class="modal-content">
305  <div class="modal-header">
306  <form>
307  <button formmethod="dialog" class="close" aria-label="close">
308  <span aria-hidden="true">&times;</span></button>
309  </form>
310  </div>
311  <div class="c-table-data__async_messageresponse modal-body"></div>
312  </div>
313  </div>
314  </dialog>
315 </div>
316 EOT;
317  $expected = $this->brutallyTrimHTML($expected);
318  $this->assertEquals($expected, $actual);
319  }
button(string $caption, string $cmd)
$renderer
Interface Observer Contains several chained tasks and infos about them.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Both the subject and the direction need to be specified when expressing an order. ...
Definition: Order.php:12
form( $class_path, string $cmd, string $submit_caption="")
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:28
+ Here is the call graph for this function:

◆ testDataTableRenderStandardRow()

DataRendererTest::testDataTableRenderStandardRow ( I\Table\DataRow  $row)

testDataTableDataRowFromBuilder

Definition at line 429 of file DataRendererTest.php.

References ILIAS\Repository\button().

430  {
431  $actual = $this->brutallyTrimHTML($this->getDefaultRenderer()->render($row));
432  $expected = <<<EOT
433 <td class="c-table-data__cell c-table-data__rowselection" tabindex="-1">
434  <input type="checkbox" value="row_id-1" class="c-table-data__row-selector"></td>
435 <td class="c-table-data__cell c-table-data__cell--text " tabindex="-1"><span class="c-table-data__cell__col-title">Field 1:</span>v1
436 </td>
437 <td class="c-table-data__cell c-table-data__cell--text " tabindex="-1"><span class="c-table-data__cell__col-title">Field 2:</span>v2
438 </td>
439 <td class="c-table-data__cell c-table-data__cell--number " tabindex="-1"><span class="c-table-data__cell__col-title">Field 3:</span>3
440 </td>
441 <td class="c-table-data__cell c-table-data__rowaction" tabindex="-1">
442  <div class="dropdown" id="id_3">
443  <button class="btn btn-default dropdown-toggle" type="button" aria-label="actions" aria-haspopup="true" aria-expanded="false" aria-controls="id_3_menu">
444  <span class="caret"></span></button>
445  <ul id="id_3_menu" class="dropdown-menu">
446  <li>
447  <button class="btn btn-link" data-action="http://wwww.ilias.de?ref_id=1&namespace_param%5B%5D=row_id-1" id="id_1">label1</button>
448  </li>
449  <li>
450  <button class="btn btn-link" data-action="http://wwww.ilias.de?ref_id=1&namespace_param%5B%5D=row_id-1" id="id_2">label2</button>
451  </li>
452  </ul>
453  </div>
454 </td>
455 
456 EOT;
457  $expected = $this->brutallyTrimHTML($expected);
458  $this->assertEquals($expected, $actual);
459  }
button(string $caption, string $cmd)
+ Here is the call graph for this function:

◆ testDataTableRenderTableHeader()

DataRendererTest::testDataTableRenderTableHeader ( )

Definition at line 165 of file DataRendererTest.php.

References $data, Vendor\Package\$f, ILIAS\UI\Implementation\Component\Table\$range, $renderer, ILIAS\Repository\button(), ILIAS\Repository\form(), and ILIAS\UI\examples\Symbol\Glyph\Sort\sort().

166  {
167  $renderer = $this->getRenderer();
168  $data_factory = new \ILIAS\Data\Factory();
169  $tpl = $this->getTemplateFactory()->getTemplate("components/ILIAS/UI/src/templates/default/Table/tpl.datatable.html", true, true);
170  $f = $this->getColumnFactory();
171  $data = new class () implements ILIAS\UI\Component\Table\DataRetrieval {
172  public function getRows(
173  Component\Table\DataRowBuilder $row_builder,
174  array $visible_column_ids,
175  Data\Range $range,
176  Data\Order $order,
177  ?array $filter_data,
178  ?array $additional_parameters
179  ): \Generator {
180  yield $row_builder->buldDataRow('', []);
181  }
182  public function getTotalRowCount(
183  ?array $filter_data,
184  ?array $additional_parameters
185  ): ?int {
186  return null;
187  }
188  };
189  $columns = [
190  'f1' => $f->text("Field 1")->withIndex(1),
191  'f2' => $f->text("Field 2")->withIndex(2)->withIsSortable(false),
192  'f3' => $f->number("Field 3")->withIndex(3)
193  ];
194  $sortation_signal = new I\Signal('sort_header_signal_id');
195  $sortation_signal->addOption('value', 'f1:ASC');
196  $table = $this->getUIFactory()->table()->data('', $columns, $data)
197  ->withRequest($this->getDummyRequest());
198  $renderer->p_renderTableHeader($this->getDefaultRenderer(), $table, $tpl, $sortation_signal);
199 
200  $actual = $this->brutallyTrimHTML($tpl->get());
201  $expected = <<<EOT
202 <div class="c-table-data" id="{ID}">
203  <div class="viewcontrols">{VIEW_CONTROLS}</div>
204  <div class="c-table-data__table-wrapper">
205  <table class="c-table-data__table" aria-labelledby="{ID}_label" aria-colcount="{COL_COUNT}" role="grid">
206  <thead>
207  <tr class="c-table-data__header c-table-data__row">
208  <th class="c-table-data__header c-table-data__cell c-table-data__cell--text" tabindex="-1" aria-colindex="1" aria-sort="ascending">
209  <div class="c-table-data__header__resize-wrapper">
210  <a tabindex="0" class="glyph" href="#" aria-label="sort_ascending" id="id_2"><span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span></a>
211  <button class="btn btn-link" id="id_1">Field 1</button>
212  </div>
213  </th>
214  <th class="c-table-data__header c-table-data__cell c-table-data__cell--text" tabindex="-1" aria-colindex="2">
215  <div class="c-table-data__header__resize-wrapper">Field 2</div>
216  </th>
217  <th class="c-table-data__header c-table-data__cell c-table-data__cell--number" tabindex="-1" aria-colindex="3">
218  <div class="c-table-data__header__resize-wrapper">
219  <button class="btn btn-link" id="id_3">Field 3</button>
220  </div>
221  </th>
222  </tr>
223  </thead>
224  <tbody class="c-table-data__body"></tbody>
225  </table>
226  </div>
227  <div class="c-table-data__async_modal_container"></div>
228  <dialog class="c-table-data__async_message c-modal" id="{ID}_msgmodal">
229  <div class="modal-dialog" role="document">
230  <div class="modal-content">
231  <div class="modal-header">
232  <form>
233  <button formmethod="dialog" class="close" aria-label="close">
234  <span aria-hidden="true">&times;</span></button>
235  </form>
236  </div>
237  <div class="c-table-data__async_messageresponse modal-body"></div>
238  </div>
239  </div>
240  </dialog>
241 </div>
242 EOT;
243  $expected = $this->brutallyTrimHTML($expected);
244  $this->assertEquals($expected, $actual);
245  }
button(string $caption, string $cmd)
$renderer
Interface Observer Contains several chained tasks and infos about them.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
sort()
description: > Example for rendering a Sort Glyph.
Definition: sort.php:25
Both the subject and the direction need to be specified when expressing an order. ...
Definition: Order.php:12
form( $class_path, string $cmd, string $submit_caption="")
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:28
+ Here is the call graph for this function:

◆ testDataTableRowBuilder()

DataRendererTest::testDataTableRowBuilder ( )

Definition at line 369 of file DataRendererTest.php.

References Vendor\Package\$f, $token, $url, and ILIAS\UI\Implementation\Component\Input\getDataFactory().

370  {
371  $f = $this->getColumnFactory();
372  $columns = [
373  'f1' => $f->text("Field 1")->withIndex(1),
374  'f2' => $f->text("Field 2")->withIndex(2),
375  'f3' => $f->number("Field 3")->withIndex(3)
376  ];
377  $f = $this->getActionFactory();
378  $url = $this->getDataFactory()->uri('http://wwww.ilias.de?ref_id=1');
379  $url_builder = new URLBuilder($url);
380  list($builder, $token) = $url_builder->acquireParameter(['namespace'], 'param');
381  $actions = [
382  'a1' => $f->standard('label1', $builder, $token)->withAsync(),
383  'a2' => $f->standard('label2', $builder, $token)
384  ];
385 
386  $rb = (new I\Table\DataRowBuilder())
387  ->withMultiActionsPresent(true)
388  ->withSingleActions($actions)
389  ->withVisibleColumns($columns);
390 
391  $row = $rb->buildDataRow('row_id-1', []);
392  $this->assertInstanceOf(Component\Table\DataRow::class, $row);
393 
394  return [$rb, $columns, $actions];
395  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$url
Definition: shib_logout.php:63
$token
Definition: xapitoken.php:67
URLBuilder.
Definition: URLBuilder.php:39
+ Here is the call graph for this function:

◆ testDataTableSingleActionsDropdown()

DataRendererTest::testDataTableSingleActionsDropdown ( )

Definition at line 148 of file DataRendererTest.php.

References Vendor\Package\$f, $renderer, $token, $url, and ILIAS\UI\Implementation\Component\Input\getDataFactory().

149  {
150  $renderer = $this->getRenderer();
151  $f = $this->getActionFactory();
152  $url = $this->getDataFactory()->uri('http://wwww.ilias.de?ref_id=1');
153  $url_builder = new URLBuilder($url);
154  list($builder, $token) = $url_builder->acquireParameter(['namespace'], 'param');
155  $actions = [
156  'a1' => $f->standard('label1', $builder, $token)->withAsync(),
157  'a2' => $f->standard('label2', $builder, $token)
158  ];
159  $this->assertEquals(
160  2,
161  count($renderer->p_getSingleActionsForRow('row_id-1', $actions)->getItems())
162  );
163  }
$renderer
$url
Definition: shib_logout.php:63
$token
Definition: xapitoken.php:67
URLBuilder.
Definition: URLBuilder.php:39
+ Here is the call graph for this function:

◆ testRenderEmptyDataCell()

DataRendererTest::testRenderEmptyDataCell ( )

Definition at line 461 of file DataRendererTest.php.

References $data, ILIAS\UI\Implementation\Component\Table\$range, ILIAS\ResourceStorage\Flavour\Machine\DefaultMachines\from(), and getLanguage().

461  : void
462  {
463  $data = new class () implements Component\Table\DataRetrieval {
464  public function getRows(
465  Component\Table\DataRowBuilder $row_builder,
466  array $visible_column_ids,
467  Data\Range $range,
468  Data\Order $order,
469  ?array $filter_data,
470  ?array $additional_parameters
471  ): Generator {
472  yield from [];
473  }
474 
475  public function getTotalRowCount(?array $filter_data, ?array $additional_parameters): ?int
476  {
477  return 0;
478  }
479  };
480 
481  $columns = [
482  'f1' => $this->getUIFactory()->table()->column()->text('f1'),
483  'f2' => $this->getUIFactory()->table()->column()->text('f2'),
484  'f3' => $this->getUIFactory()->table()->column()->text('f3'),
485  'f4' => $this->getUIFactory()->table()->column()->text('f4'),
486  'f5' => $this->getUIFactory()->table()->column()->text('f5'),
487  ];
488 
489  $table = $this->getTableFactory()->data('', $columns, $data)
490  ->withRequest($this->getDummyRequest());
491 
492  $html = $this->getDefaultRenderer()->render($table);
493 
494  $translation = $this->getLanguage()->txt('ui_table_no_records');
495  $column_count = count($columns);
496 
497  // check that the empty cell is stretched over all columns.
498  $this->assertTrue(str_contains($html, "colspan=\"$column_count\""));
499  // check that the cell contains the default message.
500  $this->assertTrue(str_contains($html, $translation));
501  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Both the subject and the direction need to be specified when expressing an order. ...
Definition: Order.php:12
getLanguage()
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:28
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: