ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
PasswordInputTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2018 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5require_once(__DIR__ . "/../../../../../libs/composer/vendor/autoload.php");
6require_once(__DIR__ . "/../../../Base.php");
7require_once(__DIR__ . "/InputTest.php");
8
11use ILIAS\Data\Password as PWD;
12use \ILIAS\UI\Component\Input\Field;
13use \ILIAS\Data;
14
15class _PWDInputData implements InputData
16{
17 public function get($name)
18 {
19 return 'some value';
20 }
21 public function getOr($name, $default)
22 {
23 return 'some alternative value';
24 }
25}
26
28{
29 public function setUp() : void
30 {
31 $this->name_source = new DefNamesource();
32 }
33
34
35 protected function buildFactory()
36 {
37 $df = new Data\Factory();
38 $language = $this->createMock(\ilLanguage::class);
40 new SignalGenerator(),
41 $df,
42 new \ILIAS\Refinery\Factory($df, $language),
43 $language
44 );
45 }
46
47
49 {
50 $f = $this->buildFactory();
51 $pwd = $f->password("label", "byline");
52 $this->assertInstanceOf(Field\Input::class, $pwd);
53 $this->assertInstanceOf(Field\Password::class, $pwd);
54 }
55
56
57 public function test_render()
58 {
59 $f = $this->buildFactory();
60 $label = "label";
61 $byline = "byline";
62 $name = "name_0";
63 $pwd = $f->password($label, $byline)->withNameFrom($this->name_source);
64
65 $r = $this->getDefaultRenderer();
66 $expected = ""
67 . "<div class=\"form-group row\">"
68 . "<label for=\"$name\" class=\"control-label col-sm-3\">$label</label>"
69 . "<div class=\"col-sm-9\">"
70 . "<div class=\"il-input-password\">"
71 . "<input type=\"password\" name=\"$name\" class=\"form-control form-control-sm\" />"
72 . "</div>"
73 . "<div class=\"help-block\">$byline</div>"
74 . "</div>"
75 . "</div>";
76 $this->assertHTMLEquals($expected, $r->render($pwd));
77 }
78
79
80 public function test_render_error()
81 {
82 $f = $this->buildFactory();
83 $label = "label";
84 $byline = "byline";
85 $name = "name_0";
86 $error = "an_error";
87 $pwd = $f->password($label, $byline)->withNameFrom($this->name_source)->withError($error);
88
89 $r = $this->getDefaultRenderer();
90 $html = $this->normalizeHTML($r->render($pwd));
91 $expected = ""
92 . "<div class=\"form-group row\">"
93 . " <label for=\"$name\" class=\"control-label col-sm-3\">$label</label>"
94 . " <div class=\"col-sm-9\">"
95 . " <div class=\"il-input-password\">"
96 . " <input type=\"password\" name=\"$name\" class=\"form-control form-control-sm\" />"
97 . " </div>"
98 . " <div class=\"help-block\">$byline</div>"
99 . " <div class=\"help-block alert alert-danger\" role=\"alert\">"
100 . " <img border=\"0\" src=\"./templates/default/images/icon_alert.svg\" alt=\"alert\" />"
101 . " $error"
102 . " </div>"
103 . " </div>"
104 . "</div>";
105
106 $html = preg_replace('!\s+!', ' ', $html);
107 $expected = preg_replace('!\s+!', ' ', $expected);
108 $html = explode(' ', $html); //so you can actually _see_ the difference...
109 $expected = explode(' ', $expected);
110 $this->assertEquals($expected, $html);
111 }
112
113
114 public function test_render_no_byline()
115 {
116 $f = $this->buildFactory();
117 $label = "label";
118 $name = "name_0";
119 $pwd = $f->password($label)->withNameFrom($this->name_source);
120
121 $r = $this->getDefaultRenderer();
122 $expected = ""
123 . "<div class=\"form-group row\">"
124 . "<label for=\"$name\" class=\"control-label col-sm-3\">$label</label>"
125 . "<div class=\"col-sm-9\">"
126 . "<div class=\"il-input-password\">"
127 . "<input type=\"password\" name=\"$name\" class=\"form-control form-control-sm\" />"
128 . "</div>"
129 . "</div>"
130 . "</div>";
131 $this->assertHTMLEquals($expected, $r->render($pwd));
132 }
133
134
135 public function test_render_value()
136 {
137 $f = $this->buildFactory();
138 $label = "label";
139 $value = "value_0";
140 $name = "name_0";
141 $pwd = $f->password($label)->withValue($value)->withNameFrom($this->name_source);
142
143 $r = $this->getDefaultRenderer();
144 $expected = ""
145 . "<div class=\"form-group row\">"
146 . "<label for=\"$name\" class=\"control-label col-sm-3\">$label</label>"
147 . "<div class=\"col-sm-9\">"
148 . "<div class=\"il-input-password\">"
149 . "<input type=\"password\" name=\"$name\" value=\"$value\" class=\"form-control form-control-sm\" />"
150 . "</div>"
151 . "</div>"
152 . "</div>";
153 $this->assertHTMLEquals($expected, $r->render($pwd));
154 }
155
156
157 public function test_render_required()
158 {
159 $f = $this->buildFactory();
160 $label = "label";
161 $name = "name_0";
162 $pwd = $f->password($label)->withNameFrom($this->name_source)->withRequired(true);
163
164 $r = $this->getDefaultRenderer();
165 $html = $r->render($pwd);
166
167 $expected = ""
168 . "<div class=\"form-group row\">"
169 . "<label for=\"$name\" class=\"control-label col-sm-3\">" . "$label"
170 . "<span class=\"asterisk\">*</span>"
171 . "</label>"
172 . "<div class=\"col-sm-9\">"
173 . "<div class=\"il-input-password\">"
174 . "<input type=\"password\" name=\"$name\" class=\"form-control form-control-sm\" />"
175 . "</div>"
176 . "</div>"
177 . "</div>";
178 $this->assertHTMLEquals($expected, $html);
179 }
180
181
182 public function test_render_disabled()
183 {
184 $f = $this->buildFactory();
185 $label = "label";
186 $name = "name_0";
187 $pwd = $f->password($label)->withNameFrom($this->name_source)->withDisabled(true);
188
189 $r = $this->getDefaultRenderer();
190 $html = $r->render($pwd);
191
192 $expected = ""
193 . "<div class=\"form-group row\">"
194 . "<label for=\"$name\" class=\"control-label col-sm-3\">$label</label>"
195 . "<div class=\"col-sm-9\">"
196 . "<div class=\"il-input-password\">"
197 . "<input type=\"password\" name=\"$name\" disabled=\"disabled\" class=\"form-control form-control-sm\" />"
198 . "</div>"
199 . "</div>"
200 . "</div>";
201 $this->assertHTMLEquals($expected, $html);
202 }
203
204
205 public function test_value_required()
206 {
207 $f = $this->buildFactory();
208 $label = "label";
209 $name = "name_0";
210 $pwd = $f->password($label)->withNameFrom($this->name_source)->withRequired(true);
211
212 $pwd1 = $pwd->withInput(new DefInputData([$name => "0"]));
213 $value1 = $pwd1->getContent();
214 $this->assertTrue($value1->isOk());
215
216 $pwd2 = $pwd->withInput(new DefInputData([$name => ""]));
217 $value2 = $pwd2->getContent();
218 $this->assertTrue($value2->isError());
219 }
220
221 public function test_value_type()
222 {
223 $f = $this->buildFactory();
224 $label = "label";
225 $pwd = $f->password($label)->withNameFrom($this->name_source);
226 $this->assertNull($pwd->getValue());
227
228 $post = new _PWDInputData();
229 $pwd = $pwd->withInput($post);
230 $this->assertEquals($post->getOr('', ''), $pwd->getValue());
231 $this->assertInstanceOf(PWD::class, $pwd->getContent()->value());
232 }
233}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
A password is used as part of credentials for authentication.
Definition: Password.php:14
Provides common functionality for UI tests.
Definition: Base.php:225
assertHTMLEquals($expected_html_as_string, $html_as_string)
Definition: Base.php:326
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:268
normalizeHTML($html)
Definition: Base.php:317
getOr($name, $default)
Get a named value from the data and fallback to default if that name does not exist.
Describes how Input-Elements want to interact with posted data.
Definition: InputData.php:13
if($format !==null) $name
Definition: metadata.php:230
Class ChatMainBarProvider \MainMenu\Provider.