ILIAS  release_7 Revision v7.30-3-g800a261c036
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->assertStringContainsString("glyphicon-chevron-left", $html);
86 $this->assertStringContainsString("glyphicon-chevron-right", $html);
87 $this->assertStringContainsString("il-viewcontrol-section", $html);
88 $this->assertStringContainsString("btn", $html);
89
90 $expected = $this->getSectionExpectedHTML();
91 $this->assertHTMLEquals($expected, $html);
92
93 $f = $this->getViewControlFactory();
94 $this->assertInstanceOf("ILIAS\\UI\\Component\\ViewControl\\Factory", $f);
95 }
96
98 {
99 $f = $this->getViewControlFactory();
100
101 $this->assertEquals($this->active, $f->mode($this->actions, $this->aria_label)->withActive($this->active)->getActive());
102 $this->assertNotEquals($this->active, $f->mode($this->actions, $this->aria_label)->withActive("Dummy text")->getActive());
103 }
104
106 {
107 $f = $this->getViewControlFactory();
108 $r = $this->getDefaultRenderer();
109
110 $this->assertIsArray($f->mode($this->actions, $this->aria_label)->getLabelledActions());
111 }
112
114 {
115 $f = $this->getViewControlFactory();
116 $r = $this->getDefaultRenderer();
117 $mode = $f->mode($this->actions, $this->aria_label);
118
119 $html = $this->normalizeHTML($r->render($mode));
120
121 $active = $mode->getActive();
122 if ($active == "") {
123 $activate_first_item = true;
124 }
125
126 $expected = "<div class=\"btn-group il-viewcontrol-mode\" aria-label=\"" . $this->aria_label . "\" role=\"" . $this->role . "\">";
127 foreach ($this->actions as $label => $action) {
128 if ($activate_first_item) {
129 $expected .= "<button class=\"btn btn-default engaged\" aria-label=\"$label\" aria-pressed=\"true\" data-action=\"$action\" id=\"id_1\">$label</button>";
130 $activate_first_item = false;
131 } elseif ($active == $label) {
132 $expected .= "<button class=\"btn btn-default engaged\" aria-label=\"$label\" aria-pressed=\"true\" data-action=\"$action\" id=\"id_1\">$label</button>";
133 } else {
134 $expected .= "<button class=\"btn btn-default\" aria-label=\"$label\" aria-pressed=\"false\" data-action=\"$action\" id=\"id_2\">$label</button>";
135 }
136 }
137 $expected .= "</div>";
138
139 $this->assertHTMLEquals($expected, $html);
140 }
141
142 public function getUIFactory()
143 {
144 $factory = new class extends NoUIFactory {
145 public function counter()
146 {
147 return new I\Component\Counter\Factory();
148 }
149 public function button()
150 {
151 return new I\Component\Button\Factory();
152 }
153 };
154 return $factory;
155 }
156
157 protected function getSectionExpectedHTML()
158 {
159 $expected = <<<EOT
160<div class="il-viewcontrol-section">
161<a class="btn btn-default " href="http://www.ilias.de" aria-label="previous" data-action="http://www.ilias.de" id="id_1"><span class="glyphicon glyphicon-chevron-left"></span></a>
162<button class="btn btn-default" data-action="">Today</button>
163<a class="btn btn-default " href="http://www.github.com" aria-label="next" data-action="http://www.github.com" id="id_2"><span class="glyphicon glyphicon-chevron-right"></span></a>
164</div>
165EOT;
166 return $expected;
167 }
168}
$section
Definition: Utf8Test.php:83
An exception for terminatinating execution or to throw for unit testing.
Builds a Color from either hex- or rgb values.
Definition: Factory.php:14
Provides common functionality for UI tests.
Definition: Base.php:263
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:372
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
normalizeHTML($html)
Definition: Base.php:363
test_viewcontrol_section_get_previous_actions()
test_viewcontrol_section_get_next_actions()
$factory
Definition: metadata.php:58