ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
PresentationTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once("vendor/composer/vendor/autoload.php");
22 require_once(__DIR__ . "/TableTestBase.php");
23 
25 use ILIAS\UI\Component as C;
27 
32 {
33  private function getFactory(): I\Component\Table\Factory
34  {
35  return new I\Component\Table\Factory(
36  new I\Component\SignalGenerator(),
37  new \ILIAS\Data\Factory(),
38  new I\Component\Table\Column\Factory(),
39  new I\Component\Table\Action\Factory(),
40  new I\Component\Table\DataRowBuilder(),
41  new I\Component\Table\OrderingRowBuilder()
42  );
43  }
44 
45  public function testTableConstruction(): void
46  {
47  $f = $this->getTableFactory();
48  $this->assertInstanceOf("ILIAS\\UI\\Component\\Table\\Factory", $f);
49 
50  $pt = $f->presentation('title', [], function (): void {
51  });
52  $this->assertInstanceOf("ILIAS\\UI\\Component\\Table\\Presentation", $pt);
53 
54  $this->assertEquals("title", $pt->getTitle());
55  $this->assertEquals([], $pt->getViewControls());
56  $this->assertInstanceOf(Closure::class, $pt->getRowMapping());
57 
58  $pt = $pt
59  ->withEnvironment(array('k' => 'v'))
60  ->withData(array('dk' => 'dv'));
61  $this->assertEquals(array('k' => 'v'), $pt->getEnvironment());
62  $this->assertEquals(array('dk' => 'dv'), $pt->getData());
63  }
64 
65  public function testRowConstruction(): void
66  {
67  $f = $this->getTableFactory();
68  $pt = $f->presentation('title', [], function (): void {
69  });
70  $row = new PresentationRow($pt->getSignalGenerator(), 'table_id');
71 
72  $this->assertInstanceOf("ILIAS\\UI\\Component\\Table\\PresentationRow", $row);
73  $this->assertInstanceOf("ILIAS\\UI\\Component\\Signal", $row->getShowSignal());
74  $this->assertInstanceOf("ILIAS\\UI\\Component\\Signal", $row->getCloseSignal());
75  $this->assertInstanceOf("ILIAS\\UI\\Component\\Signal", $row->getToggleSignal());
76 
77  $this->assertEquals(
78  "headline",
79  $row->withHeadline("headline")->getHeadline()
80  );
81  $this->assertEquals(
82  "subheadline",
83  $row->withSubheadline("subheadline")->getSubheadline()
84  );
85  $this->assertEquals(
86  array("f1" => "v1"),
87  $row->withImportantFields(array("f1" => "v1"))->getImportantFields()
88  );
89  $this->assertEquals(
90  "field_headline",
91  $row->withFurtherFieldsHeadline("field_headline")->getFurtherFieldsHeadline()
92  );
93  $this->assertEquals(
94  array("ff1" => "fv1"),
95  $row->withFurtherFields(array("ff1" => "fv1"))->getFurtherFields()
96  );
97  }
98 
99  public function getUIFactory(): NoUIFactory
100  {
101  $factory = new class () extends NoUIFactory {
102  public I\Component\SignalGenerator $sig_gen;
103 
104  public function button(): C\Button\Factory
105  {
106  return new I\Component\Button\Factory(
107  new I\Component\SignalGenerator()
108  );
109  }
110  public function symbol(): ILIAS\UI\Component\Symbol\Factory
111  {
112  return new I\Component\Symbol\Factory(
113  new I\Component\Symbol\Icon\Factory(),
114  new I\Component\Symbol\Glyph\Factory(),
115  new I\Component\Symbol\Avatar\Factory()
116  );
117  }
118  };
119  $factory->sig_gen = new I\Component\SignalGenerator();
120  return $factory;
121  }
122 
123  protected function getDummyData(): array
124  {
125  return [[
126  'headline' => 'some title',
127  'subhead' => 'some type',
128  'important_fields' => ['important-1','important-2'],
129  'content' => ['1st' => 'first content', '2nd' => 'second content'],
130  'further_headline' => 'further fields',
131  'further_fields' => ['f-1' => 'further', 'f-2' => 'way further'],
132  'action' => 'do'
133  ]];
134  }
135 
136  public function testFullRendering(): void
137  {
138  $mapping = function ($row, $record, $ui_factory, $environment) {
139  return $row
140  ->withHeadline($record['headline'])
141  ->withSubheadline($record['subhead'])
142  ->withImportantFields($record['important_fields'])
143  ->withContent((new I\Component\Listing\Descriptive($record['content'])))
144  ->withFurtherFieldsHeadline($record['further_headline'])
145  ->withFurtherFields($record['further_fields'])
146  ->withAction((new I\Component\Button\Standard($record['action'], '#')));
147  };
148 
149  $expected = <<<EXP
150 <div class="il-table-presentation" id="id_3">
151  <h3 class="ilHeader">title</h3>
152  <div class="il-table-presentation-viewcontrols">
153  <div class="l-bar__space-keeper l-bar__space-keeper--space-between">
154  <div class="l-bar__group">
155  <div class="l-bar__element">
156  <button class="btn btn-default" id="id_1">presentation_table_expand</button>
157  <button class="btn btn-default" id="id_2">presentation_table_collapse</button>
158  </div>
159  </div>
160  <div class="l-bar__group"></div>
161  </div>
162  </div>
163  <div class="il-table-presentation-data">
164  <div class="il-table-presentation-row row collapsed" id="id_4">
165 
166  <div class="il-table-presentation-row-controls col-lg-auto col-sm-12">
167  <div class="il-table-presentation-row-controls-expander inline">
168  <a tabindex="0" class="glyph" href="#" aria-label="expand_content" id="id_5">
169  <span class="glyphicon glyphicon-triangle-right" aria-hidden="true"></span>
170  </a>
171  </div>
172  <div class="il-table-presentation-row-controls-collapser">
173  <a tabindex="0" class="glyph" href="#" aria-label="collapse_content" id="id_6">
174  <span class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span>
175  </a>
176  </div>
177  </div>
178 
179  <div class="il-table-presentation-row-contents col-lg col-sm-12">
180  <div class="row">
181  <div class="il-table-presentation-row-header col-lg col-sm-12">
182  <h4 class="il-table-presentation-row-header-headline" onClick="$(document).trigger('il_signal...');">some title<br /><small>some type</small>
183  </h4>
184  <div class="il-table-presentation-row-header-fields">
185  <div class="l-bar__space-keeper">
186  <div class="l-bar__group">
187  <div class="il-table-presentation-row-header-fields-value l-bar__element">important-1</div>
188  </div>
189  </div>
190  <div class="l-bar__space-keeper">
191  <div class="l-bar__group">
192  <div class="il-table-presentation-row-header-fields-value l-bar__element">important-2</div>
193  </div>
194  </div>
195  <button class="btn btn-link" id="id_7">presentation_table_more</button>
196  </div>
197  </div>
198  <div class="il-table-presentation-actions col-lg-auto col-sm-12">
199  <button class="btn btn-default" data-action="#" id="id_8">do</button><br />
200  </div>
201  <div class="il-table-presentation-row-expanded col-lg-12 col-sm-12">
202  <div class="row">
203  <div class="il-table-presentation-desclist col-lg col-sm-12 desclist-column">
204  <dl>
205  <dt>1st</dt>
206  <dd>first content</dd>
207  <dt>2nd</dt>
208  <dd>second content</dd>
209  </dl>
210  </div>
211  <div class="il-table-presentation-details col-lg-5 col-sm-12">
212  <div class="il-table-presentation-fields">
213  <h5>further fields</h5>
214  <span class="il-item-property-name">f-1</span>
215  <span class="il-item-property-value">further</span>
216  <br />
217  <span class="il-item-property-name">f-2</span>
218  <span class="il-item-property-value">way further</span>
219  <br />
220  </div>
221  </div>
222  </div>
223  </div>
224  </div>
225  </div>
226  </div>
227  </div>
228 </div>
229 EXP;
230 
231  $r = $this->getDefaultRenderer();
232  $f = $this->getTableFactory();
233  $pt = $f->presentation('title', [], $mapping);
234  $actual = $r->render($pt->withData($this->getDummyData()));
235  $this->assertEquals(
236  $this->brutallyTrimHTML($expected),
237  $this->brutallyTrimHTML($this->brutallyTrimSignals($actual))
238  );
239  }
240 
241 
242  public function testMinimalRendering(): void
243  {
244  $mapping = function ($row, $record, $ui_factory, $environment) {
245  return $row
246  ->withHeadline($record['headline'])
247  ->withContent((new I\Component\Listing\Descriptive($record['content'])));
248  };
249 
250  $expected = <<<EXP
251 <div class="il-table-presentation" id="id_3">
252  <h3 class="ilHeader">title</h3>
253  <div class="il-table-presentation-viewcontrols">
254 
255  <div class="l-bar__space-keeper l-bar__space-keeper--space-between">
256  <div class="l-bar__group">
257  <div class="l-bar__element">
258 
259  <button class="btn btn-default" id="id_1">presentation_table_expand</button>
260  <button class="btn btn-default" id="id_2">presentation_table_collapse</button>
261  </div>
262  </div>
263  <div class="l-bar__group"></div>
264  </div>
265  </div>
266  <div class="il-table-presentation-data">
267  <div class="il-table-presentation-row row collapsed" id="id_4">
268 
269  <div class="il-table-presentation-row-controls col-lg-auto col-sm-12">
270  <div class="il-table-presentation-row-controls-expander inline">
271  <a tabindex="0" class="glyph" href="#" aria-label="expand_content" id="id_5">
272  <span class="glyphicon glyphicon-triangle-right" aria-hidden="true"></span>
273  </a>
274  </div>
275  <div class="il-table-presentation-row-controls-collapser">
276  <a tabindex="0" class="glyph" href="#" aria-label="collapse_content" id="id_6">
277  <span class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span>
278  </a>
279  </div>
280  </div>
281 
282  <div class="il-table-presentation-row-contents col-lg col-sm-12">
283  <div class="row">
284  <div class="il-table-presentation-row-header col-lg col-sm-12">
285  <h4 class="il-table-presentation-row-header-headline" onClick="$(document).trigger('il_signal...');">some title</h4>
286  <div class="il-table-presentation-row-header-fields">
287  <button class="btn btn-link" id="id_7">presentation_table_more</button>
288  </div>
289  </div>
290  <div class="il-table-presentation-actions col-lg-auto col-sm-12"></div>
291  <div class="il-table-presentation-row-expanded col-lg-12 col-sm-12">
292  <div class="row">
293  <div class="il-table-presentation-desclist col-lg col-sm-12">
294  <dl>
295  <dt>1st</dt>
296  <dd>first content</dd>
297  <dt>2nd</dt>
298  <dd>second content</dd>
299  </dl>
300  </div>
301  </div>
302  </div>
303  </div>
304  </div>
305 
306  </div>
307  </div>
308 </div>
309 EXP;
310  $r = $this->getDefaultRenderer();
311  $f = $this->getTableFactory();
312  $pt = $f->presentation('title', [], $mapping);
313  $actual = $r->render($pt->withData($this->getDummyData()));
314  $this->assertEquals(
315  $this->brutallyTrimHTML($expected),
316  $this->brutallyTrimHTML($this->brutallyTrimSignals($actual))
317  );
318  }
319 
320  public function testRenderEmptyTableEntry(): void
321  {
322  $mapping = fn(PresentationRow $row, mixed $record, \ILIAS\UI\Factory $ui_factory, mixed $environment) => $row;
323 
324  $table = $this->getTableFactory()->presentation('', [], $mapping);
325 
326  $html = $this->getDefaultRenderer()->render($table);
327 
328  $translation = $this->getLanguage()->txt('ui_table_no_records');
329 
330  $this->assertTrue(str_contains($html, $translation));
331  }
332 }
Tests for Presentation Table.
button(string $caption, string $cmd)
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...
small()
description: > This can be used, when space is very scarce and the label cannot be displayed ...
Definition: small.php:18
getLanguage()
Basic Tests for all Tables.
$r