ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
DropdownTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2017 Alexander Killing <killing@leifos.de> Extended GPL, see docs/LICENSE */
4
5require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
6require_once(__DIR__ . "/../../Base.php");
7
8use \ILIAS\UI\Component as C;
9use \ILIAS\UI\Implementation as I;
10
15{
16 protected function getFactory()
17 {
18 return new I\Component\Dropdown\Factory();
19 }
20
22 {
23 $f = $this->getFactory();
24
25 $this->assertInstanceOf("ILIAS\\UI\\Component\\Dropdown\\Standard", $f->standard(array()));
26 }
27
28 public function test_with_label()
29 {
30 $f = $this->getFactory();
31
32 $c = $f->standard(array())->withLabel("label");
33
34 $this->assertEquals($c->getLabel(), "label");
35 }
36
37 public function test_with_items()
38 {
39 $f = $this->getFactory();
40 $link = new I\Component\Link\Standard("Link to Github", "http://www.github.com");
41 $c = $f->standard(array(
42 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
43 new I\Component\Button\Shy("GitHub", "https://www.github.com"),
44 new I\Component\Divider\Horizontal(),
45 $link->withOpenInNewViewport(true)
46 ));
47 $items = $c->getItems();
48
49 $this->assertTrue(is_array($items));
50 $this->assertInstanceOf("ILIAS\\UI\\Component\\Button\\Shy", $items[0]);
51 $this->assertInstanceOf("ILIAS\\UI\\Component\\Divider\\Horizontal", $items[2]);
52 $this->assertInstanceOf("ILIAS\\UI\\Component\\Link\\Standard", $items[3]);
53 }
54
55 public function test_render_empty()
56 {
57 $f = $this->getFactory();
58 $r = $this->getDefaultRenderer();
59
60 $c = $f->standard(array());
61
62 $html = $r->render($c);
63 $expected = "";
64
65 $this->assertEquals($expected, $html);
66 }
67
68 public function test_render_items()
69 {
70 $f = $this->getFactory();
71 $r = $this->getDefaultRenderer();
72
73 $c = $f->standard(array(
74 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
75 new I\Component\Divider\Horizontal(),
76 new I\Component\Button\Shy("GitHub", "https://www.github.com")
77 ));
78
79 $html = $r->render($c);
80
81 $expected = <<<EOT
82 <div class="dropdown">
83 <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-label="actions" aria-haspopup="true" aria-expanded="false">
84 <span class="caret"></span>
85 </button>
86 <ul class="dropdown-menu">
87 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
88 <li><hr /></li>
89 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></li>
90 </ul>
91 </div>
92EOT;
93
94 $this->assertHTMLEquals($expected, $html);
95 }
96
98 {
99 $f = $this->getFactory();
100 $r = $this->getDefaultRenderer();
101
102 $c = $f->standard(array(
103 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
104 new I\Component\Divider\Horizontal(),
105 new I\Component\Button\Shy("GitHub", "https://www.github.com")
106 ))->withLabel("label");
107
108 $html = $r->render($c);
109
110 $expected = <<<EOT
111 <div class="dropdown"><button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">label <span class="caret"></span></button>
112 <ul class="dropdown-menu">
113 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
114 <li><hr /></li>
115 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></li>
116 </ul>
117 </div>
118EOT;
119
120 $this->assertHTMLEquals($expected, $html);
121 }
122
124 {
125 $f = $this->getFactory();
126 $r = $this->getDefaultRenderer();
127
128 $link = new I\Component\Link\Standard("Link to ILIAS", "http://www.ilias.de");
129
130 $c = $f->standard(array(
131 $link->withOpenInNewViewport(true)
132 ));
133
134 $html = $r->render($c);
135
136 $expected = <<<EOT
137 <div class="dropdown"><button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-label="actions" aria-haspopup="true" aria-expanded="false"><span class="caret"></span></button>
138 <ul class="dropdown-menu">
139 <li><a href="http://www.ilias.de" target="_blank" rel="noopener">Link to ILIAS</a></li>
140 </ul>
141 </div>
142EOT;
143
144 $this->assertHTMLEquals($expected, $html);
145 }
146
148 {
149 $f = $this->getFactory();
150 $r = $this->getDefaultRenderer();
151
152 $c = $f->standard(array(
153 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
154 new I\Component\Divider\Horizontal(),
155 new I\Component\Button\Shy("GitHub", "https://www.github.com")
156 ))->withLabel("label")->withAriaLabel("my_aria_label");
157
158 $html = $r->render($c);
159
160 $expected = <<<EOT
161 <div class="dropdown"><button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-label="my_aria_label" aria-haspopup="true" aria-expanded="false">label <span class="caret"></span></button>
162 <ul class="dropdown-menu">
163 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
164 <li><hr /></li>
165 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></li>
166 </ul>
167 </div>
168EOT;
169
170 $this->assertHTMLEquals($expected, $html);
171 }
172}
An exception for terminatinating execution or to throw for unit testing.
Test on card implementation.
test_render_with_link_new_viewport()
test_render_items_with_label()
test_implements_factory_interface()
test_render_items_with_aria_label()
Provides common functionality for UI tests.
Definition: Base.php:225
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:326
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:268
Class ChatMainBarProvider \MainMenu\Provider.