ILIAS  release_7 Revision v7.30-3-g800a261c036
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 class=\"control-label col-sm-3\">$label</label>"
69 . "<div class=\"col-sm-9\">"
70 . "<div class=\"il-input-password\" id=\"id_1\">"
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->brutallyTrimHTML($r->render($pwd));
91 $expected = $this->brutallyTrimHTML('
92<div class="form-group row">
93 <label class="control-label col-sm-3">label</label>
94 <div class="col-sm-9">
95 <div class="help-block alert alert-danger" role="alert">an_error</div>
96 <div class="il-input-password" id="id_1"><input type="password" name="name_0" class="form-control form-control-sm" /></div>
97 <div class="help-block">byline</div>
98 </div>
99</div>');
100
101 $this->assertEquals($expected, $html);
102 }
103
104
105 public function test_render_no_byline()
106 {
107 $f = $this->buildFactory();
108 $label = "label";
109 $name = "name_0";
110 $pwd = $f->password($label)->withNameFrom($this->name_source);
111
112 $r = $this->getDefaultRenderer();
113 $expected = ""
114 . "<div class=\"form-group row\">"
115 . "<label class=\"control-label col-sm-3\">$label</label>"
116 . "<div class=\"col-sm-9\">"
117 . "<div class=\"il-input-password\" id=\"id_1\">"
118 . "<input type=\"password\" name=\"$name\" class=\"form-control form-control-sm\" />"
119 . "</div>"
120 . "</div>"
121 . "</div>";
122 $this->assertHTMLEquals($expected, $r->render($pwd));
123 }
124
125
126 public function test_render_value()
127 {
128 $f = $this->buildFactory();
129 $label = "label";
130 $value = "value_0";
131 $name = "name_0";
132 $pwd = $f->password($label)->withValue($value)->withNameFrom($this->name_source);
133
134 $r = $this->getDefaultRenderer();
135 $expected = ""
136 . "<div class=\"form-group row\">"
137 . "<label class=\"control-label col-sm-3\">$label</label>"
138 . "<div class=\"col-sm-9\">"
139 . "<div class=\"il-input-password\" id=\"id_1\">"
140 . "<input type=\"password\" name=\"$name\" value=\"$value\" class=\"form-control form-control-sm\" />"
141 . "</div>"
142 . "</div>"
143 . "</div>";
144 $this->assertHTMLEquals($expected, $r->render($pwd));
145 }
146
147
148 public function test_render_required()
149 {
150 $f = $this->buildFactory();
151 $label = "label";
152 $name = "name_0";
153 $pwd = $f->password($label)->withNameFrom($this->name_source)->withRequired(true);
154
155 $r = $this->getDefaultRenderer();
156 $html = $r->render($pwd);
157
158 $expected = ""
159 . "<div class=\"form-group row\">"
160 . "<label class=\"control-label col-sm-3\">" . "$label"
161 . "<span class=\"asterisk\">*</span>"
162 . "</label>"
163 . "<div class=\"col-sm-9\">"
164 . "<div class=\"il-input-password\" id=\"id_1\">"
165 . "<input type=\"password\" name=\"$name\" class=\"form-control form-control-sm\" />"
166 . "</div>"
167 . "</div>"
168 . "</div>";
169 $this->assertHTMLEquals($expected, $html);
170 }
171
172
173 public function test_render_disabled()
174 {
175 $f = $this->buildFactory();
176 $label = "label";
177 $name = "name_0";
178 $pwd = $f->password($label)->withNameFrom($this->name_source)->withDisabled(true);
179
180 $r = $this->getDefaultRenderer();
181 $html = $r->render($pwd);
182
183 $expected = ""
184 . "<div class=\"form-group row\">"
185 . "<label class=\"control-label col-sm-3\">$label</label>"
186 . "<div class=\"col-sm-9\">"
187 . "<div class=\"il-input-password\" id=\"id_1\">"
188 . "<input type=\"password\" name=\"$name\" disabled=\"disabled\" class=\"form-control form-control-sm\" />"
189 . "</div>"
190 . "</div>"
191 . "</div>";
192 $this->assertHTMLEquals($expected, $html);
193 }
194
195
196 public function test_value_required()
197 {
198 $f = $this->buildFactory();
199 $label = "label";
200 $name = "name_0";
201 $pwd = $f->password($label)->withNameFrom($this->name_source)->withRequired(true);
202
203 $pwd1 = $pwd->withInput(new DefInputData([$name => "0"]));
204 $value1 = $pwd1->getContent();
205 $this->assertTrue($value1->isOk());
206
207 $pwd2 = $pwd->withInput(new DefInputData([$name => ""]));
208 $value2 = $pwd2->getContent();
209 $this->assertTrue($value2->isError());
210 }
211
212 public function test_value_type()
213 {
214 $f = $this->buildFactory();
215 $label = "label";
216 $pwd = $f->password($label)->withNameFrom($this->name_source);
217 $this->assertNull($pwd->getValue());
218
219 $post = new _PWDInputData();
220 $pwd = $pwd->withInput($post);
221 $this->assertEquals($post->getOr('', ''), $pwd->getValue());
222 $this->assertInstanceOf(PWD::class, $pwd->getContent()->value());
223 }
224}
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: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
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Definition: Base.php:392
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.