ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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(): I\Component\Button\Factory
105  {
106  return new I\Component\Button\Factory();
107  }
108  public function symbol(): I\Component\Symbol\Factory
109  {
110  return new I\Component\Symbol\Factory(
111  new I\Component\Symbol\Icon\Factory(),
112  new I\Component\Symbol\Glyph\Factory(),
113  new I\Component\Symbol\Avatar\Factory()
114  );
115  }
116  };
117  $factory->sig_gen = new I\Component\SignalGenerator();
118  return $factory;
119  }
120 
121  protected function getDummyData(): array
122  {
123  return [[
124  'headline' => 'some title',
125  'subhead' => 'some type',
126  'important_fields' => ['important-1','important-2'],
127  'content' => ['1st' => 'first content', '2nd' => 'second content'],
128  'further_headline' => 'further fields',
129  'further_fields' => ['f-1' => 'further', 'f-2' => 'way further'],
130  'action' => 'do'
131  ]];
132  }
133 
134  public function testFullRendering(): void
135  {
136  $mapping = function ($row, $record, $ui_factory, $environment) {
137  return $row
138  ->withHeadline($record['headline'])
139  ->withSubheadline($record['subhead'])
140  ->withImportantFields($record['important_fields'])
141  ->withContent((new I\Component\Listing\Descriptive($record['content'])))
142  ->withFurtherFieldsHeadline($record['further_headline'])
143  ->withFurtherFields($record['further_fields'])
144  ->withAction((new I\Component\Button\Standard($record['action'], '#')));
145  };
146 
147  $expected = <<<EXP
148 <div class="il-table-presentation" id="id_3">
149  <h3 class="ilHeader">title</h3>
150  <div class="il-table-presentation-viewcontrols">
151  <div class="l-bar__space-keeper l-bar__space-keeper--space-between">
152  <div class="l-bar__group">
153  <div class="l-bar__element">
154  <button class="btn btn-default" id="id_1">presentation_table_expand</button>
155  <button class="btn btn-default" id="id_2">presentation_table_collapse</button>
156  </div>
157  </div>
158  <div class="l-bar__group"></div>
159  </div>
160  </div>
161  <div class="il-table-presentation-data">
162  <div class="il-table-presentation-row row collapsed" id="id_4">
163 
164  <div class="il-table-presentation-row-controls col-lg-auto col-sm-12">
165  <div class="il-table-presentation-row-controls-expander inline">
166  <a tabindex="0" class="glyph" href="#" aria-label="expand_content" id="id_5">
167  <span class="glyphicon glyphicon-triangle-right" aria-hidden="true"></span>
168  </a>
169  </div>
170  <div class="il-table-presentation-row-controls-collapser">
171  <a tabindex="0" class="glyph" href="#" aria-label="collapse_content" id="id_6">
172  <span class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span>
173  </a>
174  </div>
175  </div>
176 
177  <div class="il-table-presentation-row-contents col-lg col-sm-12">
178  <div class="row">
179  <div class="il-table-presentation-row-header col-lg col-sm-12">
180  <h4 class="il-table-presentation-row-header-headline" onClick="$(document).trigger('il_signal...');">some title<br /><small>some type</small>
181  </h4>
182  <div class="il-table-presentation-row-header-fields">
183  <div class="l-bar__space-keeper">
184  <div class="l-bar__group">
185  <div class="il-table-presentation-row-header-fields-value l-bar__element">important-1</div>
186  </div>
187  </div>
188  <div class="l-bar__space-keeper">
189  <div class="l-bar__group">
190  <div class="il-table-presentation-row-header-fields-value l-bar__element">important-2</div>
191  </div>
192  </div>
193  <button class="btn btn-link" id="id_7">presentation_table_more</button>
194  </div>
195  </div>
196  <div class="il-table-presentation-actions col-lg-auto col-sm-12">
197  <button class="btn btn-default" data-action="#" id="id_8">do</button><br />
198  </div>
199  <div class="il-table-presentation-row-expanded col-lg-12 col-sm-12">
200  <div class="row">
201  <div class="il-table-presentation-desclist col-lg col-sm-12 desclist-column">
202  <dl>
203  <dt>1st</dt>
204  <dd>first content</dd>
205  <dt>2nd</dt>
206  <dd>second content</dd>
207  </dl>
208  </div>
209  <div class="il-table-presentation-details col-lg-5 col-sm-12">
210  <div class="il-table-presentation-fields">
211  <h5>further fields</h5>
212  <span class="il-item-property-name">f-1</span>
213  <span class="il-item-property-value">further</span>
214  <br />
215  <span class="il-item-property-name">f-2</span>
216  <span class="il-item-property-value">way further</span>
217  <br />
218  </div>
219  </div>
220  </div>
221  </div>
222  </div>
223  </div>
224  </div>
225  </div>
226 </div>
227 EXP;
228 
229  $r = $this->getDefaultRenderer();
230  $f = $this->getTableFactory();
231  $pt = $f->presentation('title', [], $mapping);
232  $actual = $r->render($pt->withData($this->getDummyData()));
233  $this->assertEquals(
234  $this->brutallyTrimHTML($expected),
235  $this->brutallyTrimHTML($this->brutallyTrimSignals($actual))
236  );
237  }
238 
239 
240  public function testMinimalRendering(): void
241  {
242  $mapping = function ($row, $record, $ui_factory, $environment) {
243  return $row
244  ->withHeadline($record['headline'])
245  ->withContent((new I\Component\Listing\Descriptive($record['content'])));
246  };
247 
248  $expected = <<<EXP
249 <div class="il-table-presentation" id="id_3">
250  <h3 class="ilHeader">title</h3>
251  <div class="il-table-presentation-viewcontrols">
252 
253  <div class="l-bar__space-keeper l-bar__space-keeper--space-between">
254  <div class="l-bar__group">
255  <div class="l-bar__element">
256 
257  <button class="btn btn-default" id="id_1">presentation_table_expand</button>
258  <button class="btn btn-default" id="id_2">presentation_table_collapse</button>
259  </div>
260  </div>
261  <div class="l-bar__group"></div>
262  </div>
263  </div>
264  <div class="il-table-presentation-data">
265  <div class="il-table-presentation-row row collapsed" id="id_4">
266 
267  <div class="il-table-presentation-row-controls col-lg-auto col-sm-12">
268  <div class="il-table-presentation-row-controls-expander inline">
269  <a tabindex="0" class="glyph" href="#" aria-label="expand_content" id="id_5">
270  <span class="glyphicon glyphicon-triangle-right" aria-hidden="true"></span>
271  </a>
272  </div>
273  <div class="il-table-presentation-row-controls-collapser">
274  <a tabindex="0" class="glyph" href="#" aria-label="collapse_content" id="id_6">
275  <span class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span>
276  </a>
277  </div>
278  </div>
279 
280  <div class="il-table-presentation-row-contents col-lg col-sm-12">
281  <div class="row">
282  <div class="il-table-presentation-row-header col-lg col-sm-12">
283  <h4 class="il-table-presentation-row-header-headline" onClick="$(document).trigger('il_signal...');">some title</h4>
284  <div class="il-table-presentation-row-header-fields">
285  <button class="btn btn-link" id="id_7">presentation_table_more</button>
286  </div>
287  </div>
288  <div class="il-table-presentation-actions col-lg-auto col-sm-12"></div>
289  <div class="il-table-presentation-row-expanded col-lg-12 col-sm-12">
290  <div class="row">
291  <div class="il-table-presentation-desclist col-lg col-sm-12">
292  <dl>
293  <dt>1st</dt>
294  <dd>first content</dd>
295  <dt>2nd</dt>
296  <dd>second content</dd>
297  </dl>
298  </div>
299  </div>
300  </div>
301  </div>
302  </div>
303 
304  </div>
305  </div>
306 </div>
307 EXP;
308  $r = $this->getDefaultRenderer();
309  $f = $this->getTableFactory();
310  $pt = $f->presentation('title', [], $mapping);
311  $actual = $r->render($pt->withData($this->getDummyData()));
312  $this->assertEquals(
313  $this->brutallyTrimHTML($expected),
314  $this->brutallyTrimHTML($this->brutallyTrimSignals($actual))
315  );
316  }
317 
318  public function testRenderEmptyTableEntry(): void
319  {
320  $mapping = fn(PresentationRow $row, mixed $record, \ILIAS\UI\Factory $ui_factory, mixed $environment) => $row;
321 
322  $table = $this->getTableFactory()->presentation('', [], $mapping);
323 
324  $html = $this->getDefaultRenderer()->render($table);
325 
326  $translation = $this->getLanguage()->txt('ui_table_no_records');
327 
328  $this->assertTrue(str_contains($html, $translation));
329  }
330 }
Tests for Presentation Table.
button(string $caption, string $cmd)
Interface Observer Contains several chained tasks and infos about them.
small()
description: > This can be used, when space is very scarce and the label cannot be displayed ...
Definition: small.php:34
getLanguage()
Basic Tests for all Tables.
$r