ILIAS  release_7 Revision v7.30-3-g800a261c036
BylineNodeTest.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;
14
19{
24
28 private $icon;
29
30 public function setUp() : void
31 {
32 $this->node_factory = new I\Tree\Node\Factory();
33 $icon_factory = new I\Symbol\Icon\Factory();
34 $this->icon = $icon_factory->standard("", '');
35 }
36
37 public function testCreateBylineNode()
38 {
39 $node = $this->node_factory->bylined('My Label', 'This is my byline', $this->icon);
40 $this->assertEquals('My Label', $node->getLabel());
41 $this->assertEquals('This is my byline', $node->getByline());
42 $this->assertEquals($this->icon, $node->getIcon());
43 }
44
45 public function testRendering()
46 {
47 $node = $this->node_factory->bylined('My Label', 'This is my byline');
48
49 $r = $this->getDefaultRenderer();
50 $html = $r->render($node);
51
52 $expected = <<<EOT
53 <li id="" class="il-tree-node node-simple" role="treeitem">
54 <span class="node-line">
55 <span class="node-label">My Label</span>
56 <span class="node-byline">This is my byline</span>
57 </span>
58 </li>
59EOT;
60
61 $this->assertEquals(
62 $this->brutallyTrimHTML($expected),
63 $this->brutallyTrimHTML($html)
64 );
65 }
66
67 public function testRenderingWithIcon()
68 {
69 $node = $this->node_factory->bylined('My Label', 'This is my byline', $this->icon);
70
71 $r = $this->getDefaultRenderer();
72 $html = $r->render($node);
73
74 $expected = <<<EOT
75 <li id="" class="il-tree-node node-simple" role="treeitem">
76 <span class="node-line">
77 <span class="node-label">
78 <img class="icon small" src="./templates/default/images/icon_default.svg" alt=""/>
79 My Label
80 </span>
81 <span class="node-byline">This is my byline</span>
82 </span>
83 </li>
84EOT;
85
86 $this->assertEquals(
87 $this->brutallyTrimHTML($expected),
88 $this->brutallyTrimHTML($html)
89 );
90 }
91
92 public function testRenderingWithAsync()
93 {
94 $node = $this->node_factory->bylined('My Label', 'This is my byline');
95 $node = $node->withAsyncURL('something.de');
96
97 $r = $this->getDefaultRenderer();
98 $html = $r->render($node);
99
100 $expected = <<<EOT
101 <li id=""
102 class="il-tree-node node-simple expandable"
103 role="treeitem" aria-expanded="false"
104 data-async_url="something.de" data-async_loaded="false">
105 <span class="node-line">
106 <span class="node-label">My Label</span>
107 <span class="node-byline">This is my byline</span>
108 </span>
109 <ul role="group"></ul>
110 </li>
111EOT;
112
113 $this->assertEquals(
114 $this->brutallyTrimHTML($expected),
115 $this->brutallyTrimHTML($html)
116 );
117 }
118
119 public function testRenderingExpanded()
120 {
121 $node = $this->node_factory->bylined('My Label', 'This is my byline');
122 $node = $node->withAsyncURL('something.de')->withExpanded(true);
123
124 $r = $this->getDefaultRenderer();
125 $html = $r->render($node);
126
127 $expected = <<<EOT
128 <li id=""
129 class="il-tree-node node-simple expandable"
130 role="treeitem" aria-expanded="true"
131 data-async_url="something.de" data-async_loaded="false">
132 <span class="node-line">
133 <span class="node-label">My Label</span>
134 <span class="node-byline">This is my byline</span>
135 </span>
136 <ul role="group"></ul>
137 </li>
138EOT;
139
140 $this->assertEquals(
141 $this->brutallyTrimHTML($expected),
142 $this->brutallyTrimHTML($html)
143 );
144 }
145}
Tests for the SimpleNode.
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
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392
Provides methods to interface with javascript.