ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ItemShyTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once(__DIR__ . '/../../../../../../vendor/composer/vendor/autoload.php');
22 require_once(__DIR__ . '/../../Base.php');
23 
24 use ILIAS\UI\Component as C;
26 
31 {
32  public function getFactory(): C\Item\Factory
33  {
34  return new I\Component\Item\Factory();
35  }
36 
37  public function testImplementsFactoryInterface(): void
38  {
39  $f = $this->getFactory();
40 
41  $shy = $f->shy('shy');
42 
43  $this->assertInstanceOf('ILIAS\\UI\\Component\\Item\\Shy', $shy);
44  }
45 
46  public function testWithDescription(): void
47  {
48  $f = $this->getFactory();
49  $c = $f->shy('shy')->withDescription('This is a shy');
50  $this->assertEquals('This is a shy', $c->getDescription());
51  }
52 
53  public function testWithProperty(): void
54  {
55  $f = $this->getFactory();
56  $c = $f->shy('shy')->withProperties(['name' => 'value']);
57  $this->assertEquals(['name' => 'value'], $c->getProperties());
58  }
59 
60  public function testWithClose(): void
61  {
62  $f = $this->getFactory();
63  $c = $f->shy('shy')->withClose((new I\Component\Button\Factory())->close());
64  $this->assertInstanceOf(I\Component\Button\Close::class, $c->getClose());
65  }
66 
67  public function testWithLeadIcon(): void
68  {
69  $f = $this->getFactory();
70  $c = $f->shy('shy')->withLeadIcon(
71  (new I\Component\Symbol\Icon\Factory())->standard('name', 'label')
72  );
73  $this->assertInstanceOf(I\Component\Symbol\Icon\Icon::class, $c->getLeadIcon());
74  }
75 
76  public function testRenderBase(): void
77  {
78  $c = $this->getFactory()->shy('shy');
79 
80  $expected = <<<EOT
81 <div class="il-item il-item-shy">
82  <div class="content">
83  <div class="il-item-title">shy</div>
84  </div>
85 </div>
86 EOT;
87 
88  $this->assertHTMLEquals(
89  $this->brutallyTrimHTML($expected),
90  $this->brutallyTrimHTML($this->getDefaultRenderer()->render($c))
91  );
92  }
93 
94  public function testRenderCritical(): void
95  {
96  $c = $this->getFactory()->shy('noid"><script>alert(\'CRITICAL\')</script');
97 
98  $expected = <<<EOT
99 <div class="il-item il-item-shy">
100  <div class="content">
101  <div class="il-item-title">noid"&gt;&lt;script&gt;alert('CRITICAL')&lt;/script</div>
102  </div>
103 </div>
104 EOT;
105 
106  $this->assertHTMLEquals(
107  $this->brutallyTrimHTML($expected),
108  $this->brutallyTrimHTML($this->getDefaultRenderer()->render($c))
109  );
110  }
111 
112  public function testRenderWithDescription(): void
113  {
114  $c = $this->getFactory()->shy('shy')->withDescription('This is a shy');
115 
116  $expected = <<<EOT
117 <div class="il-item il-item-shy">
118  <div class="content">
119  <div class="il-item-title">shy</div>
120  <div class="il-item-description">This is a shy</div>
121  </div>
122 </div>
123 EOT;
124 
125  $this->assertHTMLEquals(
126  $this->brutallyTrimHTML($expected),
127  $this->brutallyTrimHTML($this->getDefaultRenderer()->render($c))
128  );
129  }
130 
131  public function testRenderWithProperty(): void
132  {
133  $c = $this->getFactory()->shy('shy')->withProperties(['name' => 'value']);
134 
135  $expected = <<<EOT
136 <div class="il-item il-item-shy">
137  <div class="content">
138  <div class="il-item-title">shy</div>
139  <hr class="il-item-divider" />
140  <div class="il-item-properties">
141  <div class="il-item-property-name">name</div>
142  <div class="il-item-property-value">value</div>
143  </div>
144  </div>
145 </div>
146 EOT;
147 
148  $this->assertHTMLEquals(
149  $this->brutallyTrimHTML($expected),
150  $this->brutallyTrimHTML($this->getDefaultRenderer()->render($c))
151  );
152  }
153 
154 
155  public function testRenderWithLeadIcon(): void
156  {
157  $c = $this->getFactory()->shy('shy')->withLeadIcon(
158  new I\Component\Symbol\Icon\Standard('name', 'aria_label', 'small', false)
159  );
160 
161  $expected = <<<EOT
162 <div class="il-item il-item-shy">
163  <img class="icon name small" src="./assets/images/standard/icon_default.svg" alt="aria_label" />
164  <div class="content">
165  <div class="il-item-title">shy</div>
166  </div>
167 </div>
168 EOT;
169 
170  $this->assertHTMLEquals(
171  $this->brutallyTrimHTML($expected),
172  $this->brutallyTrimHTML($this->getDefaultRenderer()->render($c))
173  );
174  }
175 
176  public function testRenderWithClose(): void
177  {
178  $c = $this->getFactory()->shy('shy')->withClose(new I\Component\Button\Close());
179 
180  $expected = <<<EOT
181 <div class="il-item il-item-shy">
182  <div class="content">
183  <div class="il-item-title">shy</div>
184  <button type="button" class="close" aria-label="close">
185  <span aria-hidden="true">&times;</span>
186  </button>
187  </div>
188 </div>
189 EOT;
190 
191  $this->assertEquals(
192  $this->brutallyTrimHTML($expected),
193  $this->brutallyTrimHTML($this->getDefaultRenderer()->render($c))
194  );
195  }
196 }
button(string $caption, string $cmd)
testImplementsFactoryInterface()
Definition: ItemShyTest.php:37
standard()
description: > This is an example, of how the Notification Slate is generated by assigning Notificat...
Definition: standard.php:38
small()
description: > This can be used, when space is very scarce and the label cannot be displayed ...
Definition: small.php:34
$c
Definition: deliver.php:25
testWithDescription()
Definition: ItemShyTest.php:46
testRenderCritical()
Definition: ItemShyTest.php:94
close()
description: > Example for rendring a close glyph.
Definition: close.php:41
Test items shy.
Definition: ItemShyTest.php:30