ILIAS  release_7 Revision v7.30-3-g800a261c036
IconTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2017 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
3
4require_once("libs/composer/vendor/autoload.php");
5require_once(__DIR__ . "/../../../Base.php");
6
7use \ILIAS\UI\Implementation as I;
8
13{
14 const ICON_PATH = __DIR__ . "/../../../../../templates/default/images/";
15 const ICON_OUTLINED_PATH = self::ICON_PATH . "outlined/";
16
17 private function getIconFactory()
18 {
19 return new I\Component\Symbol\Icon\Factory();
20 }
21
22 public function testConstruction()
23 {
24 $f = $this->getIconFactory();
25 $this->assertInstanceOf("ILIAS\\UI\\Component\\Symbol\\Icon\\Factory", $f);
26
27 $si = $f->standard('course', 'Kurs');
28 $this->assertInstanceOf("ILIAS\\UI\\Component\\Symbol\\Icon\\Standard", $si);
29
30 $ci = $f->custom('course', 'Kurs');
31 $this->assertInstanceOf("ILIAS\\UI\\Component\\Symbol\\Icon\\Custom", $ci);
32 }
33
34 public function testAttributes()
35 {
36 $f = $this->getIconFactory();
37
38 $ico = $f->standard('course', 'Kurs');
39 $this->assertEquals('Kurs', $ico->getLabel());
40 $this->assertEquals('course', $ico->getName());
41 $this->assertEquals('small', $ico->getSize());
42 $this->assertEquals(false, $ico->isDisabled());
43 $this->assertEquals(false, $ico->isOutlined());
44
45 $this->assertNull($ico->getAbbreviation());
46
47 $ico = $ico->withAbbreviation('K');
48 $this->assertEquals('K', $ico->getAbbreviation());
49 }
50
51 public function testSizeModification()
52 {
53 $f = $this->getIconFactory();
54 $ico = $f->standard('course', 'Kurs');
55
56 $ico = $ico->withSize('medium');
57 $this->assertEquals('medium', $ico->getSize());
58
59 $ico = $ico->withSize('large');
60 $this->assertEquals('large', $ico->getSize());
61
62 $ico = $ico->withSize('small');
63 $this->assertEquals('small', $ico->getSize());
64 }
65
67 {
68 try {
69 $f = $this->getIconFactory();
70 $ico = $f->standard('course', 'Kurs');
71 $ico = $ico->withSize('tiny');
72 $this->assertFalse("This should not happen");
73 } catch (\InvalidArgumentException $e) {
74 $this->assertTrue(true);
75 }
76 }
77
78 public function testDisabledModification()
79 {
80 $f = $this->getIconFactory();
81 $ico = $f->standard('course', 'Kurs', 'small');
82
83 $ico = $ico->withDisabled(false);
84 $this->assertEquals(false, $ico->isDisabled());
85
86 $ico = $ico->withDisabled(true);
87 $this->assertEquals(true, $ico->isDisabled());
88 }
89
91 {
92 try {
93 $f = $this->getIconFactory();
94 $ico = $f->standard('course', 'Kurs', 'small');
95 $ico = $ico->withDisabled('true');
96 $this->assertFalse("This should not happen");
97 } catch (\InvalidArgumentException $e) {
98 $this->assertTrue(true);
99 }
100 }
101
102 public function testOutlinedModification()
103 {
104 $f = $this->getIconFactory();
105 $ico = $f->standard('course', 'Kurs', 'small');
106
107 $ico = $ico->withIsOutlined(true);
108 $this->assertEquals(true, $ico->isOutlined());
109
110 $ico = $ico->withIsOutlined(false);
111 $this->assertEquals(false, $ico->isOutlined());
112 }
113
114 public function testCustomPath()
115 {
116 $f = $this->getIconFactory();
117
118 $ico = $f->custom('/some/path/', 'Custom Icon');
119 $this->assertEquals('/some/path/', $ico->getIconPath());
120 }
121
122 public function testRenderingStandard()
123 {
124 $ico = $this->getIconFactory()->standard('crs', 'Course', 'medium');
125 $html = $this->normalizeHTML($this->getDefaultRenderer()->render($ico));
126 $expected = '<img class="icon crs medium" src="./templates/default/images/icon_crs.svg" alt="Course"/>';
127 $this->assertEquals($expected, $html);
128 return $ico;
129 }
130
134 public function testRenderingStandardDisabled($ico)
135 {
136 $ico = $ico->withDisabled(true);
137 $html = $this->normalizeHTML($this->getDefaultRenderer()->render($ico));
138 $expected = '<img class="icon crs medium disabled" src="./templates/default/images/icon_crs.svg" alt="Course" aria-disabled="true"/>';
139 $this->assertEquals($expected, $html);
140 }
141
146 {
147 $ico = $ico->withAbbreviation('CRS');
148 $html = $this->normalizeHTML($this->getDefaultRenderer()->render($ico));
149 $expected = <<<imgtag
150<img class="icon cr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GV4dAogICBzdHlsZT0iCiAgICAgIGZvbnQtc3R5bGU6bm9ybWFsOwogICAgICBmb250LXdlaWdodDpub3JtYWw7CiAgICAgIGZvbnQtc2l6ZToxNHB4OwogICAgICBmb250LWZhbWlseTpzYW5zLXNlcmlmOwogICAgICBsZXR0ZXItc3BhY2luZzowcHg7CiAgICAgIGZpbGw6IzAwMDsKICAgICAgZmlsbC1vcGFjaXR5OjE7CiAgICAiCiAgICB4PSI1MCUiCiAgICB5PSI1NSUiCiAgICBkb21pbmFudC1iYXNlbGluZT0ibWlkZGxlIgogICAgdGV4dC1hbmNob3I9Im1pZGRsZSIKICA+Q1JTPC90ZXh0Pjwvc3ZnPg==" alt="Course" data-abbreviation="CRS"/>
151imgtag;
152 $this->assertEquals(trim($expected), trim($html));
153 }
154
158 public function testRenderingStandardOutlined($ico)
159 {
160 $ico = $ico->withIsOutlined(true);
161 $html = $this->normalizeHTML($this->getDefaultRenderer()->render($ico));
162 $expected = '<img class="icon crs medium outlined" src="./templates/default/images/outlined/icon_crs.svg" alt="Course"/>';
163 $this->assertEquals($expected, $html);
164 }
165
166 public function testRenderingCustom()
167 {
168 $path = './templates/default/images/icon_fold.svg';
169 $ico = $this->getIconFactory()->custom($path, 'Custom', 'medium');
170 $html = $this->normalizeHTML($this->getDefaultRenderer()->render($ico));
171 $expected = '<img class="icon custom medium" src="./templates/default/images/icon_fold.svg" alt="Custom"/>';
172 $this->assertEquals($expected, $html);
173 return $ico;
174 }
175
177 {
178 $f = $this->getIconFactory();
179 $default_icons_abr = $f->standard("nothing", "nothing")->getAllStandardHandles();
180
181 foreach ($default_icons_abr as $icon_abr) {
182 $path = self::ICON_PATH . "icon_" . $icon_abr . ".svg";
183 $this->assertTrue(file_exists($path), "Missing Standard Icon: " . $path);
184 }
185 }
186
188 {
189 $f = $this->getIconFactory();
190 $default_icons_abr = $f->standard("nothing", "nothing")->getAllStandardHandles();
191
192 foreach ($default_icons_abr as $icon_abr) {
193 $path = self::ICON_OUTLINED_PATH . "icon_" . $icon_abr . ".svg";
194
195 $this->assertTrue(file_exists($path), "Missing Outlined Icon: " . $path);
196 }
197 }
198
203 {
204 $ico = $ico->withAdditionalOnLoadCode(function ($id) {
205 return 'alert();';
206 });
207 $html = $this->normalizeHTML($this->getDefaultRenderer()->render($ico));
208 $expected = $this->normalizeHTML('<img id="id_1" class="icon crs medium" src="./templates/default/images/icon_crs.svg" alt="Course"/>');
209 $this->assertEquals($expected, $html);
210 }
211}
An exception for terminatinating execution or to throw for unit testing.
Provides common functionality for UI tests.
Definition: Base.php:263
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
normalizeHTML($html)
Definition: Base.php:363
Test on icon implementation.
Definition: IconTest.php:13
testRenderingStandardJSBindable($ico)
@depends testRenderingStandard
Definition: IconTest.php:202
testRenderingStandard()
Definition: IconTest.php:122
testRenderingStandardDisabled($ico)
@depends testRenderingStandard
Definition: IconTest.php:134
testRenderingStandardAbbreviation($ico)
@depends testRenderingStandard
Definition: IconTest.php:145
testSizeModificationWrongParam()
Definition: IconTest.php:66
testSizeModification()
Definition: IconTest.php:51
testCustomPath()
Definition: IconTest.php:114
testAttributes()
Definition: IconTest.php:34
getIconFactory()
Definition: IconTest.php:17
const ICON_PATH
Definition: IconTest.php:14
testRenderingCustom()
Definition: IconTest.php:166
testOutlinedModification()
Definition: IconTest.php:102
testAllOutlinedIconsExist()
Definition: IconTest.php:187
testRenderingStandardOutlined($ico)
@depends testRenderingStandard
Definition: IconTest.php:158
const ICON_OUTLINED_PATH
Definition: IconTest.php:15
testConstruction()
Definition: IconTest.php:22
testDisabledModification()
Definition: IconTest.php:78
testAllStandardIconsExist()
Definition: IconTest.php:176
testDisabledModificationWrongParam()
Definition: IconTest.php:90