ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PanelTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2016 Timon Amstutz <timon.amstutz@ilub.unibe.ch> 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
12{
13 public function __construct($id = "")
14 {
15 $this->id = $id;
16 }
17 public function getCanonicalName()
18 {
19 return "Component Dummy";
20 }
21}
22
27{
28
32 public function getPanelFactory()
33 {
34 return new I\Component\Panel\Factory(
35 $this->createMock(C\Panel\Listing\Factory::class)
36 );
37 }
38
40 {
41 $f = $this->getPanelFactory();
42
43 $this->assertInstanceOf("ILIAS\\UI\\Component\\Panel\\Factory", $f);
44 $this->assertInstanceOf(
45 "ILIAS\\UI\\Component\\Panel\\Standard",
46 $f->standard("Title", array(new ComponentDummy()))
47 );
48 $this->assertInstanceOf(
49 "ILIAS\\UI\\Component\\Panel\\Sub",
50 $f->sub("Title", array(new ComponentDummy()))
51 );
52 $this->assertInstanceOf(
53 "ILIAS\\UI\\Component\\Panel\\Report",
54 $f->report("Title", $f->sub("Title", array(new ComponentDummy())))
55 );
56 }
57
58 public function test_standard_get_title()
59 {
60 $f = $this->getPanelFactory();
61 $p = $f->standard("Title", array(new ComponentDummy()));
62
63 $this->assertEquals($p->getTitle(), "Title");
64 }
65
66 public function test_standard_get_content()
67 {
68 $f = $this->getPanelFactory();
69 $c = new ComponentDummy();
70 $p = $f->standard("Title", array($c));
71
72 $this->assertEquals($p->getContent(), array($c));
73 }
74
76 {
77 $fp = $this->getPanelFactory();
78
79 $p = $fp->standard("Title", array(new ComponentDummy()));
80
81 $actions = new I\Component\Dropdown\Standard(array(
82 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
83 new I\Component\Button\Shy("GitHub", "https://www.github.com")
84 ));
85
86 $p = $p->withActions($actions);
87
88 $this->assertEquals($p->getActions(), $actions);
89 }
90
91 public function test_sub_with_actions()
92 {
93 $fp = $this->getPanelFactory();
94
95 $p = $fp->sub("Title", array(new ComponentDummy()));
96
97 $actions = new I\Component\Dropdown\Standard(array(
98 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
99 new I\Component\Button\Shy("GitHub", "https://www.github.com")
100 ));
101
102 $p = $p->withActions($actions);
103
104 $this->assertEquals($p->getActions(), $actions);
105 }
106
107 public function test_sub_with_card()
108 {
109 $fp = $this->getPanelFactory();
110
111 $p = $fp->sub("Title", array(new ComponentDummy()));
112
113 $card = new I\Component\Card\Card("Card Title");
114
115 $p = $p->withCard($card);
116
117 $this->assertEquals($p->getCard(), $card);
118 }
119
120 public function test_report_get_title()
121 {
122 $f = $this->getPanelFactory();
123 $sub = $f->sub("Title", array(new ComponentDummy()));
124 $p = $f->report("Title", array($sub));
125
126 $this->assertEquals($p->getTitle(), "Title");
127 }
128
129 public function test_report_get_content()
130 {
131 $f = $this->getPanelFactory();
132 $sub = $f->sub("Title", array(new ComponentDummy()));
133 $p = $f->report("Title", $sub);
134
135 $this->assertEquals($p->getContent(), array($sub));
136 }
137
138
139 public function test_render_standard()
140 {
141 $f = $this->getPanelFactory();
142 $r = $this->getDefaultRenderer();
143
144 $actions = new I\Component\Dropdown\Standard(array(
145 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
146 new I\Component\Button\Shy("GitHub", "https://www.github.com")
147 ));
148
149 $p = $f->standard("Title", array())->withActions($actions);
150
151 $html = $r->render($p);
152
153 $expected_html = <<<EOT
154<div class="panel panel-primary">
155 <div class="panel-heading ilHeader clearfix">
156 <h3 class="ilHeader">Title</h3>
157 <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>
158 <ul class="dropdown-menu">
159 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
160 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></li>
161 </ul>
162 </div>
163 </div>
164 <div class="panel-body"></div>
165</div>
166EOT;
167 $this->assertHTMLEquals($expected_html, $html);
168 }
169
170 public function test_render_sub()
171 {
172 $fp = $this->getPanelFactory();
173 $r = $this->getDefaultRenderer();
174
175 $actions = new I\Component\Dropdown\Standard(array(
176 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
177 new I\Component\Button\Shy("GitHub", "https://www.github.com")
178 ));
179
180 $p = $fp->sub("Title", array())->withActions($actions);
181 $card = new I\Component\Card\Card("Card Title");
182 $p = $p->withCard($card);
183 $html = $r->render($p);
184
185 $expected_html = <<<EOT
186<div class="panel panel-primary">
187 <div class="panel-heading ilBlockHeader clearfix">
188 <h4>Title</h4>
189 <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>
190 <ul class="dropdown-menu">
191 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
192 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></li>
193 </ul>
194 </div>
195 </div>
196 <div class="panel-body">
197 <div class="row">
198 <div class="col-sm-8"></div>
199 <div class="col-sm-4">
200 <div class="il-card thumbnail">
201 <div class="card-no-highlight"></div>
202 <div class="caption">
203 <h5 class="card-title">Card Title</h5>
204 </div>
205 </div>
206 </div>
207 </div>
208 </div>
209</div>
210EOT;
211
212 $this->assertHTMLEquals($expected_html, $html);
213 }
214 public function test_render_report()
215 {
216 $fp = $this->getPanelFactory();
217 $r = $this->getDefaultRenderer();
218 $sub = $fp->sub("Title", array());
219 $card = new I\Component\Card\Card("Card Title");
220 $sub = $sub->withCard($card);
221 $report = $fp->report("Title", $sub);
222
223 $html = $r->render($report);
224
225 $expected_html =
226 "<div class=\"panel panel-primary il-panel-report\">" .
227 " <div class=\"panel-heading ilHeader\">" .
228 "<h3 class=\"ilHeader\">Title</h3>" .
229 " </div>" .
230 " <div class=\"panel-body\">" .
231 "
232 <div class=\"panel panel-primary\">" .
233 " <div class=\"panel-heading ilBlockHeader clearfix\">" .
234 " <h4>Title</h4>" .
235 " </div>" .
236 " <div class=\"panel-body\"><div class=\"row\">" .
237 " <div class=\"col-sm-8\"></div>" .
238 " <div class=\"col-sm-4\">" .
239 " <div class=\"il-card thumbnail\"><div class=\"card-no-highlight\"></div><div class=\"caption\"><h5 class=\"card-title\">Card Title</h5></div></div>" .
240 " </div>" .
241 " </div></div>" .
242 " </div>" .
243 " </div>" .
244 "</div>";
245
246 $this->assertHTMLEquals($expected_html, $html);
247 }
248}
An exception for terminatinating execution or to throw for unit testing.
__construct($id="")
Definition: PanelTest.php:13
getCanonicalName()
Get the canonical name of the component.
Definition: PanelTest.php:17
Provides common functionality for UI tests.
Definition: Base.php:192
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:270
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:228
Test on button implementation.
Definition: PanelTest.php:27
getPanelFactory()
Definition: PanelTest.php:32
test_standard_with_actions()
Definition: PanelTest.php:75
test_standard_get_content()
Definition: PanelTest.php:66
test_sub_with_card()
Definition: PanelTest.php:107
test_report_get_title()
Definition: PanelTest.php:120
test_render_report()
Definition: PanelTest.php:214
test_report_get_content()
Definition: PanelTest.php:129
test_render_standard()
Definition: PanelTest.php:139
test_render_sub()
Definition: PanelTest.php:170
test_sub_with_actions()
Definition: PanelTest.php:91
test_standard_get_title()
Definition: PanelTest.php:58
test_implements_factory_interface()
Definition: PanelTest.php:39
Title class.
Definition: Title.php:37
$html
Definition: example_001.php:87
$r
Definition: example_031.php:79
if(!array_key_exists('StateId', $_REQUEST)) $id
A component is the most general form of an entity in the UI.
Definition: Component.php:14
Class BaseForm.
$this data['403_header']