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 
5 require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
6 require_once(__DIR__ . "/../../Base.php");
7 
8 use \ILIAS\UI\Component as C;
9 use \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>
90 EOT;
91 
92  $this->assertHTMLEquals($expected, $html);
93  }
94 
95  public function test_render_items_with_label()
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>
116 EOT;
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>
142 EOT;
143 
144  $this->assertHTMLEquals($expected, $html);
145  }
146 }
Class BaseForm.
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:228
test_render_items_with_label()
$r
Definition: example_031.php:79
test_render_items_with_aria_label()
Provides common functionality for UI tests.
Definition: Base.php:191
Test on card implementation.
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:270
$this data['403_header']
$html
Definition: example_001.php:87
test_implements_factory_interface()