ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ItemShyTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
20 require_once(__DIR__ . '/../../../../libs/composer/vendor/autoload.php');
21 require_once(__DIR__ . '/../../Base.php');
22 
23 use ILIAS\UI\Component as C;
25 
30 {
31  public function getFactory(): C\Item\Factory
32  {
33  return new I\Component\Item\Factory();
34  }
35 
36  public function test_implements_factory_interface(): void
37  {
38  $f = $this->getFactory();
39 
40  $shy = $f->shy('shy');
41 
42  $this->assertInstanceOf('ILIAS\\UI\\Component\\Item\\Shy', $shy);
43  }
44 
45  public function test_with_description(): void
46  {
47  $f = $this->getFactory();
48  $c = $f->shy('shy')->withDescription('This is a shy');
49  $this->assertEquals('This is a shy', $c->getDescription());
50  }
51 
52  public function test_with_property(): void
53  {
54  $f = $this->getFactory();
55  $c = $f->shy('shy')->withProperties(['name' => 'value']);
56  $this->assertEquals(['name' => 'value'], $c->getProperties());
57  }
58 
59  public function test_with_close(): void
60  {
61  $f = $this->getFactory();
62  $c = $f->shy('shy')->withClose((new I\Component\Button\Factory())->close());
63  $this->assertInstanceOf(I\Component\Button\Close::class, $c->getClose());
64  }
65 
66  public function test_with_lead_icon(): void
67  {
68  $f = $this->getFactory();
69  $c = $f->shy('shy')->withLeadIcon(
70  (new I\Component\Symbol\Icon\Factory())->standard('name', 'label')
71  );
72  $this->assertInstanceOf(I\Component\Symbol\Icon\Icon::class, $c->getLeadIcon());
73  }
74 
75  public function test_render_base(): void
76  {
77  $c = $this->getFactory()->shy('shy');
78 
79  $expected = <<<EOT
80 <div class="il-item il-item-shy">
81  <div class="content">
82  <div class="il-item-title">shy</div>
83  </div>
84 </div>
85 EOT;
86 
87  $this->assertHTMLEquals(
88  $this->brutallyTrimHTML($expected),
89  $this->brutallyTrimHTML($this->getDefaultRenderer()->render($c))
90  );
91  }
92 
93  public function test_render_critical(): void
94  {
95  $c = $this->getFactory()->shy('noid"><script>alert(\'CRITICAL\')</script');
96 
97  $expected = <<<EOT
98 <div class="il-item il-item-shy">
99  <div class="content">
100  <div class="il-item-title">noid"&gt;&lt;script&gt;alert('CRITICAL')&lt;/script</div>
101  </div>
102 </div>
103 EOT;
104 
105  $this->assertHTMLEquals(
106  $this->brutallyTrimHTML($expected),
107  $this->brutallyTrimHTML($this->getDefaultRenderer()->render($c))
108  );
109  }
110 
111  public function test_render_with_description(): void
112  {
113  $c = $this->getFactory()->shy('shy')->withDescription('This is a shy');
114 
115  $expected = <<<EOT
116 <div class="il-item il-item-shy">
117  <div class="content">
118  <div class="il-item-title">shy</div>
119  <div class="il-item-description">This is a shy</div>
120  </div>
121 </div>
122 EOT;
123 
124  $this->assertHTMLEquals(
125  $this->brutallyTrimHTML($expected),
126  $this->brutallyTrimHTML($this->getDefaultRenderer()->render($c))
127  );
128  }
129 
130  public function test_render_with_property(): void
131  {
132  $c = $this->getFactory()->shy('shy')->withProperties(['name' => 'value']);
133 
134  $expected = <<<EOT
135 <div class="il-item il-item-shy">
136  <div class="content">
137  <div class="il-item-title">shy</div>
138  <hr class="il-item-divider" />
139  <div class="il-item-properties">
140  <div class="il-item-property-name">name</div>
141  <div class="il-item-property-value">value</div>
142  </div>
143  </div>
144 </div>
145 EOT;
146 
147  $this->assertHTMLEquals(
148  $this->brutallyTrimHTML($expected),
149  $this->brutallyTrimHTML($this->getDefaultRenderer()->render($c))
150  );
151  }
152 
153 
154  public function test_render_with_lead_icon(): void
155  {
156  $c = $this->getFactory()->shy('shy')->withLeadIcon(
157  new I\Component\Symbol\Icon\Standard('name', 'aria_label', 'small', false)
158  );
159 
160  $expected = <<<EOT
161 <div class="il-item il-item-shy">
162  <img class="icon name small" src="./templates/default/images/icon_default.svg" alt="aria_label" />
163  <div class="content">
164  <div class="il-item-title">shy</div>
165  </div>
166 </div>
167 EOT;
168 
169  $this->assertHTMLEquals(
170  $this->brutallyTrimHTML($expected),
171  $this->brutallyTrimHTML($this->getDefaultRenderer()->render($c))
172  );
173  }
174 
175  public function test_render_with_close(): void
176  {
177  $c = $this->getFactory()->shy('shy')->withClose(new I\Component\Button\Close());
178 
179  $expected = <<<EOT
180 <div class="il-item il-item-shy">
181  <div class="content">
182  <div class="il-item-title">shy</div>
183  <button type="button" class="close" aria-label="close">
184  <span aria-hidden="true">&times;</span>
185  </button>
186  </div>
187 </div>
188 EOT;
189 
190  $this->assertEquals(
191  $this->brutallyTrimHTML($expected),
192  $this->brutallyTrimHTML($this->getDefaultRenderer()->render($c))
193  );
194  }
195 }
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
$c
Definition: cli.php:38
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
standard()
This is an example, of how the Notification Slate is generated by assigning Notification Items to it...
Definition: standard.php:16
test_render_critical()
Definition: ItemShyTest.php:93
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:444
assertHTMLEquals(string $expected_html_as_string, string $html_as_string)
Definition: Base.php:427
Provides common functionality for UI tests.
Definition: Base.php:298
test_with_property()
Definition: ItemShyTest.php:52
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: ItemShyTest.php:29
test_implements_factory_interface()
Definition: ItemShyTest.php:36
test_with_description()
Definition: ItemShyTest.php:45
test_with_lead_icon()
Definition: ItemShyTest.php:66