ILIAS  release_8 Revision v8.24
PresentationTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once("libs/composer/vendor/autoload.php");
22require_once(__DIR__ . "/TableTestBase.php");
23
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 testBareTableRendering(): void
54 {
55 $r = $this->getDefaultRenderer();
56 $f = $this->getTableFactory();
57 $pt = $f->presentation('title', [], function (): void {
58 });
59 $expected = <<<EXP
60 <div class="il-table-presentation" id="id_1">
61 <h3 class="ilHeader">title</h3>
62 <div class="il-table-presentation-data"></div>
63 </div>
64EXP;
65
66 $this->assertHTMLEquals(
67 $this->brutallyTrimHTML($expected),
68 $this->brutallyTrimHTML($r->render($pt->withData([])))
69 );
70 }
71
72 public function testRowConstruction(): void
73 {
74 $f = $this->getTableFactory();
75 $pt = $f->presentation('title', [], function (): void {
76 });
77 $row = new PresentationRow($pt->getSignalGenerator(), 'table_id');
78
79 $this->assertInstanceOf("ILIAS\\UI\\Component\\Table\\PresentationRow", $row);
80 $this->assertInstanceOf("ILIAS\\UI\\Component\\Signal", $row->getShowSignal());
81 $this->assertInstanceOf("ILIAS\\UI\\Component\\Signal", $row->getCloseSignal());
82 $this->assertInstanceOf("ILIAS\\UI\\Component\\Signal", $row->getToggleSignal());
83
84 $this->assertEquals(
85 "headline",
86 $row->withHeadline("headline")->getHeadline()
87 );
88 $this->assertEquals(
89 "subheadline",
90 $row->withSubheadline("subheadline")->getSubheadline()
91 );
92 $this->assertEquals(
93 array("f1" => "v1"),
94 $row->withImportantFields(array("f1" => "v1"))->getImportantFields()
95 );
96 $this->assertEquals(
97 "field_headline",
98 $row->withFurtherFieldsHeadline("field_headline")->getFurtherFieldsHeadline()
99 );
100 $this->assertEquals(
101 array("ff1" => "fv1"),
102 $row->withFurtherFields(array("ff1" => "fv1"))->getFurtherFields()
103 );
104 }
105
106 public function getUIFactory(): NoUIFactory
107 {
108 $factory = new class () extends NoUIFactory {
109 public I\Component\SignalGenerator $sig_gen;
110
111 public function button(): C\Button\Factory
112 {
113 return new I\Component\Button\Factory(
114 new I\Component\SignalGenerator()
115 );
116 }
117 public function symbol(): ILIAS\UI\Component\Symbol\Factory
118 {
119 return new I\Component\Symbol\Factory(
120 new I\Component\Symbol\Icon\Factory(),
121 new I\Component\Symbol\Glyph\Factory(),
122 new I\Component\Symbol\Avatar\Factory()
123 );
124 }
125 };
126 $factory->sig_gen = new I\Component\SignalGenerator();
127 return $factory;
128 }
129
130 protected function getDummyData(): array
131 {
132 return [[
133 'headline' => 'some title',
134 'subhead' => 'some type',
135 'important_fields' => ['important-1','important-2'],
136 'content' => ['1st' => 'first content', '2nd' => 'second content'],
137 'further_headline' => 'further fields',
138 'further_fields' => ['f-1' => 'further', 'f-2' => 'way further'],
139 'action' => 'do'
140 ]];
141 }
142
143 public function testFullRendering(): void
144 {
145 $mapping = function ($row, $record, $ui_factory, $environment) {
146 return $row
147 ->withHeadline($record['headline'])
148 ->withSubheadline($record['subhead'])
149 ->withImportantFields($record['important_fields'])
150 ->withContent((new I\Component\Listing\Descriptive($record['content'])))
151 ->withFurtherFieldsHeadline($record['further_headline'])
152 ->withFurtherFields($record['further_fields'])
153 ->withAction((new I\Component\Button\Standard($record['action'], '#')));
154 };
155
156 $expected = <<<EXP
157<div class="il-table-presentation" id="id_1">
158 <h3 class="ilHeader">title</h3>
159 <div class="il-table-presentation-data">
160 <div class="il-table-presentation-row row collapsed" id="id_2">
161
162 <div class="il-table-presentation-row-controls">
163 <div class="il-table-presentation-row-controls-expander inline">
164 <a tabindex="0" class="glyph" href="#" aria-label="expand_content" id="id_3">
165 <span class="glyphicon glyphicon-triangle-right" aria-hidden="true"></span>
166 </a>
167 </div>
168 <div class="il-table-presentation-row-controls-collapser">
169 <a tabindex="0" class="glyph" href="#" aria-label="collapse_content" id="id_4">
170 <span class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span>
171 </a>
172 </div>
173 </div>
174
175 <div class="il-table-presentation-row-contents">
176 <div class="il-table-presentation-actions"><button class="btn btn-default" data-action="#" id="id_6">do</button><br /></div>
177 <div class="il-table-presentation-row-header">
178 <h4 class="il-table-presentation-row-header-headline" onClick="$(document).trigger('il_signal...');">some title<br /><small>some type</small>
179 </h4>
180 <div class="il-table-presentation-row-header-fields">important-1|important-2|<button class="btn btn-link" id="id_5">presentation_table_more</button></div>
181 </div>
182
183 <div class="il-table-presentation-row-expanded">
184 <div class="il-table-presentation-desclist inline desclist-column">
185 <dl>
186 <dt>1st</dt>
187 <dd>first content</dd>
188 <dt>2nd</dt>
189 <dd>second content</dd>
190 </dl>
191 </div>
192
193 <div class="il-table-presentation-details inline">
194 <div class="il-table-presentation-fields">
195 <h5>further fields</h5>
196 <span class="il-item-property-name">f-1</span>
197 <span class="il-item-property-value">further</span>
198 <br />
199 <span class="il-item-property-name">f-2</span>
200 <span class="il-item-property-value">way further</span>
201 <br />
202 </div>
203 </div>
204 </div>
205
206 </div>
207 </div>
208 </div>
209</div>
210EXP;
211
212 $r = $this->getDefaultRenderer();
213 $f = $this->getTableFactory();
214 $pt = $f->presentation('title', [], $mapping);
215 $actual = $r->render($pt->withData($this->getDummyData()));
216 $this->assertHTMLEquals(
217 $this->brutallyTrimHTML($expected),
218 $this->brutallyTrimHTML($this->brutallyTrimSignals($actual))
219 );
220 }
221
222
223 public function testMinimalRendering(): void
224 {
225 $mapping = function ($row, $record, $ui_factory, $environment) {
226 return $row
227 ->withHeadline($record['headline'])
228 ->withContent((new I\Component\Listing\Descriptive($record['content'])));
229 };
230
231 $expected = <<<EXP
232<div class="il-table-presentation" id="id_1">
233 <h3 class="ilHeader">title</h3>
234 <div class="il-table-presentation-data">
235 <div class="il-table-presentation-row row collapsed" id="id_2">
236
237 <div class="il-table-presentation-row-controls">
238 <div class="il-table-presentation-row-controls-expander inline">
239 <a tabindex="0" class="glyph" href="#" aria-label="expand_content" id="id_3">
240 <span class="glyphicon glyphicon-triangle-right" aria-hidden="true"></span>
241 </a>
242 </div>
243 <div class="il-table-presentation-row-controls-collapser">
244 <a tabindex="0" class="glyph" href="#" aria-label="collapse_content" id="id_4">
245 <span class="glyphicon glyphicon-triangle-bottom" aria-hidden="true"></span>
246 </a>
247 </div>
248 </div>
249
250 <div class="il-table-presentation-row-contents">
251 <div class="il-table-presentation-actions"></div>
252 <div class="il-table-presentation-row-header">
253 <h4 class="il-table-presentation-row-header-headline" onClick="$(document).trigger('il_signal...');">some title</h4>
254 <div class="il-table-presentation-row-header-fields">
255 <button class="btn btn-link" id="id_5">presentation_table_more</button>
256 </div>
257 </div>
258 <div class="il-table-presentation-row-expanded">
259 <div class="il-table-presentation-desclist inline">
260 <dl>
261 <dt>1st</dt>
262 <dd>first content</dd>
263 <dt>2nd</dt>
264 <dd>second content</dd>
265 </dl>
266 </div>
267 </div>
268 </div>
269
270 </div>
271 </div>
272</div>
273EXP;
274 $r = $this->getDefaultRenderer();
275 $f = $this->getTableFactory();
276 $pt = $f->presentation('title', [], $mapping);
277 $actual = $r->render($pt->withData($this->getDummyData()));
278 $this->assertHTMLEquals(
279 $this->brutallyTrimHTML($expected),
280 $this->brutallyTrimHTML($this->brutallyTrimSignals($actual))
281 );
282 }
283}
assertHTMLEquals(string $expected_html_as_string, string $html_as_string)
Definition: Base.php:427
brutallyTrimSignals(string $html)
A naive replacement of all il_signal-ids with dots to ease comparisons of rendered output.
Definition: Base.php:459
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:444
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
Tests for Presentation Table.
Basic Tests for all Tables.
$errors fields
Definition: imgupload.php:67
$factory
Definition: metadata.php:75
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...