ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  public function __construct($id = ""){
12  $this->id = $id;
13  }
14 }
15 
20 
24  public function getPanelFactory() {
25  return new \ILIAS\UI\Implementation\Component\Panel\Factory();
26  }
27 
31  public function getFactory() {
32  return new \ILIAS\UI\Implementation\Factory();
33  }
34 
36  $f = $this->getPanelFactory();
37 
38  $this->assertInstanceOf("ILIAS\\UI\\Component\\Panel\\Factory", $f);
39  $this->assertInstanceOf
40  ( "ILIAS\\UI\\Component\\Panel\\Standard"
41  , $f->standard("Title",array(new ComponentDummy()))
42  );
43  $this->assertInstanceOf
44  ( "ILIAS\\UI\\Component\\Panel\\Sub"
45  , $f->sub("Title",array(new ComponentDummy()))
46  );
47  $this->assertInstanceOf
48  ( "ILIAS\\UI\\Component\\Panel\\Report"
49  , $f->report("Title",$f->sub("Title",array(new ComponentDummy())))
50  );
51  }
52 
53  public function test_standard_get_title() {
54  $f = $this->getPanelFactory();
55  $p = $f->standard("Title",array(new ComponentDummy()));
56 
57  $this->assertEquals($p->getTitle(), "Title");
58  }
59 
60  public function test_standard_get_content() {
61  $f = $this->getPanelFactory();
62  $c = new ComponentDummy();
63  $p = $f->standard("Title",array($c));
64 
65  $this->assertEquals($p->getContent(), array($c));
66  }
67 
68 
69  public function test_sub_with_card() {
70  $fp = $this->getPanelFactory();
71  $f = $this->getFactory();
72 
73  $p = $fp->sub("Title",array(new ComponentDummy()));
74 
75  $card = $f->card("Card Title");
76 
77  $p = $p->withCard($card);
78 
79  $this->assertEquals($p->getCard(), $card);
80  }
81 
82  public function test_report_get_title() {
83  $f = $this->getPanelFactory();
84  $sub = $f->sub("Title",array(new ComponentDummy()));
85  $p = $f->report("Title",array($sub));
86 
87  $this->assertEquals($p->getTitle(), "Title");
88  }
89 
90  public function test_report_get_content() {
91  $f = $this->getPanelFactory();
92  $sub = $f->sub("Title",array(new ComponentDummy()));
93  $p = $f->report("Title",$sub);
94 
95  $this->assertEquals($p->getContent(), array($sub));
96  }
97 
98 
99  public function test_render_standard() {
100  $f = $this->getPanelFactory();
101  $r = $this->getDefaultRenderer();
102  $p = $f->standard("Title",array());
103 
104  $html = new DOMDocument();
105  $html->formatOutput = true;
106  $html->preserveWhiteSpace = false;
107 
108  $expected = new DOMDocument();
109  $expected->formatOutput = true;
110  $expected->preserveWhiteSpace = false;
111 
112  $html = $r->render($p);
113 
114  $expected_html =
115  "<div class=\"panel panel-primary\">".
116  " <div class=\"panel-heading ilHeader\">".
117  " <h3 class=\"ilHeader\">Title</h3>".
118  " </div>".
119  " <div class=\"panel-body\"></div>".
120  "</div>";
121 
122  $this->assertHTMLEquals($expected_html, $html);
123  }
124 
125  public function test_render_sub() {
126  $f = $this->getFactory();
127  $fp = $this->getPanelFactory();
128  $r = $this->getDefaultRenderer();
129  $p = $fp->sub("Title",array());
130  $card = $f->card("Card Title");
131  $p = $p->withCard($card);
132  $html = $r->render($p);
133 
134  $expected_html =
135  "<div class=\"panel panel-primary\">".
136  " <div class=\"panel-heading ilBlockHeader\">".
137  " <h4>Title</h4>".
138  " </div>".
139  " <div class=\"panel-body\"><div class=\"row\">".
140  " <div class=\"col-sm-8\"></div>".
141  " <div class=\"col-sm-4\">".
142  " <div class=\"il-card thumbnail\"><div class=\"caption\"><h5 class=\"card-title\">Card Title</h5></div></div>".
143  " </div>".
144  " </div></div>".
145  "</div>";
146 
147  $this->assertHTMLEquals($expected_html, $html);
148  }
149  public function test_render_report() {
150  $f = $this->getFactory();
151  $fp = $this->getPanelFactory();
152  $r = $this->getDefaultRenderer();
153  $sub = $fp->sub("Title",array());
154  $card = $f->card("Card Title");
155  $sub = $sub->withCard($card);
156  $report = $fp->report("Title",$sub);
157 
158  $html = $r->render($report);
159 
160  $expected_html =
161  "<div class=\"panel panel-primary il-panel-report\">".
162  " <div class=\"panel-heading ilHeader\">".
163  "<h3 class=\"ilHeader\">Title</h3>".
164  " </div>".
165  " <div class=\"panel-body\">".
166  "
167  <div class=\"panel panel-primary\">".
168  " <div class=\"panel-heading ilBlockHeader\">".
169  " <h4>Title</h4>".
170  " </div>".
171  " <div class=\"panel-body\"><div class=\"row\">".
172  " <div class=\"col-sm-8\"></div>".
173  " <div class=\"col-sm-4\">".
174  " <div class=\"il-card thumbnail\"><div class=\"caption\"><h5 class=\"card-title\">Card Title</h5></div></div>".
175  " </div>".
176  " </div></div>".
177  " </div>".
178  " </div>".
179  "</div>";
180 
181  $this->assertHTMLEquals($expected_html, $html);
182  }
183 }
test_implements_factory_interface()
Definition: PanelTest.php:35
test_standard_get_content()
Definition: PanelTest.php:60
test_standard_get_title()
Definition: PanelTest.php:53
Test on button implementation.
Definition: PanelTest.php:19
test_render_standard()
Definition: PanelTest.php:99
test_sub_with_card()
Definition: PanelTest.php:69
test_render_report()
Definition: PanelTest.php:149
getFactory()
Definition: PanelTest.php:31
A component is the most general form of an entity in the UI.
Definition: Component.php:13
getPanelFactory()
Definition: PanelTest.php:24
$r
Definition: example_031.php:79
Provides common functionality for UI tests.
Definition: Base.php:69
test_render_sub()
Definition: PanelTest.php:125
Create styles array
The data for the language used.
test_report_get_content()
Definition: PanelTest.php:90
__construct($id="")
Definition: PanelTest.php:11
test_report_get_title()
Definition: PanelTest.php:82
$html
Definition: example_001.php:87