ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $c = $f->standard(array(
41 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
42 new I\Component\Button\Shy("GitHub", "https://www.github.com"),
43 new I\Component\Divider\Horizontal(),
44 new I\Component\Button\Shy("GitHub", "https://www.github.com")
45 ));
46 $items = $c->getItems();
47
48 $this->assertTrue(is_array($items));
49 $this->assertInstanceOf("ILIAS\\UI\\Component\\Button\\Shy", $items[0]);
50 $this->assertInstanceOf("ILIAS\\UI\\Component\\Divider\\Horizontal", $items[2]);
51 }
52
53 public function test_render_empty()
54 {
55 $f = $this->getFactory();
56 $r = $this->getDefaultRenderer();
57
58 $c = $f->standard(array());
59
60 $html = $r->render($c);
61 $expected = "";
62
63 $this->assertEquals($expected, $html);
64 }
65
66 public function test_render_items()
67 {
68 $f = $this->getFactory();
69 $r = $this->getDefaultRenderer();
70
71 $c = $f->standard(array(
72 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
73 new I\Component\Divider\Horizontal(),
74 new I\Component\Button\Shy("GitHub", "https://www.github.com")
75 ));
76
77 $html = $r->render($c);
78
79 $expected = <<<EOT
80 <div class="dropdown">
81 <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-label="actions" aria-haspopup="true" aria-expanded="false">
82 <span class="caret"></span>
83 </button>
84 <ul class="dropdown-menu">
85 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
86 <li><hr /></li>
87 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></li>
88 </ul>
89 </div>
90EOT;
91
92 $this->assertHTMLEquals($expected, $html);
93 }
94
96 {
97 $f = $this->getFactory();
98 $r = $this->getDefaultRenderer();
99
100 $c = $f->standard(array(
101 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
102 new I\Component\Divider\Horizontal(),
103 new I\Component\Button\Shy("GitHub", "https://www.github.com")
104 ))->withLabel("label");
105
106 $html = $r->render($c);
107
108 $expected = <<<EOT
109 <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>
110 <ul class="dropdown-menu">
111 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
112 <li><hr /></li>
113 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></li>
114 </ul>
115 </div>
116EOT;
117
118 $this->assertHTMLEquals($expected, $html);
119 }
120
122 {
123 $f = $this->getFactory();
124 $r = $this->getDefaultRenderer();
125
126 $c = $f->standard(array(
127 new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
128 new I\Component\Divider\Horizontal(),
129 new I\Component\Button\Shy("GitHub", "https://www.github.com")
130 ))->withLabel("label")->withAriaLabel("my_aria_label");
131
132 $html = $r->render($c);
133
134 $expected = <<<EOT
135 <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>
136 <ul class="dropdown-menu">
137 <li><button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button></li>
138 <li><hr /></li>
139 <li><button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button></li>
140 </ul>
141 </div>
142EOT;
143
144 $this->assertHTMLEquals($expected, $html);
145 }
146}
An exception for terminatinating execution or to throw for unit testing.
Test on card implementation.
test_render_items_with_label()
test_implements_factory_interface()
test_render_items_with_aria_label()
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
$html
Definition: example_001.php:87
$r
Definition: example_031.php:79
Class BaseForm.
$this data['403_header']