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