ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
4 require_once("libs/composer/vendor/autoload.php");
5 require_once(__DIR__ . "/../../../Base.php");
6 
7 use \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->getAriaLabel());
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  $f = $this->getIconFactory();
125  $r = $this->getDefaultRenderer();
126 
127  $ico = $ico = $f->standard('crs', 'Course', 'medium');
128  $html = $this->normalizeHTML($r->render($ico));
129  $expected = '<div class="icon crs medium" aria-label="Course"></div>';
130  $this->assertEquals($expected, $html);
131 
132  //with disabled
133  $ico = $ico->withDisabled(true);
134  $html = $this->normalizeHTML($r->render($ico));
135  $expected = '<div class="icon crs medium disabled" aria-label="Course"></div>';
136  $this->assertEquals($expected, $html);
137 
138  //with abbreviation
139  $ico = $ico->withAbbreviation('CRS');
140  $html = $this->normalizeHTML($r->render($ico));
141  $expected = '<div class="icon crs medium disabled" aria-label="Course">'
142  . ' <div class="abbreviation">CRS</div>'
143  . '</div>';
144  $this->assertEquals($expected, $html);
145  }
146 
148  {
149  $f = $this->getIconFactory();
150  $r = $this->getDefaultRenderer();
151 
152  $ico = $ico = $f->standard('crs', 'Course', 'medium')->withIsOutlined(true);
153  $html = $this->normalizeHTML($r->render($ico));
154  $expected = '<div class="icon crs medium outlined" aria-label="Course"></div>';
155  $this->assertEquals($expected, $html);
156 
157  //with disabled
158  $ico = $ico->withDisabled(true);
159  $html = $this->normalizeHTML($r->render($ico));
160  $expected = '<div class="icon crs medium disabled outlined" aria-label="Course"></div>';
161  $this->assertEquals($expected, $html);
162 
163  //with abbreviation
164  $ico = $ico->withAbbreviation('CRS');
165  $html = $this->normalizeHTML($r->render($ico));
166  $expected = '<div class="icon crs medium disabled outlined" aria-label="Course">'
167  . ' <div class="abbreviation">CRS</div>'
168  . '</div>';
169  $this->assertEquals($expected, $html);
170  }
171 
172  public function testRenderingCustom()
173  {
174  $f = $this->getIconFactory();
175  $r = $this->getDefaultRenderer();
176  $path = './templates/default/images/icon_fold.svg';
177 
178  $ico = $ico = $f->custom($path, 'Custom', 'medium');
179  $html = $this->normalizeHTML($r->render($ico));
180  $expected = '<div class="icon custom medium" aria-label="Custom">'
181  . ' <img src="./templates/default/images/icon_fold.svg" />'
182  . '</div>';
183  $this->assertEquals($expected, $html);
184 
185  //with disabled
186  $ico = $ico->withDisabled(true);
187  $html = $this->normalizeHTML($r->render($ico));
188  $expected = '<div class="icon custom medium disabled" aria-label="Custom">'
189  . ' <img src="./templates/default/images/icon_fold.svg" />'
190  . '</div>';
191  $this->assertEquals($expected, $html);
192 
193  //with abbreviation
194  $ico = $ico->withAbbreviation('CS');
195  $html = $this->normalizeHTML($r->render($ico));
196  $expected = '<div class="icon custom medium disabled" aria-label="Custom">'
197  . ' <img src="./templates/default/images/icon_fold.svg" />'
198  . ' <div class="abbreviation">CS</div>'
199  . '</div>';
200 
201  $this->assertEquals($expected, $html);
202  }
203 
204  public function testAllStandardIconsExist()
205  {
206  $f = $this->getIconFactory();
207  $default_icons_abr = $f->standard("nothing", "nothing")->getAllStandardHandles();
208 
209  foreach ($default_icons_abr as $icon_abr) {
210  $path = self::ICON_PATH . "icon_" . $icon_abr . ".svg";
211  $this->assertTrue(file_exists($path), "Missing Standard Icon: " . $path);
212  }
213  }
214 
215  public function testAllOutlinedIconsExist()
216  {
217  $f = $this->getIconFactory();
218  $default_icons_abr = $f->standard("nothing", "nothing")->getAllStandardHandles();
219 
220  foreach ($default_icons_abr as $icon_abr) {
221  $path = self::ICON_OUTLINED_PATH . "icon_" . $icon_abr . ".svg";
222 
223  $this->assertTrue(file_exists($path), "Missing Outlined Icon: " . $path);
224  }
225  }
226 }
testDisabledModificationWrongParam()
Definition: IconTest.php:90
testAttributes()
Definition: IconTest.php:34
testCustomPath()
Definition: IconTest.php:114
testDisabledModification()
Definition: IconTest.php:78
testAllOutlinedIconsExist()
Definition: IconTest.php:215
testRenderingCustom()
Definition: IconTest.php:172
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:268
normalizeHTML($html)
Definition: Base.php:317
Provides common functionality for UI tests.
Definition: Base.php:224
testSizeModificationWrongParam()
Definition: IconTest.php:66
testAllStandardIconsExist()
Definition: IconTest.php:204
testOutlinedModification()
Definition: IconTest.php:102
Test on icon implementation.
Definition: IconTest.php:12
testRenderingStandardOutlined()
Definition: IconTest.php:147
const ICON_PATH
Definition: IconTest.php:14
const ICON_OUTLINED_PATH
Definition: IconTest.php:15
testSizeModification()
Definition: IconTest.php:51
testRenderingStandard()
Definition: IconTest.php:122
testConstruction()
Definition: IconTest.php:22
getIconFactory()
Definition: IconTest.php:17