ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
5 require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
6 require_once(__DIR__ . "/../../Base.php");
7 
8 use \ILIAS\UI\Component as C;
9 
10 class ComponentDummy implements C\Component
11 {
12  public function __construct($id = "")
13  {
14  $this->id = $id;
15  }
16  public function getCanonicalName()
17  {
18  return "Component Dummy";
19  }
20 }
21 
26 {
27 
31  public function getPanelFactory()
32  {
33  return new \ILIAS\UI\Implementation\Component\Panel\Factory();
34  }
35 
39  public function getFactory()
40  {
41  return new \ILIAS\UI\Implementation\Factory();
42  }
43 
45  {
46  $f = $this->getPanelFactory();
47 
48  $this->assertInstanceOf("ILIAS\\UI\\Component\\Panel\\Factory", $f);
49  $this->assertInstanceOf(
50  "ILIAS\\UI\\Component\\Panel\\Standard",
51  $f->standard("Title", array(new ComponentDummy()))
52  );
53  $this->assertInstanceOf(
54  "ILIAS\\UI\\Component\\Panel\\Sub",
55  $f->sub("Title", array(new ComponentDummy()))
56  );
57  $this->assertInstanceOf(
58  "ILIAS\\UI\\Component\\Panel\\Report",
59  $f->report("Title", $f->sub("Title", array(new ComponentDummy())))
60  );
61  }
62 
63  public function test_standard_get_title()
64  {
65  $f = $this->getPanelFactory();
66  $p = $f->standard("Title", array(new ComponentDummy()));
67 
68  $this->assertEquals($p->getTitle(), "Title");
69  }
70 
71  public function test_standard_get_content()
72  {
73  $f = $this->getPanelFactory();
74  $c = new ComponentDummy();
75  $p = $f->standard("Title", array($c));
76 
77  $this->assertEquals($p->getContent(), array($c));
78  }
79 
80  public function test_standard_with_actions()
81  {
82  $fp = $this->getPanelFactory();
83  $f = $this->getFactory();
84 
85  $p = $fp->standard("Title", array(new ComponentDummy()));
86 
87  $actions = $f->dropdown()->standard(array(
88  $f->button()->shy("ILIAS", "https://www.ilias.de"),
89  $f->button()->shy("GitHub", "https://www.github.com")
90  ));
91 
92  $p = $p->withActions($actions);
93 
94  $this->assertEquals($p->getActions(), $actions);
95  }
96 
97  public function test_sub_with_actions()
98  {
99  $fp = $this->getPanelFactory();
100  $f = $this->getFactory();
101 
102  $p = $fp->sub("Title", array(new ComponentDummy()));
103 
104  $actions = $f->dropdown()->standard(array(
105  $f->button()->shy("ILIAS", "https://www.ilias.de"),
106  $f->button()->shy("GitHub", "https://www.github.com")
107  ));
108 
109  $p = $p->withActions($actions);
110 
111  $this->assertEquals($p->getActions(), $actions);
112  }
113 
114  public function test_sub_with_card()
115  {
116  $fp = $this->getPanelFactory();
117  $f = $this->getFactory();
118 
119  $p = $fp->sub("Title", array(new ComponentDummy()));
120 
121  $card = $f->card("Card Title");
122 
123  $p = $p->withCard($card);
124 
125  $this->assertEquals($p->getCard(), $card);
126  }
127 
128  public function test_report_get_title()
129  {
130  $f = $this->getPanelFactory();
131  $sub = $f->sub("Title", array(new ComponentDummy()));
132  $p = $f->report("Title", array($sub));
133 
134  $this->assertEquals($p->getTitle(), "Title");
135  }
136 
137  public function test_report_get_content()
138  {
139  $f = $this->getPanelFactory();
140  $sub = $f->sub("Title", array(new ComponentDummy()));
141  $p = $f->report("Title", $sub);
142 
143  $this->assertEquals($p->getContent(), array($sub));
144  }
145 
146 
147  public function test_render_standard()
148  {
149  $f = $this->getFactory();
150  $r = $this->getDefaultRenderer();
151 
152  $actions = $f->dropdown()->standard(array(
153  $f->button()->shy("ILIAS", "https://www.ilias.de"),
154  $f->button()->shy("GitHub", "https://www.github.com")
155  ));
156 
157  $p = $f->panel()->standard("Title", array())->withActions($actions);
158 
159  $html = $r->render($p);
160 
161  $expected_html = <<<EOT
162 <div class="panel panel-primary">
163  <div class="panel-heading ilHeader clearfix">
164  <h3 class="ilHeader">Title</h3>
165  <div class="dropdown"><button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <span class="caret"></span></button>
166  <ul class="dropdown-menu">
167  <li><a class="btn btn-link" href="https://www.ilias.de" data-action="https://www.ilias.de">ILIAS</a></li>
168  <li><a class="btn btn-link" href="https://www.github.com" data-action="https://www.github.com">GitHub</a></li>
169  </ul>
170  </div>
171  </div>
172  <div class="panel-body"></div>
173 </div>
174 EOT;
175  $this->assertHTMLEquals($expected_html, $html);
176  }
177 
178  public function test_render_sub()
179  {
180  $f = $this->getFactory();
181  $fp = $this->getPanelFactory();
182  $r = $this->getDefaultRenderer();
183 
184  $actions = $f->dropdown()->standard(array(
185  $f->button()->shy("ILIAS", "https://www.ilias.de"),
186  $f->button()->shy("GitHub", "https://www.github.com")
187  ));
188 
189  $p = $fp->sub("Title", array())->withActions($actions);
190  $card = $f->card("Card Title");
191  $p = $p->withCard($card);
192  $html = $r->render($p);
193 
194  $expected_html = <<<EOT
195 <div class="panel panel-primary">
196  <div class="panel-heading ilBlockHeader clearfix">
197  <h4>Title</h4>
198  <div class="dropdown"><button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <span class="caret"></span></button>
199  <ul class="dropdown-menu">
200  <li><a class="btn btn-link" href="https://www.ilias.de" data-action="https://www.ilias.de">ILIAS</a></li>
201  <li><a class="btn btn-link" href="https://www.github.com" data-action="https://www.github.com">GitHub</a></li>
202  </ul>
203  </div>
204  </div>
205  <div class="panel-body">
206  <div class="row">
207  <div class="col-sm-8"></div>
208  <div class="col-sm-4">
209  <div class="il-card thumbnail">
210  <div class="card-no-highlight"></div>
211  <div class="caption">
212  <h5 class="card-title">Card Title</h5>
213  </div>
214  </div>
215  </div>
216  </div>
217  </div>
218 </div>
219 EOT;
220 
221  $this->assertHTMLEquals($expected_html, $html);
222  }
223  public function test_render_report()
224  {
225  $f = $this->getFactory();
226  $fp = $this->getPanelFactory();
227  $r = $this->getDefaultRenderer();
228  $sub = $fp->sub("Title", array());
229  $card = $f->card("Card Title");
230  $sub = $sub->withCard($card);
231  $report = $fp->report("Title", $sub);
232 
233  $html = $r->render($report);
234 
235  $expected_html =
236  "<div class=\"panel panel-primary il-panel-report\">" .
237  " <div class=\"panel-heading ilHeader\">" .
238  "<h3 class=\"ilHeader\">Title</h3>" .
239  " </div>" .
240  " <div class=\"panel-body\">" .
241  "
242  <div class=\"panel panel-primary\">" .
243  " <div class=\"panel-heading ilBlockHeader clearfix\">" .
244  " <h4>Title</h4>" .
245  " </div>" .
246  " <div class=\"panel-body\"><div class=\"row\">" .
247  " <div class=\"col-sm-8\"></div>" .
248  " <div class=\"col-sm-4\">" .
249  " <div class=\"il-card thumbnail\"><div class=\"card-no-highlight\"></div><div class=\"caption\"><h5 class=\"card-title\">Card Title</h5></div></div>" .
250  " </div>" .
251  " </div></div>" .
252  " </div>" .
253  " </div>" .
254  "</div>";
255 
256  $this->assertHTMLEquals($expected_html, $html);
257  }
258 }
Add some data
test_implements_factory_interface()
Definition: PanelTest.php:44
test_standard_get_content()
Definition: PanelTest.php:71
test_standard_get_title()
Definition: PanelTest.php:63
Test on button implementation.
Definition: PanelTest.php:25
test_render_standard()
Definition: PanelTest.php:147
Class BaseForm.
test_sub_with_card()
Definition: PanelTest.php:114
test_standard_with_actions()
Definition: PanelTest.php:80
if(!array_key_exists('StateId', $_REQUEST)) $id
test_render_report()
Definition: PanelTest.php:223
Title class.
Definition: Title.php:36
getFactory()
Definition: PanelTest.php:39
A component is the most general form of an entity in the UI.
Definition: Component.php:13
getPanelFactory()
Definition: PanelTest.php:31
$r
Definition: example_031.php:79
test_sub_with_actions()
Definition: PanelTest.php:97
Provides common functionality for UI tests.
Definition: Base.php:177
test_render_sub()
Definition: PanelTest.php:178
getCanonicalName()
Get the canonical name of the component.
Definition: PanelTest.php:16
Create styles array
The data for the language used.
test_report_get_content()
Definition: PanelTest.php:137
__construct($id="")
Definition: PanelTest.php:12
test_report_get_title()
Definition: PanelTest.php:128
$html
Definition: example_001.php:87