ILIAS  release_8 Revision v8.24
SimpleNodeTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once("libs/composer/vendor/autoload.php");
22require_once(__DIR__ . "../../../../Base.php");
23
26
31{
32 private I\Tree\Node\Factory $node_factory;
34
35 public function setUp(): void
36 {
37 $this->node_factory = new I\Tree\Node\Factory();
38 $icon_factory = new I\Symbol\Icon\Factory();
39 $this->icon = $icon_factory->standard("", '');
40 }
41
42 public function brutallyTrimHTML(string $html): string
43 {
44 $html = str_replace(["\n", "\r", "\t"], "", $html);
45 $html = preg_replace('# {2,}#', " ", $html);
46 return trim($html);
47 }
48
49 public function testConstruction(): C\Tree\Node\Simple
50 {
51 $node = $this->node_factory->simple('simple');
52 $this->assertInstanceOf(
53 "ILIAS\\UI\\Component\\Tree\\Node\\Simple",
54 $node
55 );
56 return $node;
57 }
58
59 public function testWrongConstruction(): void
60 {
61 $this->expectException(ArgumentCountError::class);
62 $this->node_factory->simple();
63 }
64
65 public function testConstructionWithIcon(): C\Tree\Node\Simple
66 {
67 $node = $this->node_factory->simple('label', $this->icon);
68 $this->assertInstanceOf(
69 "ILIAS\\UI\\Component\\Tree\\Node\\Simple",
70 $node
71 );
72 return $node;
73 }
74 public function testConstructionWithIconAndDifferentLabels(): C\Tree\Node\Simple
75 {
76 $this->icon->setLabel('Different Icon Label');
77 $node = $this->node_factory->simple('label', $this->icon);
78 $this->assertInstanceOf(
79 "ILIAS\\UI\\Component\\Tree\\Node\\Simple",
80 $node
81 );
82 return $node;
83 }
84
88 public function testGetDifferentLabels(C\Tree\Node\Simple $node): void
89 {
90 $this->assertNotEquals($this->icon->getLabel(), $node->getLabel());
91 }
92
96 public function testGetLabel(C\Tree\Node\Simple $node): void
97 {
98 $this->assertEquals("label", $node->getLabel());
99 }
100
104 public function testGetIcon(C\Tree\Node\Simple $node): C\Tree\Node\Simple
105 {
106 $this->assertEquals($this->icon, $node->getIcon());
107 return $node;
108 }
109
113 public function testDefaultAsyncLoading(C\Tree\Node\Simple $node): void
114 {
115 $this->assertFalse($node->getAsyncLoading());
116 }
117
121 public function testWithAsyncURL(C\Tree\Node\Simple $node): C\Tree\Node\Simple
122 {
123 $url = 'something.de';
124 $node = $node->withAsyncURL($url);
125 $this->assertTrue($node->getAsyncLoading());
126 $this->assertEquals($url, $node->getAsyncURL());
127 return $node;
128 }
129
133 public function testRendering(C\Tree\Node\Simple $node): void
134 {
135 $r = $this->getDefaultRenderer();
136 $html = $r->render($node);
137
138 $expected = <<<EOT
139 <li id="" class="il-tree-node node-simple" role="treeitem">
140 <span class="node-line">
141 <span class="node-label">simple</span>
142 </span>
143 </li>
144EOT;
145
146 $this->assertEquals(
147 $this->brutallyTrimHTML($expected),
148 $this->brutallyTrimHTML($html)
149 );
150 }
151
155 public function testRenderingWithAsync(C\Tree\Node\Simple $node): void
156 {
157 $r = $this->getDefaultRenderer();
158 $html = $r->render($node);
159
160 $expected = <<<EOT
161 <li id=""
162 class="il-tree-node node-simple expandable"
163 role="treeitem" aria-expanded="false"
164 data-async_url="something.de" data-async_loaded="false">
165 <span class="node-line">
166 <span class="node-label">simple</span>
167 </span>
168 <ul role="group"></ul>
169 </li>
170EOT;
171
172 $this->assertEquals(
173 $this->brutallyTrimHTML($expected),
174 $this->brutallyTrimHTML($html)
175 );
176 }
177
181 public function testRenderingWithIcon(C\Tree\Node\Simple $node): void
182 {
183 $r = $this->getDefaultRenderer();
184 $html = $r->render($node);
185
186 $expected = <<<EOT
187 <li id="" class="il-tree-node node-simple" role="treeitem">
188 <span class="node-line">
189 <span class="node-label">
190 <img class="icon small" src="./templates/default/images/icon_default.svg" alt=""/>
191 label
192 </span>
193 </span>
194 </li>
195EOT;
196
197 $this->assertEquals(
198 $this->brutallyTrimHTML($expected),
199 $this->brutallyTrimHTML($html)
200 );
201 }
209 public function testRenderingWithIconAndAltAttribute(C\Tree\Node\Simple $node): void
210 {
211 $r = $this->getDefaultRenderer();
212 $html = $r->render($node);
213
214 $expected = <<<EOT
215 <li id="" class="il-tree-node node-simple" role="treeitem">
216 <span class="node-line">
217 <span class="node-label">
218 <img class="icon small" src="./templates/default/images/icon_default.svg" alt="Different Icon Label"/>
219 label
220 </span>
221 </span>
222 </li>
223EOT;
224
225 $this->assertEquals(
226 $this->brutallyTrimHTML($expected),
227 $this->brutallyTrimHTML($html)
228 );
229 }
230}
Provides common functionality for UI tests.
Definition: Base.php:299
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
Tests for the SimpleNode.
testRenderingWithIconAndAltAttribute(C\Tree\Node\Simple $node)
This test is successfull if the icon label differs from the node label.
testWithAsyncURL(C\Tree\Node\Simple $node)
@depends testConstruction
testRenderingWithIcon(C\Tree\Node\Simple $node)
@depends testConstructionWithIcon
testGetIcon(C\Tree\Node\Simple $node)
@depends testConstructionWithIcon
testGetDifferentLabels(C\Tree\Node\Simple $node)
@depends testConstructionWithIconAndDifferentLabels
testRendering(C\Tree\Node\Simple $node)
@depends testConstruction
testConstructionWithIconAndDifferentLabels()
I Tree Node Factory $node_factory
C Symbol Icon Standard $icon
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
testRenderingWithAsync(C\Tree\Node\Simple $node)
@depends testWithAsyncURL
testDefaultAsyncLoading(C\Tree\Node\Simple $node)
@depends testConstruction
testGetLabel(C\Tree\Node\Simple $node)
@depends testConstructionWithIcon
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...
$url