ILIAS  release_7 Revision v7.30-3-g800a261c036
SimpleNodeTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2019 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5require_once("libs/composer/vendor/autoload.php");
6require_once(__DIR__ . "../../../../Base.php");
7
8use \ILIAS\UI\Component as C;
9use \ILIAS\UI\Implementation\Component as I;
10
15{
16 public function setUp() : void
17 {
18 $this->node_factory = new I\Tree\Node\Factory();
19 $icon_factory = new I\Symbol\Icon\Factory();
20 $this->icon = $icon_factory->standard("", '');
21 }
22
23 public function brutallyTrimHTML($html)
24 {
25 $html = str_replace(["\n", "\r", "\t"], "", $html);
26 $html = preg_replace('# {2,}#', " ", $html);
27 return trim($html);
28 }
29
30 public function testConstruction()
31 {
32 $node = $this->node_factory->simple('simple');
33 $this->assertInstanceOf(
34 "ILIAS\\UI\\Component\\Tree\\Node\\Simple",
35 $node
36 );
37 return $node;
38 }
39
40 public function testWrongConstruction()
41 {
42 $this->expectException(\ArgumentCountError::class);
43 $node = $this->node_factory->simple();
44 }
45
46 public function testConstructionWithIcon()
47 {
48 $node = $this->node_factory->simple('label', $this->icon);
49 $this->assertInstanceOf(
50 "ILIAS\\UI\\Component\\Tree\\Node\\Simple",
51 $node
52 );
53 return $node;
54 }
55
59 public function testGetLabel($node)
60 {
61 $this->assertEquals(
62 "label",
63 $node->getLabel()
64 );
65 }
66
70 public function testGetIcon($node)
71 {
72 $this->assertEquals(
73 $this->icon,
74 $node->getIcon()
75 );
76 return $node;
77 }
78
82 public function testDefaultAsyncLoading($node)
83 {
84 $this->assertFalse(
85 $node->getAsyncLoading()
86 );
87 }
88
92 public function testWithAsyncURL($node)
93 {
94 $url = 'something.de';
95 $node = $node->withAsyncURL($url);
96 $this->assertTrue(
97 $node->getAsyncLoading()
98 );
99 $this->assertEquals(
100 $url,
101 $node->getAsyncURL()
102 );
103 return $node;
104 }
105
109 public function testRendering($node)
110 {
111 $r = $this->getDefaultRenderer();
112 $html = $r->render($node);
113
114 $expected = <<<EOT
115 <li id="" class="il-tree-node node-simple" role="treeitem">
116 <span class="node-line">
117 <span class="node-label">simple</span>
118 </span>
119 </li>
120EOT;
121
122 $this->assertEquals(
123 $this->brutallyTrimHTML($expected),
124 $this->brutallyTrimHTML($html)
125 );
126 }
127
131 public function testRenderingWithAsync($node)
132 {
133 $r = $this->getDefaultRenderer();
134 $html = $r->render($node);
135
136 $expected = <<<EOT
137 <li id=""
138 class="il-tree-node node-simple expandable"
139 role="treeitem" aria-expanded="false"
140 data-async_url="something.de" data-async_loaded="false">
141 <span class="node-line">
142 <span class="node-label">simple</span>
143 </span>
144 <ul role="group"></ul>
145 </li>
146EOT;
147
148 $this->assertEquals(
149 $this->brutallyTrimHTML($expected),
150 $this->brutallyTrimHTML($html)
151 );
152 }
153
157 public function testRenderingWithIcon($node)
158 {
159 $r = $this->getDefaultRenderer();
160 $html = $r->render($node);
161
162 $expected = <<<EOT
163 <li id="" class="il-tree-node node-simple" role="treeitem">
164 <span class="node-line">
165 <span class="node-label">
166 <img class="icon small" src="./templates/default/images/icon_default.svg" alt=""/>
167 label
168 </span>
169 </span>
170 </li>
171EOT;
172
173 $this->assertEquals(
174 $this->brutallyTrimHTML($expected),
175 $this->brutallyTrimHTML($html)
176 );
177 }
178}
simple()
Definition: simple.php:5
An exception for terminatinating execution or to throw for unit testing.
Provides common functionality for UI tests.
Definition: Base.php:263
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
Tests for the SimpleNode.
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
testRendering($node)
@depends testConstruction
testGetLabel($node)
@depends testConstructionWithIcon
testRenderingWithAsync($node)
@depends testWithAsyncURL
testDefaultAsyncLoading($node)
@depends testConstruction
testWithAsyncURL($node)
@depends testConstruction
testGetIcon($node)
@depends testConstructionWithIcon
testRenderingWithIcon($node)
@depends testConstructionWithIcon
$url