ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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\Component as C;
8 use \ILIAS\UI\Implementation as I;
9 
14 {
15  private function getIconFactory()
16  {
17  return new I\Component\Icon\Factory();
18  }
19 
20  public function testConstruction()
21  {
22  $f = $this->getIconFactory();
23  $this->assertInstanceOf("ILIAS\\UI\\Component\\Icon\\Factory", $f);
24 
25  $si = $f->standard('course', 'Kurs');
26  $this->assertInstanceOf("ILIAS\\UI\\Component\\Icon\\Standard", $si);
27 
28  $ci = $f->custom('course', 'Kurs');
29  $this->assertInstanceOf("ILIAS\\UI\\Component\\Icon\\Custom", $ci);
30  }
31 
32  public function testAttributes()
33  {
34  $f = $this->getIconFactory();
35 
36  $ico = $f->standard('course', 'Kurs');
37  $this->assertEquals('Kurs', $ico->getAriaLabel());
38  $this->assertEquals('course', $ico->getName());
39  $this->assertEquals('small', $ico->getSize());
40  $this->assertEquals(false, $ico->isDisabled());
41  $this->assertEquals(false, $ico->isOutlined());
42 
43  $this->assertNull($ico->getAbbreviation());
44 
45  $ico = $ico->withAbbreviation('K');
46  $this->assertEquals('K', $ico->getAbbreviation());
47  }
48 
49  public function testSizeModification()
50  {
51  $f = $this->getIconFactory();
52  $ico = $f->standard('course', 'Kurs');
53 
54  $ico = $ico->withSize('medium');
55  $this->assertEquals('medium', $ico->getSize());
56 
57  $ico = $ico->withSize('large');
58  $this->assertEquals('large', $ico->getSize());
59 
60  $ico = $ico->withSize('small');
61  $this->assertEquals('small', $ico->getSize());
62  }
63 
65  {
66  try {
67  $f = $this->getIconFactory();
68  $ico = $f->standard('course', 'Kurs');
69  $ico = $ico->withSize('tiny');
70  $this->assertFalse("This should not happen");
71  } catch (\InvalidArgumentException $e) {
72  $this->assertTrue(true);
73  }
74  }
75 
76  public function testDisabledModification()
77  {
78  $f = $this->getIconFactory();
79  $ico = $f->standard('course', 'Kurs', 'small');
80 
81  $ico = $ico->withDisabled(false);
82  $this->assertEquals(false, $ico->isDisabled());
83 
84  $ico = $ico->withDisabled(true);
85  $this->assertEquals(true, $ico->isDisabled());
86  }
87 
89  {
90  try {
91  $f = $this->getIconFactory();
92  $ico = $f->standard('course', 'Kurs', 'small');
93  $ico = $ico->withDisabled('true');
94  $this->assertFalse("This should not happen");
95  } catch (\InvalidArgumentException $e) {
96  $this->assertTrue(true);
97  }
98  }
99 
100  public function testOutlinedModification()
101  {
102  $f = $this->getIconFactory();
103  $ico = $f->standard('course', 'Kurs', 'small');
104 
105  $ico = $ico->withIsOutlined(true);
106  $this->assertEquals(true, $ico->isOutlined());
107 
108  $ico = $ico->withIsOutlined(false);
109  $this->assertEquals(false, $ico->isOutlined());
110  }
111 
112  public function testCustomPath()
113  {
114  $f = $this->getIconFactory();
115 
116  $ico = $f->custom('/some/path/', 'Custom Icon');
117  $this->assertEquals('/some/path/', $ico->getIconPath());
118  }
119 
120  public function testRenderingStandard()
121  {
122  $f = $this->getIconFactory();
123  $r = $this->getDefaultRenderer();
124 
125  $ico = $ico = $f->standard('crs', 'Course', 'medium');
126  $html = $this->normalizeHTML($r->render($ico));
127  $expected = '<div class="icon crs medium" aria-label="Course"></div>';
128  $this->assertEquals($expected, $html);
129 
130  //with disabled
131  $ico = $ico->withDisabled(true);
132  $html = $this->normalizeHTML($r->render($ico));
133  $expected = '<div class="icon crs medium disabled" aria-label="Course"></div>';
134  $this->assertEquals($expected, $html);
135 
136  //with abbreviation
137  $ico = $ico->withAbbreviation('CRS');
138  $html = $this->normalizeHTML($r->render($ico));
139  $expected = '<div class="icon crs medium disabled" aria-label="Course">'
140  . ' <div class="abbreviation">CRS</div>'
141  . '</div>';
142  $this->assertEquals($expected, $html);
143  }
144 
146  {
147  $f = $this->getIconFactory();
148  $r = $this->getDefaultRenderer();
149 
150  $ico = $ico = $f->standard('crs', 'Course', 'medium')->withIsOutlined(true);
151  $html = $this->normalizeHTML($r->render($ico));
152  $expected = '<div class="icon crs medium outlined" aria-label="Course"></div>';
153  $this->assertEquals($expected, $html);
154 
155  //with disabled
156  $ico = $ico->withDisabled(true);
157  $html = $this->normalizeHTML($r->render($ico));
158  $expected = '<div class="icon crs medium disabled outlined" aria-label="Course"></div>';
159  $this->assertEquals($expected, $html);
160 
161  //with abbreviation
162  $ico = $ico->withAbbreviation('CRS');
163  $html = $this->normalizeHTML($r->render($ico));
164  $expected = '<div class="icon crs medium disabled outlined" aria-label="Course">'
165  . ' <div class="abbreviation">CRS</div>'
166  . '</div>';
167  $this->assertEquals($expected, $html);
168  }
169 
170  public function testRenderingCustom()
171  {
172  $f = $this->getIconFactory();
173  $r = $this->getDefaultRenderer();
174  $path = './templates/default/images/icon_fold.svg';
175 
176  $ico = $ico = $f->custom($path, 'Custom', 'medium');
177  $html = $this->normalizeHTML($r->render($ico));
178  $expected = '<div class="icon custom medium" aria-label="Custom">'
179  . ' <img src="./templates/default/images/icon_fold.svg" />'
180  . '</div>';
181  $this->assertEquals($expected, $html);
182 
183  //with disabled
184  $ico = $ico->withDisabled(true);
185  $html = $this->normalizeHTML($r->render($ico));
186  $expected = '<div class="icon custom medium disabled" aria-label="Custom">'
187  . ' <img src="./templates/default/images/icon_fold.svg" />'
188  . '</div>';
189  $this->assertEquals($expected, $html);
190 
191  //with abbreviation
192  $ico = $ico->withAbbreviation('CS');
193  $html = $this->normalizeHTML($r->render($ico));
194  $expected = '<div class="icon custom medium disabled" aria-label="Custom">'
195  . ' <img src="./templates/default/images/icon_fold.svg" />'
196  . ' <div class="abbreviation">CS</div>'
197  . '</div>';
198 
199  $this->assertEquals($expected, $html);
200  }
201 }
testDisabledModificationWrongParam()
Definition: IconTest.php:88
$path
Definition: aliased.php:25
testAttributes()
Definition: IconTest.php:32
testCustomPath()
Definition: IconTest.php:112
testDisabledModification()
Definition: IconTest.php:76
testRenderingCustom()
Definition: IconTest.php:170
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:228
normalizeHTML($html)
Definition: Base.php:261
$r
Definition: example_031.php:79
Provides common functionality for UI tests.
Definition: Base.php:191
testSizeModificationWrongParam()
Definition: IconTest.php:64
testOutlinedModification()
Definition: IconTest.php:100
Test on icon implementation.
Definition: IconTest.php:13
testRenderingStandardOutlined()
Definition: IconTest.php:145
testSizeModification()
Definition: IconTest.php:49
testRenderingStandard()
Definition: IconTest.php:120
testConstruction()
Definition: IconTest.php:20
$html
Definition: example_001.php:87
getIconFactory()
Definition: IconTest.php:15