ILIAS  release_7 Revision v7.30-3-g800a261c036
MetaBarTest Class Reference

Tests for the Meta Bar. More...

+ Inheritance diagram for MetaBarTest:
+ Collaboration diagram for MetaBarTest:

Public Member Functions

 setUp ()
 
 testConstruction ()
 
 testAddEntry ()
 
 testDisallowedEntry ()
 
 testSignalsPresent ()
 
 getUIFactory ()
 
 brutallyTrimHTML ($html)
 A more radical version of normalizeHTML. More...
 
 testRendering ()
 
 testAcceptsBulkyLinkAsEntry ()
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getRefinery ()
 
 getImagePathResolver ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
 
 getDecoratedRenderer (Renderer $default)
 
 normalizeHTML ($html)
 
 assertHTMLEquals ($expected_html_as_string, $html_as_string)
 

Protected Member Functions

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

Detailed Description

Tests for the Meta Bar.

Definition at line 16 of file MetaBarTest.php.

Member Function Documentation

◆ brutallyTrimHTML()

MetaBarTest::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 117 of file MetaBarTest.php.

118 {
119 $html = str_replace(["\n", "\r", "\t"], "", $html);
120 $html = preg_replace('# {2,}#', " ", $html);
121 $html = preg_replace('/<!--(.|\s)*?-->/', '', $html);
122 $html = str_replace('> <', '><', $html);
123 return trim($html);
124 }

Referenced by testRendering().

+ Here is the caller graph for this function:

◆ getButton()

MetaBarTest::getButton ( )
protected

Definition at line 47 of file MetaBarTest.php.

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

Referenced by testAddEntry(), and testRendering().

+ Here is the caller graph for this function:

◆ getSlate()

MetaBarTest::getSlate ( )
protected

Definition at line 53 of file MetaBarTest.php.

54 {
55 $mock = $this->getMockBuilder(Legacy::class)
56 ->disableOriginalConstructor()
57 ->setMethods(["transformToLegacyComponent"])
58 ->getMock();
59
60 $mock->method('transformToLegacyComponent')->willReturn('content');
61 return $mock;
62 }

Referenced by testAddEntry(), and testRendering().

+ Here is the caller graph for this function:

◆ getUIFactory()

MetaBarTest::getUIFactory ( )

Reimplemented from ILIAS_UI_TestBase.

Definition at line 87 of file MetaBarTest.php.

88 {
89 $factory = new class extends NoUIFactory {
90 public function button()
91 {
92 return $this->button_factory;
93 }
94 public function mainControls() : C\MainControls\Factory
95 {
96 return $this->mc_factory;
97 }
98 public function symbol() : C\Symbol\Factory
99 {
100 return new I\Component\Symbol\Factory(
101 new I\Component\Symbol\Icon\Factory(),
102 new I\Component\Symbol\Glyph\Factory(),
103 new I\Component\Symbol\Avatar\Factory()
104 );
105 }
106 public function counter() : C\Counter\Factory
107 {
108 return $this->counter_factory;
109 }
110 };
111 $factory->button_factory = $this->button_factory;
112 $factory->mc_factory = $this->factory;
113 $factory->counter_factory = $this->counter_factory;
114 return $factory;
115 }
$factory
Definition: metadata.php:58

References $factory.

◆ setUp()

MetaBarTest::setUp ( )

Reimplemented from ILIAS_UI_TestBase.

Definition at line 18 of file MetaBarTest.php.

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

References metabar().

+ Here is the call graph for this function:

◆ testAcceptsBulkyLinkAsEntry()

MetaBarTest::testAcceptsBulkyLinkAsEntry ( )

Definition at line 175 of file MetaBarTest.php.

175 : void
176 {
177 $r = $this->getDefaultRenderer();
178
179 $bulky_link = $this->createMock(ILIAS\UI\Component\Link\Bulky::class);
180 $mb = $this->metabar
181 ->withAdditionalEntry('bulky link', $bulky_link);
182
183 $this->assertTrue(true); // Should not throw...
184 }
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.

References ILIAS_UI_TestBase\getDefaultRenderer(), and metabar().

+ Here is the call graph for this function:

◆ testAddEntry()

MetaBarTest::testAddEntry ( )

Definition at line 64 of file MetaBarTest.php.

65 {
66 $button = $this->getButton();
67 $slate = $this->getSlate();
68 $mb = $this->metabar
69 ->withAdditionalEntry('button', $button)
70 ->withAdditionalEntry('slate', $slate);
71 $entries = $mb->getEntries();
72 $this->assertEquals($button, $entries['button']);
73 $this->assertEquals($slate, $entries['slate']);
74 }

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

+ Here is the call graph for this function:

◆ testConstruction()

MetaBarTest::testConstruction ( )

Definition at line 39 of file MetaBarTest.php.

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

References metabar().

+ Here is the call graph for this function:

◆ testDisallowedEntry()

MetaBarTest::testDisallowedEntry ( )

Definition at line 76 of file MetaBarTest.php.

77 {
78 $this->expectException(\InvalidArgumentException::class);
79 $mb = $this->metabar->withAdditionalEntry('test', 'wrong_param');
80 }

References metabar().

+ Here is the call graph for this function:

◆ testRendering()

MetaBarTest::testRendering ( )

Definition at line 126 of file MetaBarTest.php.

127 {
128 $r = $this->getDefaultRenderer();
129
130 $button = $this->getButton();
131 $slate = $this->getSlate();
132 $mb = $this->metabar
133 ->withAdditionalEntry('button', $button)
134 ->withAdditionalEntry('button2', $button);
135
136 $html = $r->render($mb);
137
138 $expected = '
139 <ul class="il-maincontrols-metabar" role="menubar" style="visibility: hidden" aria-label="metabar_aria_label" id="id_5" >
140 <li role="none">
141 <button class="btn btn-bulky" data-action="#" id="id_1" role="menuitem" >
142 <img class="icon custom small" src="" alt=""/><span class="bulky-label">TestEntry</span>
143 </button>
144 </li>
145 <li role="none">
146 <button class="btn btn-bulky" data-action="#" id="id_2" role="menuitem" >
147 <img class="icon custom small" src="" alt=""/><span class="bulky-label">TestEntry</span>
148 </button>
149 </li>
150 <li role="none">
151 <button class="btn btn-bulky" id="id_3" role="menuitem" aria-haspopup="true" >
152 <span class="glyph" aria-label="disclose" role="img">
153 <span class="glyphicon glyphicon-option-vertical" aria-hidden="true"></span>
154 <span class="il-counter"><span class="badge badge-notify il-counter-status" style="display:none">0</span></span>
155 <span class="il-counter"><span class="badge badge-notify il-counter-novelty" style="display:none">0</span></span>
156 </span>
157 <span class="bulky-label">more</span>
158 </button>
159 <div class="il-metabar-slates">
160 <div class="il-maincontrols-slate disengaged" id="id_4" role="menu">
161 <div class="il-maincontrols-slate-content" data-replace-marker="content"></div>
162 </div>
163 </div>
164 </li>
165 </ul>
166';
167
168 $this->assertEquals(
169 $this->brutallyTrimHTML($expected),
170 $this->brutallyTrimHTML($html)
171 );
172 }
brutallyTrimHTML($html)
A more radical version of normalizeHTML.

References brutallyTrimHTML(), getButton(), ILIAS_UI_TestBase\getDefaultRenderer(), getSlate(), and metabar().

+ Here is the call graph for this function:

◆ testSignalsPresent()

MetaBarTest::testSignalsPresent ( )

Definition at line 82 of file MetaBarTest.php.

83 {
84 $this->assertInstanceOf(Signal::class, $this->metabar->getEntryClickSignal());
85 }

References metabar().

+ Here is the call graph for this function:

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