ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
13 {
14  private function getIconFactory()
15  {
16  $f = new \ILIAS\UI\Implementation\Factory();
17  return $f->icon();
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->assertNull($ico->getAbbreviation());
41 
42  $ico = $ico->withAbbreviation('K');
43  $this->assertEquals('K', $ico->getAbbreviation());
44  }
45 
46  public function testSizeModification()
47  {
48  $f = $f = $this->getIconFactory();
49  $ico = $f->standard('course', 'Kurs');
50 
51  $ico = $ico->withSize('medium');
52  $this->assertEquals('medium', $ico->getSize());
53 
54  $ico = $ico->withSize('large');
55  $this->assertEquals('large', $ico->getSize());
56 
57  $ico = $ico->withSize('small');
58  $this->assertEquals('small', $ico->getSize());
59  }
60 
62  {
63  try {
64  $f = $f = $this->getIconFactory();
65  $ico = $f->standard('course', 'Kurs');
66  $ico = $ico->withSize('tiny');
67  $this->assertFalse("This should not happen");
68  } catch (\InvalidArgumentException $e) {
69  $this->assertTrue(true);
70  }
71  }
72 
73  public function testCustomPath()
74  {
75  $f = $f = $this->getIconFactory();
76 
77  $ico = $f->custom('/some/path/', 'Custom Icon');
78  $this->assertEquals('/some/path/', $ico->getIconPath());
79  }
80 
81  public function testRenderingStandard()
82  {
83  $f = $f = $this->getIconFactory();
84  $r = $this->getDefaultRenderer();
85 
86  $ico = $ico = $f->standard('crs', 'Course', 'medium');
87  $html = $this->normalizeHTML($r->render($ico));
88  $expected = '<div class="icon crs medium" aria-label="Course"></div>';
89  $this->assertEquals($expected, $html);
90 
91  //with abbreviation
92  $ico = $ico->withAbbreviation('CRS');
93  $html = $this->normalizeHTML($r->render($ico));
94  $expected = '<div class="icon crs medium" aria-label="Course">'
95  . ' <div class="abbreviation">CRS</div>'
96  . '</div>';
97  $this->assertEquals($expected, $html);
98  }
99 
100  public function testRenderingCustom()
101  {
102  $f = $f = $this->getIconFactory();
103  $r = $this->getDefaultRenderer();
104  $path = './templates/default/images/icon_fold.svg';
105 
106  $ico = $ico = $f->custom($path, 'Custom', 'medium');
107  $html = $this->normalizeHTML($r->render($ico));
108  $expected = '<div class="icon custom medium" aria-label="Custom">'
109  . ' <img src="./templates/default/images/icon_fold.svg" />'
110  . '</div>';
111  $this->assertEquals($expected, $html);
112 
113  //with abbreviation
114  $ico = $ico->withAbbreviation('CS');
115  $html = $this->normalizeHTML($r->render($ico));
116  $expected = '<div class="icon custom medium" aria-label="Custom">'
117  . ' <img src="./templates/default/images/icon_fold.svg" />'
118  . ' <div class="abbreviation">CS</div>'
119  . '</div>';
120 
121  $this->assertEquals($expected, $html);
122  }
123 }
testAttributes()
Definition: IconTest.php:32
testCustomPath()
Definition: IconTest.php:73
testRenderingCustom()
Definition: IconTest.php:100
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:216
normalizeHTML($html)
Definition: Base.php:243
$r
Definition: example_031.php:79
Provides common functionality for UI tests.
Definition: Base.php:177
testSizeModificationWrongParam()
Definition: IconTest.php:61
Test on icon implementation.
Definition: IconTest.php:12
testSizeModification()
Definition: IconTest.php:46
testRenderingStandard()
Definition: IconTest.php:81
testConstruction()
Definition: IconTest.php:20
$html
Definition: example_001.php:87
getIconFactory()
Definition: IconTest.php:14