ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ViewControlTest.php
Go to the documentation of this file.
1<?php
2
3require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
4require_once(__DIR__ . "/../../Base.php");
5
6use \ILIAS\UI\Component as C;
7use \ILIAS\UI\Implementation as I;
8use \ILIAS\UI\Implementation\Component\SignalGenerator;
9
11{
12 protected $actions = array(
13 "ILIAS" => "http://www.ilias.de",
14 "Github" => "http://www.github.com"
15 );
16
17 protected $aria_label = "Mode View Controler";
18 protected $role = "group";
19 protected $active = "Github";
20
21 public function getViewControlFactory()
22 {
23 return new I\Component\ViewControl\Factory(new SignalGenerator());
24 }
25
27 {
28 $view_control_f = $this->getViewControlFactory();
29 $button_f = new I\Component\Button\Factory();
30
31 $back = new I\Component\Button\Standard("", "http://www.ilias.de");
32 $next = new I\Component\Button\Standard("", "http://www.github.com");
33 $button = new I\Component\Button\Standard("Today", "");
34
35 $this->assertInstanceOf("ILIAS\\UI\\Component\\Button\\Button", $back);
36 $this->assertInstanceOf("ILIAS\\UI\\Component\\Button\\Button", $next);
37 $this->assertInstanceOf("ILIAS\\UI\\Component\\Button\\Button", $button);
38 $this->assertInstanceOf("ILIAS\\UI\\Component\\ViewControl\\Factory", $view_control_f);
39
40 $section = $view_control_f->section($back, $button, $next);
41 $this->assertInstanceOf("ILIAS\\UI\\Component\\ViewControl\\Section", $section);
42 }
43
44
46 {
48
49 $back = $button_f->standard("", "http://www.ilias.de");
50 $next = $button_f->standard("", "http://www.github.com");
51 $button = $button_f->standard("Today", "");
52
53 $action = $this->getViewControlFactory()->section($back, $button, $next)->getPreviousActions();
54
55 $this->assertInstanceOf("ILIAS\\UI\\Component\\Button\\Button", $action);
56 }
57
59 {
61
62 $back = $button_f->standard("", "http://www.ilias.de");
63 $next = $button_f->standard("", "http://www.github.com");
64 $button = $button_f->standard("Today", "");
65
66 $action = $this->getViewControlFactory()->section($back, $button, $next)->getNextActions();
67
68 $this->assertInstanceOf("ILIAS\\UI\\Component\\Button\\Button", $action);
69 }
70
72 {
73 $view_control_f = $this->getViewControlFactory();
75
76 $r = $this->getDefaultRenderer();
77
78 $back = $button_f->standard("", "http://www.ilias.de");
79 $next = $button_f->standard("", "http://www.github.com");
80 $button = $button_f->standard("Today", "");
81
82 $section = $view_control_f->section($back, $button, $next);
83
84 $html = $r->render($section);
85 $this->assertContains("glyphicon-chevron-left", $html);
86 $this->assertContains("glyphicon-chevron-right", $html);
87 $this->assertContains("il-viewcontrol-section", $html);
88 //$this->assertContains('back', $html);
89 //$this->assertContains('next', $html);
90 $this->assertContains("btn", $html);
91
92 $expected = $this->getSectionExpectedHTML();
93 $this->assertHTMLEquals($expected, $html);
94
95 $f = $this->getViewControlFactory();
96 $this->assertInstanceOf("ILIAS\\UI\\Component\\ViewControl\\Factory", $f);
97 }
98
100 {
101 $f = $this->getViewControlFactory();
102
103 $this->assertEquals($this->active, $f->mode($this->actions, $this->aria_label)->withActive($this->active)->getActive());
104 $this->assertNotEquals($this->active, $f->mode($this->actions, $this->aria_label)->withActive("Dummy text")->getActive());
105 }
106
108 {
109 $f = $this->getViewControlFactory();
110 $r = $this->getDefaultRenderer();
111
112 $this->assertInternalType("array", $f->mode($this->actions, $this->aria_label)->getLabelledActions());
113 }
114
116 {
117 $f = $this->getViewControlFactory();
118 $r = $this->getDefaultRenderer();
119 $mode = $f->mode($this->actions, $this->aria_label);
120
121 $html = $this->normalizeHTML($r->render($mode));
122
123 $active = $mode->getActive();
124 if ($active == "") {
125 $activate_first_item = true;
126 }
127
128 $expected = "<div class=\"btn-group il-viewcontrol-mode\" aria-label=\"" . $this->aria_label . "\" role=\"" . $this->role . "\">";
129 foreach ($this->actions as $label => $action) {
130 if ($activate_first_item) {
131 $expected .= "<button class=\"btn btn-default ilSubmitInactive disabled\" aria-label=\"$label\" aria-checked=\"true\" data-action=\"$action\">$label</button>";
132 $activate_first_item = false;
133 } elseif ($active == $label) {
134 $expected .= "<button class=\"btn btn-default ilSubmitInactive disabled \" aria-label=\"$label\" aria-checked=\"true\" data-action=\"$action\">$label</button>";
135 } else {
136 $expected .= "<button class=\"btn btn-default\" aria-label=\"$label\" data-action=\"$action\" id=\"id_1\">$label</button>";
137 }
138 }
139 $expected .= "</div>";
140
141 $this->assertHTMLEquals($expected, $html);
142 }
143
144 public function getUIFactory()
145 {
146 return new \ILIAS\UI\Implementation\Factory(
147 new I\Component\Counter\Factory(),
148 $this->createMock(C\Glyph\Factory::class),
149 new I\Component\Button\Factory,
150 $this->createMock(C\Listing\Factory::class),
151 $this->createMock(C\Image\Factory::class),
152 $this->createMock(C\Panel\Factory::class),
153 $this->createMock(C\Modal\Factory::class),
154 $this->createMock(C\Dropzone\Factory::class),
155 $this->createMock(C\Popover\Factory::class),
156 $this->createMock(C\Divider\Factory::class),
157 $this->createMock(C\Link\Factory::class),
158 $this->createMock(C\Dropdown\Factory::class),
159 $this->createMock(C\Item\Factory::class),
160 $this->createMock(C\Icon\Factory::class),
161 $this->createMock(C\ViewControl\Factory::class),
162 $this->createMock(C\Chart\Factory::class),
163 $this->createMock(C\Input\Factory::class),
164 $this->createMock(C\Table\Factory::class),
165 $this->createMock(C\MessageBox\Factory::class),
166 $this->createMock(C\Card\Factory::class)
167 );
168 }
169
170 protected function getSectionExpectedHTML()
171 {
172 $expected = <<<EOT
173<div class="il-viewcontrol-section">
174<a class="btn btn-default " href="http://www.ilias.de" data-action="http://www.ilias.de"><span class="glyphicon glyphicon-chevron-left"></span></a>
175<button class="btn btn-default" data-action="">Today</button>
176<a class="btn btn-default " href="http://www.github.com" data-action="http://www.github.com"><span class="glyphicon glyphicon-chevron-right"></span></a>
177</div>
178EOT;
179 return $expected;
180 }
181}
$section
Definition: Utf8Test.php:83
An exception for terminatinating execution or to throw for unit testing.
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
normalizeHTML($html)
Definition: Base.php:261
test_viewcontrol_section_get_previous_actions()
test_viewcontrol_section_get_next_actions()
$action
$html
Definition: example_001.php:87
$r
Definition: example_031.php:79
$this data['403_header']