ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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\Component\SignalGenerator;
8
10{
11 protected $actions = array(
12 "ILIAS" => "http://www.ilias.de",
13 "Github" => "http://www.github.com"
14 );
15
16 protected $aria_label = "Mode View Controler";
17 protected $role = "group";
18 protected $active = "Github";
19
20 public function getViewControlFactory()
21 {
22 return new \ILIAS\UI\Implementation\Component\ViewControl\Factory(new SignalGenerator());
23 }
24
26 {
27 $view_control_f = $this->getViewControlFactory();
29
30 $back = $button_f->standard("", "http://www.ilias.de");
31 $next = $button_f->standard("", "http://www.github.com");
32 $button = $button_f->standard("Today", "");
33
34 $this->assertInstanceOf("ILIAS\\UI\\Component\\Button\\Button", $back);
35 $this->assertInstanceOf("ILIAS\\UI\\Component\\Button\\Button", $next);
36 $this->assertInstanceOf("ILIAS\\UI\\Component\\Button\\Button", $button);
37 $this->assertInstanceOf("ILIAS\\UI\\Component\\ViewControl\\Factory", $view_control_f);
38
39 $section = $view_control_f->section($back, $button, $next);
40 $this->assertInstanceOf("ILIAS\\UI\\Component\\ViewControl\\Section", $section);
41 }
42
43
45 {
47
48 $back = $button_f->standard("", "http://www.ilias.de");
49 $next = $button_f->standard("", "http://www.github.com");
50 $button = $button_f->standard("Today", "");
51
52 $action = $this->getViewControlFactory()->section($back, $button, $next)->getPreviousActions();
53
54 $this->assertInstanceOf("ILIAS\\UI\\Component\\Button\\Button", $action);
55 }
56
58 {
60
61 $back = $button_f->standard("", "http://www.ilias.de");
62 $next = $button_f->standard("", "http://www.github.com");
63 $button = $button_f->standard("Today", "");
64
65 $action = $this->getViewControlFactory()->section($back, $button, $next)->getNextActions();
66
67 $this->assertInstanceOf("ILIAS\\UI\\Component\\Button\\Button", $action);
68 }
69
71 {
72 $view_control_f = $this->getViewControlFactory();
74
75 $r = $this->getDefaultRenderer();
76
77 $back = $button_f->standard("", "http://www.ilias.de");
78 $next = $button_f->standard("", "http://www.github.com");
79 $button = $button_f->standard("Today", "");
80
81 $section = $view_control_f->section($back, $button, $next);
82
83 $html = $r->render($section);
84 $this->assertContains("glyphicon-chevron-left", $html);
85 $this->assertContains("glyphicon-chevron-right", $html);
86 $this->assertContains("il-viewcontrol-section", $html);
87 //$this->assertContains('back', $html);
88 //$this->assertContains('next', $html);
89 $this->assertContains("btn", $html);
90
91 $expected = $this->getSectionExpectedHTML();
92 $this->assertHTMLEquals($expected, $html);
93
94 $f = $this->getViewControlFactory();
95 $this->assertInstanceOf("ILIAS\\UI\\Component\\ViewControl\\Factory", $f);
96 }
97
99 {
100 $f = $this->getViewControlFactory();
101
102 $this->assertEquals($this->active, $f->mode($this->actions, $this->aria_label)->withActive($this->active)->getActive());
103 $this->assertNotEquals($this->active, $f->mode($this->actions, $this->aria_label)->withActive("Dummy text")->getActive());
104 }
105
107 {
108 $f = $this->getViewControlFactory();
109 $r = $this->getDefaultRenderer();
110
111 $this->assertInternalType("array", $f->mode($this->actions, $this->aria_label)->getLabelledActions());
112 }
113
115 {
116 $f = $this->getViewControlFactory();
117 $r = $this->getDefaultRenderer();
118 $mode = $f->mode($this->actions, $this->aria_label);
119
120 $html = $this->normalizeHTML($r->render($mode));
121
122 $active = $mode->getActive();
123 if ($active == "") {
124 $activate_first_item = true;
125 }
126
127 $expected = "<div class=\"btn-group il-viewcontrol-mode\" aria-label=\"" . $this->aria_label . "\" role=\"" . $this->role . "\">";
128 foreach ($this->actions as $label => $action) {
129 if ($activate_first_item) {
130 $expected .= "<a class=\"btn btn-default ilSubmitInactive disabled\" aria-label=\"$label\" aria-checked=\"true\" data-action=\"$action\">$label</a>";
131 $activate_first_item = false;
132 } elseif ($active == $label) {
133 $expected .= "<a class=\"btn btn-default ilSubmitInactive disabled \" aria-label=\"$label\" aria-checked=\"true\" data-action=\"$action\">$label</a>";
134 } else {
135 $expected .= "<a class=\"btn btn-default\" href=\"$action\" aria-label=\"$label\" data-action=\"$action\">$label</a>";
136 }
137 }
138 $expected .= "</div>";
139
140 $this->assertHTMLEquals($expected, $html);
141 }
142
143 public function getUIFactory()
144 {
145 return new \ILIAS\UI\Implementation\Factory();
146 }
147
148 protected function getSectionExpectedHTML()
149 {
150 $expected = <<<EOT
151<div class="il-viewcontrol-section">
152<a class="btn btn-default " type="button"
153 href="http://www.ilias.de" data-action="http://www.ilias.de"
154 ><span class="glyphicon glyphicon-chevron-left"></span></a>
155<a class="btn btn-default" href="" data-action="">Today</a>
156<a class="btn btn-default " type="button"
157 href="http://www.github.com" data-action="http://www.github.com"
158 ><span class="glyphicon glyphicon-chevron-right"></span></a>
159</div>
160EOT;
161 return $expected;
162 }
163}
$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:178
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:252
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:216
normalizeHTML($html)
Definition: Base.php:243
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']