ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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;
9
14{
15
19 public function getFactory()
20 {
21 return new \ILIAS\UI\Implementation\Factory();
22 }
23
25 {
26 $f = $this->getFactory();
27
28 $this->assertInstanceOf("ILIAS\\UI\\Component\\Dropdown\\Standard", $f->dropdown()->standard(array()));
29 }
30
31 public function test_with_label()
32 {
33 $f = $this->getFactory();
34
35 $c = $f->dropdown()->standard(array())->withLabel("label");
36
37 $this->assertEquals($c->getLabel(), "label");
38 }
39
40 public function test_with_items()
41 {
42 $f = $this->getFactory();
43 $c = $f->dropdown()->standard(array(
44 $f->button()->shy("ILIAS", "https://www.ilias.de"),
45 $f->button()->shy("GitHub", "https://www.github.com"),
46 $f->divider()->horizontal(),
47 $f->button()->shy("GitHub", "https://www.github.com")
48 ));
49 $items = $c->getItems();
50
51 $this->assertTrue(is_array($items));
52 $this->assertInstanceOf("ILIAS\\UI\\Component\\Button\\Shy", $items[0]);
53 $this->assertInstanceOf("ILIAS\\UI\\Component\\Divider\\Horizontal", $items[2]);
54 }
55
56 public function test_render_empty()
57 {
58 $f = $this->getFactory();
59 $r = $this->getDefaultRenderer();
60
61 $c = $f->dropdown()->standard(array());
62
63 $html = $r->render($c);
64 $expected = "";
65
66 $this->assertEquals($expected, $html);
67 }
68
69 public function test_render_items()
70 {
71 $f = $this->getFactory();
72 $r = $this->getDefaultRenderer();
73
74 $c = $f->dropdown()->standard(array(
75 $f->button()->shy("ILIAS", "https://www.ilias.de"),
76 $f->divider()->horizontal(),
77 $f->button()->shy("GitHub", "https://www.github.com")
78 ));
79
80 $html = $r->render($c);
81
82 $expected = <<<EOT
83 <div class="dropdown">
84 <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
85 <span class="caret"></span>
86 </button>
87 <ul class="dropdown-menu">
88 <li><a class="btn btn-link" href="https://www.ilias.de" data-action="https://www.ilias.de">ILIAS</a></li>
89 <li><hr /></li>
90 <li><a class="btn btn-link" href="https://www.github.com" data-action="https://www.github.com">GitHub</a></li>
91 </ul>
92 </div>
93EOT;
94
95 $this->assertHTMLEquals($expected, $html);
96 }
97
99 {
100 $f = $this->getFactory();
101 $r = $this->getDefaultRenderer();
102
103 $c = $f->dropdown()->standard(array(
104 $f->button()->shy("ILIAS", "https://www.ilias.de"),
105 $f->divider()->horizontal(),
106 $f->button()->shy("GitHub", "https://www.github.com")
107 ))->withLabel("label");
108
109 $html = $r->render($c);
110
111 $expected = <<<EOT
112 <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>
113 <ul class="dropdown-menu">
114 <li><a class="btn btn-link" href="https://www.ilias.de" data-action="https://www.ilias.de">ILIAS</a></li>
115 <li><hr /></li>
116 <li><a class="btn btn-link" href="https://www.github.com" data-action="https://www.github.com">GitHub</a></li>
117 </ul>
118 </div>
119EOT;
120
121 $this->assertHTMLEquals($expected, $html);
122 }
123}
An exception for terminatinating execution or to throw for unit testing.
Test on card implementation.
test_render_items_with_label()
test_implements_factory_interface()
Provides common functionality for UI tests.
Definition: Base.php:178
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:252
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:216
$html
Definition: example_001.php:87
$r
Definition: example_031.php:79
Class BaseForm.
$this data['403_header']