ILIAS  release_8 Revision v8.24
ExpandableTreeTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21require_once("libs/composer/vendor/autoload.php");
22require_once(__DIR__ . "../../../Base.php");
23
26
28{
29 protected string $label;
30 protected array $children;
31
32 public function __construct(string $label, array $children = [])
33 {
34 $this->label = $label;
35 $this->children = $children;
36 }
37 public function getLabel(): string
38 {
39 return $this->label;
40 }
41 public function getChildren(): array
42 {
43 return $this->children;
44 }
45}
46
48{
49 public function getChildren($record, $environment = null): array
50 {
51 return $record->getChildren();
52 }
53
54 public function build(
55 C\Tree\Node\Factory $factory,
56 $record,
57 $environment = null
58 ): C\Tree\Node\Node {
59 return $factory->simple($record->getLabel());
60 }
61}
62
67{
68 protected C\Tree\Tree $tree;
69
70 public function getUIFactory(): NoUIFactory
71 {
72 return new class () extends NoUIFactory {
73 public function tree(): C\Tree\Factory
74 {
75 return new I\Tree\Factory();
76 }
77 };
78 }
79
80 public function setUp(): void
81 {
82 $n11 = new DataNode('1.1');
83 $n12 = new DataNode('1.2', array(new DataNode('1.2.1')));
84 $n1 = new DataNode('1', [$n11, $n12]);
85 $n2 = new DataNode('2');
86 $data = [$n1, $n2];
87
88 $label = "label";
89 $recursion = new Recursion();
90 $f = $this->getUIFactory();
91 $this->tree = $f->tree()->expandable($label, $recursion)
92 ->withData($data);
93 }
94
95 public function brutallyTrimHTML(string $html): string
96 {
97 $html = str_replace(["\n", "\r", "\t"], "", $html);
98 $html = preg_replace('# {2,}#', " ", $html);
99 return trim($html);
100 }
101
102 public function testRendering(): void
103 {
104 $r = $this->getDefaultRenderer();
105 $html = $r->render($this->tree);
106
107 $expected = '<ul id="id_1" class="il-tree" role="tree" aria-label="label">' . $this->getInnerTreePart() . '</ul>';
108
109 $this->assertEquals(
110 $this->brutallyTrimHTML($expected),
111 $this->brutallyTrimHTML($html)
112 );
113 }
114
115 public function testRenderingAsSubTree(): void
116 {
117 $r = $this->getDefaultRenderer();
118 $html = $r->render($this->tree->withIsSubTree(true));
119
120 $expected = $this->getInnerTreePart();
121
122 $this->assertEquals(
123 $this->brutallyTrimHTML($expected),
124 $this->brutallyTrimHTML($html)
125 );
126 }
127
128 protected function getInnerTreePart(): string
129 {
130 return '<li id="" class="il-tree-node node-simple expandable" role="treeitem" aria-expanded="false">
131 <span class="node-line"><span class="node-label">1</span></span>
132
133 <ul role="group">
134 <li id="" class="il-tree-node node-simple" role="treeitem">
135 <span class="node-line"><span class="node-label">1.1</span></span>
136 </li>
137 <li id="" class="il-tree-node node-simple expandable" role="treeitem" aria-expanded="false">
138 <span class="node-line"><span class="node-label">1.2</span></span>
139
140 <ul role="group">
141 <li id="" class="il-tree-node node-simple" role="treeitem">
142 <span class="node-line"><span class="node-label">1.2.1</span></span>
143 </li>
144 </ul>
145 </li>
146 </ul>
147 </li>
148 <li id="" class="il-tree-node node-simple" role="treeitem">
149 <span class="node-line"><span class="node-label">2</span></span>
150 </li>';
151 }
152}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(string $label, array $children=[])
Tests for the Expandable Tree.
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Provides common functionality for UI tests.
Definition: Base.php:299
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
build(C\Tree\Node\Factory $factory, $record, $environment=null)
getChildren($record, $environment=null)
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
$factory
Definition: metadata.php:75
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...