ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
ChartBarTest Class Reference

Test on Bar Chart implementation. More...

+ Inheritance diagram for ChartBarTest:
+ Collaboration diagram for ChartBarTest:

Public Member Functions

 getDataFactory ()
 
 getUIFactory ()
 
 testImplementsFactoryInterface ()
 
 testGetInstances ()
 
 testEmptyDataset ()
 
 testWithTitle ()
 
 testWithTitleInvisible ()
 
 testWithTooltipsInvisible ()
 
 testWithLegendInvisible ()
 
 testWithLegendPosition ()
 
 testWithInvalidLegendPosition ()
 
 testWithDataset ()
 
 testWithBarConfigs ()
 
 testWithGroupConfigs ()
 
 testIndexAxis ()
 
 testRenderHorizontal ()
 
 testRenderVertical ()
 
 testRenderConvertSpecialCharactersInDatasetLabel (string $risky_datum, string $expected_in_html)
 
 testRenderConvertSpecialCharactersInItemLabel (string $risky_datum, string $expected_in_html)
 

Static Public Member Functions

static provideRiskyData ()
 

Protected Member Functions

 getFactory ()
 
 getSimpleDataset ()
 
 getExtendedDataset ()
 

Detailed Description

Test on Bar Chart implementation.

Definition at line 28 of file ChartBarTest.php.

Member Function Documentation

◆ getDataFactory()

ChartBarTest::getDataFactory ( )

Definition at line 35 of file ChartBarTest.php.

36 {
37 return new ILIAS\Data\Factory();
38 }
Builds data types.
Definition: Factory.php:36

Referenced by getExtendedDataset(), getSimpleDataset(), testEmptyDataset(), testIndexAxis(), testWithBarConfigs(), and testWithGroupConfigs().

+ Here is the caller graph for this function:

◆ getExtendedDataset()

ChartBarTest::getExtendedDataset ( )
protected

Definition at line 66 of file ChartBarTest.php.

67 {
68 $df = $this->getDataFactory();
69
70 $c_dimension = $df->dimension()->cardinal();
71 $t_dimension = $df->dimension()->range($c_dimension);
72
73 $dataset = $df->dataset(["Dataset 1" => $c_dimension, "Dataset 2" => $t_dimension]);
74 $dataset = $dataset->withPoint("Item 1", ["Dataset 1" => -1.25, "Dataset 2" => [-2, -1]]);
75 $dataset = $dataset->withPoint("Item 2", ["Dataset 1" => null, "Dataset 2" => [0, 0.5]]);
76
77 return $dataset;
78 }

References getDataFactory().

Referenced by testRenderVertical(), and testWithDataset().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFactory()

ChartBarTest::getFactory ( )
protected

◆ getSimpleDataset()

ChartBarTest::getSimpleDataset ( )
protected

Definition at line 54 of file ChartBarTest.php.

55 {
56 $df = $this->getDataFactory();
57
58 $c_dimension = $df->dimension()->cardinal();
59
60 $dataset = $df->dataset(["Dataset" => $c_dimension]);
61 $dataset = $dataset->withPoint("Item", ["Dataset" => 0]);
62
63 return $dataset;
64 }

References getDataFactory().

Referenced by testGetInstances(), testIndexAxis(), testRenderHorizontal(), testWithBarConfigs(), testWithDataset(), testWithGroupConfigs(), testWithInvalidLegendPosition(), testWithLegendInvisible(), testWithLegendPosition(), testWithTitle(), testWithTitleInvisible(), and testWithTooltipsInvisible().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUIFactory()

ChartBarTest::getUIFactory ( )

Definition at line 40 of file ChartBarTest.php.

41 {
42 return new class () extends NoUIFactory {
43 public function listing(): I\Component\Listing\Factory
44 {
45 return new I\Component\Listing\Factory(
46 new I\Component\Listing\Workflow\Factory(),
47 new I\Component\Listing\CharacteristicValue\Factory(),
48 new I\Component\Listing\Entity\Factory(),
49 );
50 }
51 };
52 }

References ILIAS\Repository\listing().

+ Here is the call graph for this function:

◆ provideRiskyData()

static ChartBarTest::provideRiskyData ( )
static

Definition at line 404 of file ChartBarTest.php.

404 : array
405 {
406 return [
407 "ampersand" => ["this&that", "this&that"],
408 "single quote" => ["it's a kind of magic", "it's a kind of magic"],
409 "double quote" => ['Dwayne "The Rock" Johnson', 'Dwayne "The Rock" Johnson'],
410 "tags" => ['<script>alert("XSS")</script>', '&lt;script&gt;alert(&quot;XSS&quot;)&lt;/script&gt;'],
411 ];
412 }

◆ testEmptyDataset()

ChartBarTest::testEmptyDataset ( )

Definition at line 109 of file ChartBarTest.php.

109 : void
110 {
111 $f = $this->getFactory();
112 $df = $this->getDataFactory();
113
114 $c_dimension = $df->dimension()->cardinal();
115
116 $dataset = $df->dataset(["Dataset" => $c_dimension]);
117
118 $this->expectException(LogicException::class);
119 $this->expectExceptionMessage("Dataset must not be empty.");
120 $horizontal = $f->horizontal(
121 "Horizontal Bar",
122 $dataset
123 );
124 }

References Vendor\Package\$f, getDataFactory(), and getFactory().

+ Here is the call graph for this function:

◆ testGetInstances()

ChartBarTest::testGetInstances ( )

Definition at line 87 of file ChartBarTest.php.

87 : void
88 {
89 $f = $this->getFactory();
90
91 $dataset = $this->getSimpleDataset();
92
93 $horizontal = $f->horizontal(
94 "Horizontal Bar",
95 $dataset
96 );
97
98 $this->assertInstanceOf("ILIAS\\UI\\Component\\Chart\\Bar\\Bar", $horizontal);
99 $this->assertInstanceOf("ILIAS\\UI\\Component\\Chart\\Bar\\Horizontal", $horizontal);
100
101 $vertical = $f->vertical(
102 "Vertical Bar",
103 $dataset
104 );
105 $this->assertInstanceOf("ILIAS\\UI\\Component\\Chart\\Bar\\Bar", $vertical);
106 $this->assertInstanceOf("ILIAS\\UI\\Component\\Chart\\Bar\\Vertical", $vertical);
107 }

References Vendor\Package\$f, getFactory(), and getSimpleDataset().

+ Here is the call graph for this function:

◆ testImplementsFactoryInterface()

ChartBarTest::testImplementsFactoryInterface ( )

Definition at line 80 of file ChartBarTest.php.

80 : void
81 {
82 $f = $this->getFactory();
83
84 $this->assertInstanceOf("ILIAS\\UI\\Component\\Chart\\Bar\\Factory", $f);
85 }

References Vendor\Package\$f, and getFactory().

+ Here is the call graph for this function:

◆ testIndexAxis()

ChartBarTest::testIndexAxis ( )

Definition at line 308 of file ChartBarTest.php.

308 : void
309 {
310 $f = $this->getFactory();
311 $df = $this->getDataFactory();
312
313 $dataset = $this->getSimpleDataset();
314
315 $horizontal = $f->horizontal(
316 "Horizontal Bar",
317 $dataset
318 );
319
320 $this->assertEquals("y", $horizontal->getIndexAxis());
321
322 $vertical = $f->vertical(
323 "Vertical Bar",
324 $dataset
325 );
326
327 $this->assertEquals("x", $vertical->getIndexAxis());
328 }

References Vendor\Package\$f, getDataFactory(), getFactory(), and getSimpleDataset().

+ Here is the call graph for this function:

◆ testRenderConvertSpecialCharactersInDatasetLabel()

ChartBarTest::testRenderConvertSpecialCharactersInDatasetLabel ( string  $risky_datum,
string  $expected_in_html 
)

Definition at line 415 of file ChartBarTest.php.

418 : void {
419 $r = $this->getDefaultRenderer();
420 $f = $this->getFactory();
421 $df = $this->getDataFactory();
422
423 $c_dimension = $df->dimension()->cardinal();
424
425 $dataset = $df->dataset([$risky_datum => $c_dimension]);
426 $dataset = $dataset->withPoint("Item", [$risky_datum => 123]);
427
428 $vertical = $f->vertical(
429 "bar123",
430 $dataset
431 );
432
433 $html = $r->render($vertical);
434
435 $expected_html = <<<EOT
436<div class="il-chart-bar-vertical">
437 <canvas id="id_1" height="150" aria-label="bar123" role="img"></canvas>
438</div>
439<div class="sr-only">
440 <dl>
441 <dt>$expected_in_html</dt>
442 <dd>
443 <ul>
444 <li>Item: 123</li>
445 </ul>
446 </dd>
447 </dl>
448</div>
449EOT;
450
451 $this->assertHTMLEquals("<div>" . $expected_html . "</div>", "<div>" . $html . "</div>");
452 }

◆ testRenderConvertSpecialCharactersInItemLabel()

ChartBarTest::testRenderConvertSpecialCharactersInItemLabel ( string  $risky_datum,
string  $expected_in_html 
)

Definition at line 455 of file ChartBarTest.php.

458 : void {
459 $r = $this->getDefaultRenderer();
460 $f = $this->getFactory();
461 $df = $this->getDataFactory();
462
463 $c_dimension = $df->dimension()->cardinal();
464
465 $dataset = $df->dataset(["Dataset" => $c_dimension]);
466 $dataset = $dataset->withPoint($risky_datum, ["Dataset" => 123]);
467
468 $vertical = $f->vertical(
469 "bar123",
470 $dataset
471 );
472
473 $html = $r->render($vertical);
474
475 $expected_html = <<<EOT
476<div class="il-chart-bar-vertical">
477 <canvas id="id_1" height="150" aria-label="bar123" role="img"></canvas>
478</div>
479<div class="sr-only">
480 <dl>
481 <dt>Dataset</dt>
482 <dd>
483 <ul>
484 <li>$expected_in_html: 123</li>
485 </ul>
486 </dd>
487 </dl>
488</div>
489EOT;
490
491 $this->assertHTMLEquals("<div>" . $expected_html . "</div>", "<div>" . $html . "</div>");
492 }

◆ testRenderHorizontal()

ChartBarTest::testRenderHorizontal ( )

Definition at line 330 of file ChartBarTest.php.

330 : void
331 {
332 $r = $this->getDefaultRenderer();
333 $f = $this->getFactory();
334
335 $dataset = $this->getSimpleDataset();
336
337 $horizontal = $f->horizontal(
338 "bar123",
339 $dataset
340 );
341
342 $html = $r->render($horizontal);
343
344 $expected_html = <<<EOT
345<div class="il-chart-bar-horizontal">
346 <canvas id="id_1" height="150" aria-label="bar123" role="img"></canvas>
347</div>
348<div class="sr-only">
349 <dl>
350 <dt>Dataset</dt>
351 <dd>
352 <ul>
353 <li>Item: 0</li>
354 </ul>
355 </dd>
356 </dl>
357</div>
358EOT;
359
360 $this->assertHTMLEquals("<div>" . $expected_html . "</div>", "<div>" . $html . "</div>");
361 }

References Vendor\Package\$f, getFactory(), and getSimpleDataset().

+ Here is the call graph for this function:

◆ testRenderVertical()

ChartBarTest::testRenderVertical ( )

Definition at line 363 of file ChartBarTest.php.

363 : void
364 {
365 $r = $this->getDefaultRenderer();
366 $f = $this->getFactory();
367
368 $dataset = $this->getExtendedDataset();
369
370 $vertical = $f->vertical(
371 "bar123",
372 $dataset
373 );
374
375 $html = $r->render($vertical);
376
377 $expected_html = <<<EOT
378<div class="il-chart-bar-vertical">
379 <canvas id="id_1" height="165" aria-label="bar123" role="img"></canvas>
380</div>
381<div class="sr-only">
382 <dl>
383 <dt>Dataset 1</dt>
384 <dd>
385 <ul>
386 <li>Item 1: -1.25</li>
387 <li>Item 2: -</li>
388 </ul>
389 </dd>
390 <dt>Dataset 2</dt>
391 <dd>
392 <ul>
393 <li>Item 1: -2 - -1</li>
394 <li>Item 2: 0 - 0.5</li>
395 </ul>
396 </dd>
397 </dl>
398</div>
399EOT;
400
401 $this->assertHTMLEquals("<div>" . $expected_html . "</div>", "<div>" . $html . "</div>");
402 }

References Vendor\Package\$f, getExtendedDataset(), and getFactory().

+ Here is the call graph for this function:

◆ testWithBarConfigs()

ChartBarTest::testWithBarConfigs ( )

Definition at line 260 of file ChartBarTest.php.

260 : void
261 {
262 $f = $this->getFactory();
263 $df = $this->getDataFactory();
264
265 $dataset = $this->getSimpleDataset();
266
267 $bc = new C\Chart\Bar\BarConfig();
268 $bc = $bc->withColor($df->color("#d38000"));
269
270 $bars = [
271 "Dataset" => $bc,
272 ];
273
274 $horizontal = $f->horizontal(
275 "Horizontal Bar",
276 $dataset
277 );
278 $horizontal1 = $horizontal->withBarConfigs($bars);
279
280 $this->assertEquals([], $horizontal->getBarConfigs());
281 $this->assertEquals($bars, $horizontal1->getBarConfigs());
282 }

References Vendor\Package\$f, getDataFactory(), getFactory(), and getSimpleDataset().

+ Here is the call graph for this function:

◆ testWithDataset()

ChartBarTest::testWithDataset ( )

Definition at line 243 of file ChartBarTest.php.

243 : void
244 {
245 $f = $this->getFactory();
246
247 $s_dataset = $this->getSimpleDataset();
248 $e_dataset = $this->getExtendedDataset();
249
250 $horizontal = $f->horizontal(
251 "Horizontal Bar",
252 $s_dataset
253 );
254 $horizontal1 = $horizontal->withDataset($e_dataset);
255
256 $this->assertEquals($s_dataset, $horizontal->getDataset());
257 $this->assertEquals($e_dataset, $horizontal1->getDataset());
258 }

References Vendor\Package\$f, getExtendedDataset(), getFactory(), and getSimpleDataset().

+ Here is the call graph for this function:

◆ testWithGroupConfigs()

ChartBarTest::testWithGroupConfigs ( )

Definition at line 284 of file ChartBarTest.php.

284 : void
285 {
286 $f = $this->getFactory();
287 $df = $this->getDataFactory();
288
289 $dataset = $this->getSimpleDataset();
290
291 $gc = new C\Chart\Bar\GroupConfig();
292 $gc = $gc->withStacked();
293
294 $groups = [
295 "Group" => $gc,
296 ];
297
298 $horizontal = $f->horizontal(
299 "Horizontal Bar",
300 $dataset
301 );
302 $horizontal1 = $horizontal->withGroupConfigs($groups);
303
304 $this->assertEquals([], $horizontal->getGroupConfigs());
305 $this->assertEquals($groups, $horizontal1->getGroupConfigs());
306 }

References Vendor\Package\$f, getDataFactory(), getFactory(), and getSimpleDataset().

+ Here is the call graph for this function:

◆ testWithInvalidLegendPosition()

ChartBarTest::testWithInvalidLegendPosition ( )

Definition at line 226 of file ChartBarTest.php.

226 : void
227 {
228 $f = $this->getFactory();
229
230 $dataset = $this->getSimpleDataset();
231
232 $horizontal = $f->horizontal(
233 "Horizontal Bar",
234 $dataset
235 );
236
237 $this->expectException(InvalidArgumentException::class);
238 $this->expectExceptionMessage("Position must be 'bottom', 'top', 'left' or 'right'.");
239
240 $horizontal = $horizontal->withLegendPosition("middle");
241 }

References Vendor\Package\$f, getFactory(), and getSimpleDataset().

+ Here is the call graph for this function:

◆ testWithLegendInvisible()

ChartBarTest::testWithLegendInvisible ( )

Definition at line 194 of file ChartBarTest.php.

194 : void
195 {
196 $f = $this->getFactory();
197
198 $dataset = $this->getSimpleDataset();
199
200 $horizontal = $f->horizontal(
201 "Horizontal Bar",
202 $dataset
203 );
204 $horizontal1 = $horizontal->withLegendVisible(false);
205
206 $this->assertEquals(true, $horizontal->isLegendVisible());
207 $this->assertEquals(false, $horizontal1->isLegendVisible());
208 }

References Vendor\Package\$f, getFactory(), and getSimpleDataset().

+ Here is the call graph for this function:

◆ testWithLegendPosition()

ChartBarTest::testWithLegendPosition ( )

Definition at line 210 of file ChartBarTest.php.

210 : void
211 {
212 $f = $this->getFactory();
213
214 $dataset = $this->getSimpleDataset();
215
216 $horizontal = $f->horizontal(
217 "Horizontal Bar",
218 $dataset
219 );
220 $horizontal1 = $horizontal->withLegendPosition("left");
221
222 $this->assertEquals("top", $horizontal->getLegendPosition());
223 $this->assertEquals("left", $horizontal1->getLegendPosition());
224 }

References Vendor\Package\$f, getFactory(), and getSimpleDataset().

+ Here is the call graph for this function:

◆ testWithTitle()

ChartBarTest::testWithTitle ( )

Definition at line 146 of file ChartBarTest.php.

146 : void
147 {
148 $f = $this->getFactory();
149
150 $dataset = $this->getSimpleDataset();
151
152 $horizontal = $f->horizontal(
153 "Horizontal Bar",
154 $dataset
155 );
156 $horizontal1 = $horizontal->withTitle("Alternative title for Horizontal Bar");
157
158 $this->assertEquals("Horizontal Bar", $horizontal->getTitle());
159 $this->assertEquals("Alternative title for Horizontal Bar", $horizontal1->getTitle());
160 }

References Vendor\Package\$f, getFactory(), and getSimpleDataset().

+ Here is the call graph for this function:

◆ testWithTitleInvisible()

ChartBarTest::testWithTitleInvisible ( )

Definition at line 162 of file ChartBarTest.php.

162 : void
163 {
164 $f = $this->getFactory();
165
166 $dataset = $this->getSimpleDataset();
167
168 $horizontal = $f->horizontal(
169 "Horizontal Bar",
170 $dataset
171 );
172 $horizontal1 = $horizontal->withTitleVisible(false);
173
174 $this->assertEquals(true, $horizontal->isTitleVisible());
175 $this->assertEquals(false, $horizontal1->isTitleVisible());
176 }

References Vendor\Package\$f, getFactory(), and getSimpleDataset().

+ Here is the call graph for this function:

◆ testWithTooltipsInvisible()

ChartBarTest::testWithTooltipsInvisible ( )

Definition at line 178 of file ChartBarTest.php.

178 : void
179 {
180 $f = $this->getFactory();
181
182 $dataset = $this->getSimpleDataset();
183
184 $horizontal = $f->horizontal(
185 "Horizontal Bar",
186 $dataset
187 );
188 $horizontal1 = $horizontal->withTooltipsVisible(false);
189
190 $this->assertEquals(true, $horizontal->isTooltipsVisible());
191 $this->assertEquals(false, $horizontal1->isTooltipsVisible());
192 }

References Vendor\Package\$f, getFactory(), and getSimpleDataset().

+ Here is the call graph for this function:

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