ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
MainBarTest Class Reference

Tests for the Main Bar. More...

+ Inheritance diagram for MainBarTest:
+ Collaboration diagram for MainBarTest:

Public Member Functions

 setUp ()
 
 testConstruction ()
 
 testAddEntry ()
 
 testDisallowedEntry ()
 
 testDouplicateIdEntry ()
 
 testDisallowedToolEntry ()
 
 testAddToolEntryWithoutToolsButton ()
 
 testAddToolEntry ()
 
 testDouplicateIdToolEntry ()
 
 testActive ($mb)
 @depends testAddEntry More...
 
 testWithInvalidActive ()
 
 testSignalsPresent ()
 
 getUIFactory ()
 
 brutallyTrimHTML ($html)
 A more radical version of normalizeHTML. More...
 
 testRendering ()
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getRefinery ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null)
 
 getDecoratedRenderer (Renderer $default)
 
 normalizeHTML ($html)
 
 assertHTMLEquals ($expected_html_as_string, $html_as_string)
 

Protected Member Functions

 getButton ()
 
 getLink ()
 
 getSlate ()
 
 brutallyTrimHTML ($html)
 A more radical version of normalizeHTML. More...
 

Detailed Description

Tests for the Main Bar.

Definition at line 16 of file MainBarTest.php.

Member Function Documentation

◆ brutallyTrimHTML()

MainBarTest::brutallyTrimHTML (   $html)

A more radical version of normalizeHTML.

Use if hard to tackle issues occur by asserting due string outputs produce an equal DOM

Parameters
$html
Returns
string

Reimplemented from ILIAS_UI_TestBase.

Definition at line 196 of file MainBarTest.php.

197 {
198 $html = str_replace(["\n", "\r", "\t"], "", $html);
199 $html = preg_replace('# {2,}#', " ", $html);
200 $html = preg_replace('/<!--(.|\s)*?-->/', '', $html);
201 return trim($html);
202 }

Referenced by testRendering().

+ Here is the caller graph for this function:

◆ getButton()

MainBarTest::getButton ( )
protected

Definition at line 47 of file MainBarTest.php.

48 {
49 $symbol = $this->icon_factory->custom('', '');
50 return $this->button_factory->bulky($symbol, 'TestEntry', '#');
51 }

Referenced by testAddEntry(), testAddToolEntry(), testDouplicateIdEntry(), testDouplicateIdToolEntry(), and testRendering().

+ Here is the caller graph for this function:

◆ getLink()

MainBarTest::getLink ( )
protected

Definition at line 53 of file MainBarTest.php.

54 {
55 $symbol = $this->icon_factory->custom('', '');
56 $target = new \ILIAS\Data\URI("http://www.ilias.de");
57 return $this->link_factory->bulky($symbol, 'TestEntry', $target);
58 }

Referenced by testAddEntry().

+ Here is the caller graph for this function:

◆ getSlate()

MainBarTest::getSlate ( )
protected

Definition at line 60 of file MainBarTest.php.

61 {
62 $mock = $this->getMockBuilder(Legacy::class)
63 ->disableOriginalConstructor()
64 ->setMethods(["transformToLegacyComponent"])
65 ->getMock();
66
67 $mock->method('transformToLegacyComponent')->willReturn('content');
68 return $mock;
69 }

Referenced by testAddToolEntry(), testAddToolEntryWithoutToolsButton(), and testDouplicateIdToolEntry().

+ Here is the caller graph for this function:

◆ getUIFactory()

MainBarTest::getUIFactory ( )

Reimplemented from ILIAS_UI_TestBase.

Definition at line 159 of file MainBarTest.php.

160 {
161 $factory = new class extends NoUIFactory {
162 public function button()
163 {
164 return $this->button_factory;
165 }
166 public function symbol() : C\Symbol\Factory
167 {
168 $f_icon = new I\Symbol\Icon\Factory();
169 $f_glyph = new I\Symbol\Glyph\Factory();
170 $f_avatar = new I\Symbol\Avatar\Factory();
171
172 return new I\Symbol\Factory($f_icon, $f_glyph, $f_avatar);
173 }
174 public function mainControls() : C\MainControls\Factory
175 {
176 $sig_gen = new I\SignalGenerator();
177 $counter_factory = new I\Counter\Factory();
178 $symbol_factory = new I\Symbol\Factory(
179 new I\Symbol\Icon\Factory(),
180 new I\Symbol\Glyph\Factory(),
181 new I\Symbol\Avatar\Factory()
182 );
183 $slate_factory = new I\MainControls\Slate\Factory($sig_gen, $counter_factory, $symbol_factory);
184 return new I\MainControls\Factory($sig_gen, $slate_factory);
185 }
186 public function legacy($legacy)
187 {
188 $sig_gen = new I\SignalGenerator();
189 return new I\Legacy\Legacy($legacy, $sig_gen);
190 }
191 };
192 $factory->button_factory = $this->button_factory;
193 return $factory;
194 }
legacy()
Definition: legacy.php:3
$factory
Definition: metadata.php:58

References $factory, and legacy().

+ Here is the call graph for this function:

◆ setUp()

MainBarTest::setUp ( )

Reimplemented from ILIAS_UI_TestBase.

Definition at line 18 of file MainBarTest.php.

18 : void
19 {
20 $sig_gen = new I\SignalGenerator();
21 $this->button_factory = new I\Button\Factory($sig_gen);
22 $this->link_factory = new I\Link\Factory();
23 $this->icon_factory = new I\Symbol\Icon\Factory();
24 $counter_factory = new I\Counter\Factory();
25 $slate_factory = new I\MainControls\Slate\Factory(
26 $sig_gen,
27 $counter_factory,
28 new I\Symbol\Factory(
29 new I\Symbol\Icon\Factory(),
30 new I\Symbol\Glyph\Factory(),
31 new I\Symbol\Avatar\Factory()
32 )
33 );
34 $this->factory = new I\MainControls\Factory($sig_gen, $slate_factory);
35
36 $this->mainbar = $this->factory->mainBar();
37 }
mainbar()
Definition: mainbar.php:2

References mainbar().

+ Here is the call graph for this function:

◆ testActive()

MainBarTest::testActive (   $mb)

@depends testAddEntry

Definition at line 138 of file MainBarTest.php.

139 {
140 $mb = $mb->withActive('testbtn');
141 $this->assertEquals('testbtn', $mb->getActive());
142 }

◆ testAddEntry()

MainBarTest::testAddEntry ( )

Definition at line 71 of file MainBarTest.php.

72 {
73 $btn = $this->getButton();
74 $lnk = $this->getLink();
75 $mb = $this->mainbar
76 ->withAdditionalEntry('testbtn', $btn)
77 ->withAdditionalEntry('testlnk', $lnk);
78
79 $entries = $mb->getEntries();
80 $expected = [
81 'testbtn' => $btn,
82 'testlnk' => $lnk,
83 ];
84 $this->assertEquals($expected, $entries);
85 return $mb;
86 }

References getButton(), getLink(), and mainbar().

+ Here is the call graph for this function:

◆ testAddToolEntry()

MainBarTest::testAddToolEntry ( )

Definition at line 115 of file MainBarTest.php.

116 {
117 $slate = $this->getSlate();
118 $mb = $this->mainbar
119 ->withToolsButton($this->getButton())
120 ->withAdditionalToolEntry('test', $slate);
121 $entries = $mb->getToolEntries();
122 $this->assertEquals($slate, $entries['test']);
123 }

References getButton(), getSlate(), and mainbar().

+ Here is the call graph for this function:

◆ testAddToolEntryWithoutToolsButton()

MainBarTest::testAddToolEntryWithoutToolsButton ( )

Definition at line 109 of file MainBarTest.php.

110 {
111 $this->expectException(\LogicException::class);
112 $mb = $this->mainbar->withAdditionalToolEntry('test', $this->getSlate());
113 }

References getSlate(), and mainbar().

+ Here is the call graph for this function:

◆ testConstruction()

MainBarTest::testConstruction ( )

Definition at line 39 of file MainBarTest.php.

40 {
41 $this->assertInstanceOf(
42 "ILIAS\\UI\\Component\\MainControls\\MainBar",
43 $this->mainbar
44 );
45 }

References mainbar().

+ Here is the call graph for this function:

◆ testDisallowedEntry()

MainBarTest::testDisallowedEntry ( )

Definition at line 88 of file MainBarTest.php.

89 {
90 $this->expectException(\InvalidArgumentException::class);
91 $mb = $this->mainbar->withAdditionalEntry('test', 'wrong_param');
92 }

References mainbar().

+ Here is the call graph for this function:

◆ testDisallowedToolEntry()

MainBarTest::testDisallowedToolEntry ( )

Definition at line 103 of file MainBarTest.php.

104 {
105 $this->expectException(\TypeError::class);
106 $mb = $this->mainbar->withAdditionalToolEntry('test', 'wrong_param');
107 }

References mainbar().

+ Here is the call graph for this function:

◆ testDouplicateIdEntry()

MainBarTest::testDouplicateIdEntry ( )

Definition at line 94 of file MainBarTest.php.

95 {
96 $this->expectException(\InvalidArgumentException::class);
97 $btn = $this->getButton();
98 $mb = $this->mainbar
99 ->withAdditionalEntry('test', $btn)
100 ->withAdditionalEntry('test', $btn);
101 }

References getButton(), and mainbar().

+ Here is the call graph for this function:

◆ testDouplicateIdToolEntry()

MainBarTest::testDouplicateIdToolEntry ( )

Definition at line 125 of file MainBarTest.php.

126 {
127 $this->expectException(\InvalidArgumentException::class);
128 $btn = $this->getButton();
129 $slate = $this->getSlate();
130 $mb = $this->mainbar->withToolsButton($btn)
131 ->withAdditionalToolEntry('test', $slate)
132 ->withAdditionalToolEntry('test', $slate);
133 }

References getButton(), getSlate(), and mainbar().

+ Here is the call graph for this function:

◆ testRendering()

MainBarTest::testRendering ( )

Definition at line 204 of file MainBarTest.php.

205 {
206 $r = $this->getDefaultRenderer();
207 $icon = $this->icon_factory->custom('', '');
208
209 $sf = $this->factory->slate();
210 $slate = $sf->combined('1', $icon, '')
211 ->withAdditionalEntry(
212 $sf->combined('1.1', $icon, '')
213 ->withAdditionalEntry(
214 $sf->combined('1.1.1', $icon, '')
215 )
216 );
217
218 $mb = $this->factory->mainBar()
219 ->withMoreButton(
220 $this->button_factory->bulky($icon, 'more', '')
221 )
222 ->withAdditionalEntry('test1', $this->getButton())
223 ->withAdditionalEntry('test2', $this->getButton())
224 ->withAdditionalEntry('slate', $slate);
225
226 $html = $r->render($mb);
227
228 $expected = <<<EOT
229 <div class="il-maincontrols-mainbar" id="id_12">
230 <nav class="il-mainbar" aria-label="mainbar_aria_label">
231 <div class="il-mainbar-triggers">
232 <div class="il-mainbar-entries" role="menubar" style="visibility: hidden">
233 <button class="btn btn-bulky" data-action="#" id="id_1" ><div class="icon custom small" aria-label=""><img src="" /></div><span class="bulky-label">TestEntry</span></button>
234 <button class="btn btn-bulky" data-action="#" id="id_2" ><div class="icon custom small" aria-label=""><img src="" /></div><span class="bulky-label">TestEntry</span></button>
235 <button class="btn btn-bulky" id="id_3" role="menuitem" aria-haspopup="true" ><div class="icon custom small" aria-label=""><img src="" /></div><span class="bulky-label">1</span></button>
236 <button class="btn btn-bulky" id="id_9" role="menuitem" aria-haspopup="true" ><span class="glyph" aria-label="show_more"><span class="glyphicon glyphicon-option-horizontal" aria-hidden="true"></span></span><span class="bulky-label">more</span></button>
237 </div>
238 </div>
239 </nav>
240
241 <div class="il-mainbar-slates">
242 <div class="il-mainbar-tools-entries">
243 <div class="il-mainbar-tools-entries-bg"></div>
244 </div>
245 <div class="il-maincontrols-slate disengaged" id="id_8" data-depth-level="1" role="menu">
246 <div class="il-maincontrols-slate-content" data-replace-marker="content">
247 <button class="btn btn-bulky" id="id_4" ><div class="icon custom small" aria-label=""><img src="" /></div><span class="bulky-label">1.1</span></button>
248
249 <div class="il-maincontrols-slate disengaged" id="id_7" data-depth-level="2">
250 <div class="il-maincontrols-slate-content" data-replace-marker="content">
251 <button class="btn btn-bulky" id="id_5" ><div class="icon custom small" aria-label=""><img src="" /></div><span class="bulky-label">1.1.1</span></button>
252
253 <div class="il-maincontrols-slate disengaged" id="id_6" data-depth-level="3">
254 <div class="il-maincontrols-slate-content" data-replace-marker="content"></div>
255 </div>
256 </div>
257 </div>
258
259 </div>
260 </div>
261
262 <div class="il-maincontrols-slate disengaged" id="id_10" data-depth-level="1" role="menu">
263 <div class="il-maincontrols-slate-content" data-replace-marker="content"></div>
264 </div>
265
266 <div class="il-mainbar-close-slates">
267 <button class="btn btn-bulky" id="id_11" ><span class="glyph" href="#" aria-label="back"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span></span><span class="bulky-label">close</span></button>
268 </div>
269 </div>
270 </div>
271EOT;
272
273 $this->assertEquals(
274 $this->brutallyTrimHTML($expected),
275 $this->brutallyTrimHTML($html)
276 );
277 }
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:268
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
close()
Definition: close.php:2
more()
Definition: more.php:2

References brutallyTrimHTML(), close(), getButton(), ILIAS_UI_TestBase\getDefaultRenderer(), and more().

+ Here is the call graph for this function:

◆ testSignalsPresent()

MainBarTest::testSignalsPresent ( )

Definition at line 151 of file MainBarTest.php.

152 {
153 $this->assertInstanceOf(Signal::class, $this->mainbar->getEntryClickSignal());
154 $this->assertInstanceOf(Signal::class, $this->mainbar->getToolsClickSignal());
155 $this->assertInstanceOf(Signal::class, $this->mainbar->getToolsRemovalSignal());
156 $this->assertInstanceOf(Signal::class, $this->mainbar->getDisengageAllSignal());
157 }

References mainbar().

+ Here is the call graph for this function:

◆ testWithInvalidActive()

MainBarTest::testWithInvalidActive ( )

Definition at line 144 of file MainBarTest.php.

145 {
146 $this->expectException(\InvalidArgumentException::class);
147 $mb = $this->mainbar
148 ->withActive('this-is-not-a-valid-entry');
149 }

References mainbar().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: