ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
5 require_once("libs/composer/vendor/autoload.php");
6 require_once(__DIR__ . "../../../../Base.php");
7 
8 use \ILIAS\UI\Component as C;
9 use \ILIAS\UI\Implementation\Component as I;
14 
19 {
23  private $node_factory;
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="none">
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>
59 EOT;
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="none">
76  <span class="node-line">
77  <span class="node-label"><div class="icon small" aria-label=""></div>My Label</span>
78  <span class="node-byline">This is my byline</span>
79  </span>
80  </li>
81 EOT;
82 
83  $this->assertEquals(
84  $this->brutallyTrimHTML($expected),
85  $this->brutallyTrimHTML($html)
86  );
87  }
88 
89  public function testRenderingWithAsync()
90  {
91  $node = $this->node_factory->bylined('My Label', 'This is my byline');
92  $node = $node->withAsyncURL('something.de');
93 
94  $r = $this->getDefaultRenderer();
95  $html = $r->render($node);
96 
97  $expected = <<<EOT
98  <li id=""
99  class="il-tree-node node-simple expandable"
100  role="treeitem" aria-expanded="false"
101  data-async_url="something.de" data-async_loaded="false">
102  <span class="node-line">
103  <span class="node-label">My Label</span>
104  <span class="node-byline">This is my byline</span>
105  </span>
106  </li>
107 EOT;
108 
109  $this->assertEquals(
110  $this->brutallyTrimHTML($expected),
111  $this->brutallyTrimHTML($html)
112  );
113  }
114 
115  public function getDefaultRenderer(JavaScriptBinding $js_binding = null)
116  {
117  $ui_factory = $this->getUIFactory();
118  $tpl_factory = $this->getTemplateFactory();
119  $resource_registry = $this->getResourceRegistry();
120  $lng = $this->getLanguage();
121  if (!$js_binding) {
122  $js_binding = $this->getJavaScriptBinding();
123  }
124 
125  $languageMock = $this->getMockBuilder('ilLanguage')
126  ->disableOriginalConstructor()
127  ->getMock();
128 
129  $defaultRendererFactory = new DefaultRendererFactory(
130  $ui_factory,
131  $tpl_factory,
132  $lng,
133  $js_binding,
134  new ILIAS\Refinery\Factory(new ILIAS\Data\Factory(), $languageMock)
135  );
136 
137  $glyphRendererFactory = new GlyphRendererFactory(
138  $ui_factory,
139  $tpl_factory,
140  $lng,
141  $js_binding,
142  new ILIAS\Refinery\Factory(new ILIAS\Data\Factory(), $languageMock)
143  );
144 
145  $fieldRendererFactory = new FieldRendererFactory(
146  $ui_factory,
147  $tpl_factory,
148  $lng,
149  $js_binding,
150  new ILIAS\Refinery\Factory(new ILIAS\Data\Factory(), $languageMock)
151  );
152 
153  $fsLoader = new \ILIAS\UI\Implementation\Render\FSLoader(
154  $defaultRendererFactory,
155  $glyphRendererFactory,
156  $fieldRendererFactory
157  );
158 
159  $loaderResourceRegistryWrapper = new \ILIAS\UI\Implementation\Render\LoaderResourceRegistryWrapper(
160  $resource_registry,
161  $fsLoader
162  );
163 
164  $component_renderer_loader
165  = new \ILIAS\UI\Implementation\Render\LoaderCachingWrapper(
166  $loaderResourceRegistryWrapper
167  );
168  return new TestDefaultRenderer($component_renderer_loader);
169  }
170 }
Class ChatMainBarProvider .
getJavaScriptBinding()
Definition: Base.php:256
Provides common functionality for UI tests.
Definition: Base.php:224
$lng
Provides methods to interface with javascript.
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:346
getTemplateFactory()
Definition: Base.php:241
getResourceRegistry()
Definition: Base.php:246
Tests for the SimpleNode.
getDefaultRenderer(JavaScriptBinding $js_binding=null)