ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
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)
 @dataProvider provideRiskyData More...
 
 testRenderConvertSpecialCharactersInItemLabel (string $risky_datum, string $expected_in_html)
 @dataProvider provideRiskyData More...
 

Static Public Member Functions

static provideRiskyData ()
 

Protected Member Functions

 getFactory ()
 
 getSimpleDataset ()
 
 getExtendedDataset ()
 

Detailed Description

Test on Bar Chart implementation.

Definition at line 27 of file ChartBarTest.php.

Member Function Documentation

◆ getDataFactory()

ChartBarTest::getDataFactory ( )

Definition at line 34 of file ChartBarTest.php.

35 {
36 return new ILIAS\Data\Factory();
37 }
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 65 of file ChartBarTest.php.

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

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 53 of file ChartBarTest.php.

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

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 39 of file ChartBarTest.php.

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

References ILIAS\Repository\listing().

+ Here is the call graph for this function:

◆ provideRiskyData()

static ChartBarTest::provideRiskyData ( )
static

Definition at line 403 of file ChartBarTest.php.

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

◆ testEmptyDataset()

ChartBarTest::testEmptyDataset ( )

Definition at line 108 of file ChartBarTest.php.

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

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

+ Here is the call graph for this function:

◆ testGetInstances()

ChartBarTest::testGetInstances ( )

Definition at line 86 of file ChartBarTest.php.

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

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

+ Here is the call graph for this function:

◆ testImplementsFactoryInterface()

ChartBarTest::testImplementsFactoryInterface ( )

Definition at line 79 of file ChartBarTest.php.

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

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

+ Here is the call graph for this function:

◆ testIndexAxis()

ChartBarTest::testIndexAxis ( )

Definition at line 307 of file ChartBarTest.php.

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

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 
)

@dataProvider provideRiskyData

Definition at line 416 of file ChartBarTest.php.

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

◆ testRenderConvertSpecialCharactersInItemLabel()

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

@dataProvider provideRiskyData

Definition at line 458 of file ChartBarTest.php.

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

◆ testRenderHorizontal()

ChartBarTest::testRenderHorizontal ( )

Definition at line 329 of file ChartBarTest.php.

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

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

+ Here is the call graph for this function:

◆ testRenderVertical()

ChartBarTest::testRenderVertical ( )

Definition at line 362 of file ChartBarTest.php.

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

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

+ Here is the call graph for this function:

◆ testWithBarConfigs()

ChartBarTest::testWithBarConfigs ( )

Definition at line 259 of file ChartBarTest.php.

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

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

+ Here is the call graph for this function:

◆ testWithDataset()

ChartBarTest::testWithDataset ( )

Definition at line 242 of file ChartBarTest.php.

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

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

+ Here is the call graph for this function:

◆ testWithGroupConfigs()

ChartBarTest::testWithGroupConfigs ( )

Definition at line 283 of file ChartBarTest.php.

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

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

+ Here is the call graph for this function:

◆ testWithInvalidLegendPosition()

ChartBarTest::testWithInvalidLegendPosition ( )

Definition at line 225 of file ChartBarTest.php.

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

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

+ Here is the call graph for this function:

◆ testWithLegendInvisible()

ChartBarTest::testWithLegendInvisible ( )

Definition at line 193 of file ChartBarTest.php.

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

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

+ Here is the call graph for this function:

◆ testWithLegendPosition()

ChartBarTest::testWithLegendPosition ( )

Definition at line 209 of file ChartBarTest.php.

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

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

+ Here is the call graph for this function:

◆ testWithTitle()

ChartBarTest::testWithTitle ( )

Definition at line 145 of file ChartBarTest.php.

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

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

+ Here is the call graph for this function:

◆ testWithTitleInvisible()

ChartBarTest::testWithTitleInvisible ( )

Definition at line 161 of file ChartBarTest.php.

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

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

+ Here is the call graph for this function:

◆ testWithTooltipsInvisible()

ChartBarTest::testWithTooltipsInvisible ( )

Definition at line 177 of file ChartBarTest.php.

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

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: