ILIAS  release_8 Revision v8.24
CombinedSlateTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once("libs/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../../Base.php");
23
27
32{
34 protected I\Button\Factory $button_factory;
35 protected I\Divider\Factory $divider_factory;
36 protected I\Symbol\Icon\Factory $icon_factory;
37
38 public function setUp(): void
39 {
40 $this->sig_gen = new I\SignalGenerator();
41 $this->button_factory = new I\Button\Factory();
42 $this->divider_factory = new I\Divider\Factory();
43 $this->icon_factory = new I\Symbol\Icon\Factory();
44 }
45
46 public function getUIFactory(): NoUIFactory
47 {
48 $factory = new class () extends NoUIFactory {
50
51 public function button(): C\Button\Factory
52 {
54 }
55 public function glyph(): C\Symbol\Glyph\Factory
56 {
57 return new I\Symbol\Glyph\Factory();
58 }
59
60 public function divider(): C\Divider\Factory
61 {
62 return new I\Divider\Factory();
63 }
64
65 public function mainControls(): C\MainControls\Factory
66 {
67 return new I\MainControls\Factory($this->sig_gen);
68 }
69 };
70 $factory->button_factory = $this->button_factory;
71 $factory->sig_gen = $this->sig_gen;
72 return $factory;
73 }
74
75 public function testRendering(): void
76 {
77 $name = 'name';
78 $icon = $this->icon_factory->custom('', '');
79 $slate = new Combined($this->sig_gen, $name, $icon);
80
81 $r = $this->getDefaultRenderer();
82 $html = $r->render($slate);
83
84 $expected = '<div class="il-maincontrols-slate disengaged" id="id_1"><div class="il-maincontrols-slate-content" data-replace-marker="content"></div></div>';
85 $this->assertEquals(
86 $expected,
87 $this->brutallyTrimHTML($html)
88 );
89 }
90
91 public function testRenderingWithAriaRole(): void
92 {
93 $name = 'name';
94 $icon = $this->icon_factory->custom('', '');
95 $slate = new Combined($this->sig_gen, $name, $icon);
96 $slate = $slate->withAriaRole(I\MainControls\Slate\Slate::MENU);
97
98 $r = $this->getDefaultRenderer();
99 $html = $r->render($slate);
100
101 $expected = '<div class="il-maincontrols-slate disengaged" id="id_1" role="menu"><div class="il-maincontrols-slate-content" data-replace-marker="content"></div></div>';
102 $this->assertEquals(
103 $expected,
104 $this->brutallyTrimHTML($html)
105 );
106 }
107
108 public function testRenderingWithSubDivider(): void
109 {
110 $name = 'name';
111 $icon = $this->icon_factory->custom('', '');
112 $subdivider = new I\Divider\Horizontal();
113 $subdivider_with_text = new I\Divider\Horizontal();
114 $subdivider_with_text = $subdivider_with_text->withLabel('Title');
115 $slate = new Combined($this->sig_gen, $name, $icon);
116 $slate = $slate
117 ->withAdditionalEntry($subdivider_with_text)
118 ->withAdditionalEntry($subdivider);
119
120 $r = $this->getDefaultRenderer();
121 $html = $r->render($slate);
122
123 $expected = <<<EOT
124 <div class="il-maincontrols-slate disengaged" id="id_1">
125 <div class="il-maincontrols-slate-content" data-replace-marker="content">
126 <ul>
127 <li><hr class="il-divider-with-label" /><h4 class="il-divider">Title</h4></li>
128 <li><hr /></li>
129 </ul>
130 </div>
131 </div>
132EOT;
133 $this->assertEquals(
134 $this->brutallyTrimHTML($expected),
135 $this->brutallyTrimHTML($html)
136 );
137 }
138
140 {
141 $icon = $this->icon_factory->custom('', '');
142 $subslate = new Combined($this->sig_gen, 'subslate_name', $icon);
143 $subbutton = $this->button_factory->bulky($icon, 'button_name', '');
144 $slate = new Combined($this->sig_gen, 'slate_name', $icon);
145 $slate = $slate
146 ->withAdditionalEntry($subslate)
147 ->withAdditionalEntry($subbutton);
148
149 $r = $this->getDefaultRenderer();
150 $html = $r->render($slate);
151
152 $expected = <<<EOT
153 <div class="il-maincontrols-slate disengaged" id="id_3">
154 <div class="il-maincontrols-slate-content" data-replace-marker="content">
155 <ul>
156 <li>
157 <button class="btn btn-bulky" id="id_1">
158 <img class="icon custom small" src="" alt=""/>
159 <span class="bulky-label">subslate_name</span>
160 </button>
161 <div class="il-maincontrols-slate disengaged" id="id_2">
162 <div class="il-maincontrols-slate-content" data-replace-marker="content"></div>
163 </div>
164 </li>
165 <li>
166 <button class="btn btn-bulky" data-action="">
167 <img class="icon custom small" src="" alt=""/>
168 <span class="bulky-label">button_name</span>
169 </button>
170 </li>
171 </ul>
172 </div>
173 </div>
174EOT;
175 $this->assertEquals(
176 $this->brutallyTrimHTML($expected),
177 $this->brutallyTrimHTML($html)
178 );
179 }
180}
Tests for the Slate.
I SignalGenerator $sig_gen
I Button Factory $button_factory
I Symbol Icon Factory $icon_factory
I Divider Factory $divider_factory
Provides common functionality for UI tests.
Definition: Base.php:299
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:444
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
Title class.
Definition: Title.php:27
$factory
Definition: metadata.php:75
if($format !==null) $name
Definition: metadata.php:247
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...