ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
SimpleNodeTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once("vendor/composer/vendor/autoload.php");
22 require_once(__DIR__ . "../../../../Base.php");
23 
24 use ILIAS\UI\Component as C;
26 
31 {
32  private I\Tree\Node\Factory $node_factory;
33  private C\Symbol\Icon\Standard $icon;
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 
85  #[\PHPUnit\Framework\Attributes\Depends('testConstructionWithIconAndDifferentLabels')]
86  public function testGetDifferentLabels(C\Tree\Node\Simple $node): void
87  {
88  $this->assertNotEquals($this->icon->getLabel(), $node->getLabel());
89  }
90 
91  #[\PHPUnit\Framework\Attributes\Depends('testConstructionWithIcon')]
92  public function testGetLabel(C\Tree\Node\Simple $node): void
93  {
94  $this->assertEquals("label", $node->getLabel());
95  }
96 
97  #[\PHPUnit\Framework\Attributes\Depends('testConstructionWithIcon')]
98  public function testGetIcon(C\Tree\Node\Simple $node): C\Tree\Node\Simple
99  {
100  $this->assertEquals($this->icon, $node->getIcon());
101  return $node;
102  }
103 
104  #[\PHPUnit\Framework\Attributes\Depends('testConstruction')]
105  public function testDefaultAsyncLoading(C\Tree\Node\Simple $node): void
106  {
107  $this->assertFalse($node->getAsyncLoading());
108  }
109 
110  #[\PHPUnit\Framework\Attributes\Depends('testConstruction')]
111  public function testWithAsyncURL(C\Tree\Node\Simple $node): C\Tree\Node\Simple
112  {
113  $url = 'something.de';
114  $node = $node->withAsyncURL($url);
115  $this->assertTrue($node->getAsyncLoading());
116  $this->assertEquals($url, $node->getAsyncURL());
117  return $node;
118  }
119 
120  #[\PHPUnit\Framework\Attributes\Depends('testConstruction')]
121  public function testRendering(C\Tree\Node\Simple $node): void
122  {
123  $r = $this->getDefaultRenderer();
124  $html = $r->render($node);
125 
126  $expected = <<<EOT
127  <li class="c-tree__node c-tree__node--simple" role="treeitem">
128  <span class="c-tree__node__line">
129  <span class="c-tree__node__label">simple</span>
130  </span>
131  </li>
132 EOT;
133 
134  $this->assertEquals(
135  $this->brutallyTrimHTML($expected),
136  $this->brutallyTrimHTML($html)
137  );
138  }
139 
140  #[\PHPUnit\Framework\Attributes\Depends('testWithAsyncURL')]
141  public function testRenderingWithAsync(C\Tree\Node\Simple $node): void
142  {
143  $r = $this->getDefaultRenderer();
144  $html = $r->render($node);
145 
146  $expected = <<<EOT
147  <li class="c-tree__node c-tree__node--simple expandable"
148  role="treeitem" aria-expanded="false"
149  data-async_url="something.de" data-async_loaded="false">
150  <span class="c-tree__node__line">
151  <span class="c-tree__node__label">simple</span>
152  </span>
153  <ul role="group"></ul>
154  </li>
155 EOT;
156 
157  $this->assertEquals(
158  $this->brutallyTrimHTML($expected),
159  $this->brutallyTrimHTML($html)
160  );
161  }
162 
163  #[\PHPUnit\Framework\Attributes\Depends('testConstructionWithIcon')]
164  public function testRenderingWithIcon(C\Tree\Node\Simple $node): void
165  {
166  $r = $this->getDefaultRenderer();
167  $html = $r->render($node);
168 
169  $expected = <<<EOT
170  <li class="c-tree__node c-tree__node--simple" role="treeitem">
171  <span class="c-tree__node__line">
172  <span class="c-tree__node__label">
173  <img class="icon small" src="./assets/images/standard/icon_default.svg" alt=""/>
174  label
175  </span>
176  </span>
177  </li>
178 EOT;
179 
180  $this->assertEquals(
181  $this->brutallyTrimHTML($expected),
182  $this->brutallyTrimHTML($html)
183  );
184  }
190  #[\PHPUnit\Framework\Attributes\Depends('testConstructionWithIconAndDifferentLabels')]
191  public function testRenderingWithIconAndAltAttribute(C\Tree\Node\Simple $node): void
192  {
193  $r = $this->getDefaultRenderer();
194  $html = $r->render($node);
195 
196  $expected = <<<EOT
197  <li class="c-tree__node c-tree__node--simple" role="treeitem">
198  <span class="c-tree__node__line">
199  <span class="c-tree__node__label">
200  <img class="icon small" src="./assets/images/standard/icon_default.svg" alt="Different Icon Label"/>
201  label
202  </span>
203  </span>
204  </li>
205 EOT;
206 
207  $this->assertEquals(
208  $this->brutallyTrimHTML($expected),
209  $this->brutallyTrimHTML($html)
210  );
211  }
212 }
testRendering(C\Tree\Node\Simple $node)
testGetLabel(C\Tree\Node\Simple $node)
simple()
description: > This example show how the UI-Elements itself looks like.
Definition: simple.php:37
testConstructionWithIconAndDifferentLabels()
Tests for the SimpleNode.
I Tree Node Factory $node_factory
testGetDifferentLabels(C\Tree\Node\Simple $node)
$url
Definition: shib_logout.php:68
C Symbol Icon Standard $icon
testRenderingWithAsync(C\Tree\Node\Simple $node)
testWithAsyncURL(C\Tree\Node\Simple $node)
testGetIcon(C\Tree\Node\Simple $node)
testDefaultAsyncLoading(C\Tree\Node\Simple $node)
brutallyTrimHTML(string $html)
testRenderingWithIcon(C\Tree\Node\Simple $node)
testRenderingWithIconAndAltAttribute(C\Tree\Node\Simple $node)
This test is successfull if the icon label differs from the node label.
$r