ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
PasswordInputTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once(__DIR__ . "/../../../../../../../vendor/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../../Base.php");
23require_once(__DIR__ . "/InputTest.php");
24require_once(__DIR__ . "/CommonFieldRendering.php");
25
29use ILIAS\Data\Password as PWD;
31use ILIAS\Data;
32use ILIAS\Refinery\Factory as Refinery;
33
34class _PWDInputData implements InputData
35{
39 public function get(string $name): string
40 {
41 return 'some value';
42 }
43
47 public function getOr(string $name, $default): string
48 {
49 return 'some alternative value';
50 }
51
55 public function has($name): bool
56 {
57 return true;
58 }
59}
60
62{
63 use CommonFieldRendering;
64
66
67 public function setUp(): void
68 {
69 $this->name_source = new DefNamesource();
70 }
71
72 public function testImplementsFactoryInterface(): void
73 {
74 $f = $this->getFieldFactory();
75 $pwd = $f->password("label", "byline");
76 $this->assertInstanceOf(\ILIAS\UI\Component\Input\Container\Form\FormInput::class, $pwd);
77 $this->assertInstanceOf(Field\Password::class, $pwd);
78 }
79
80 public function testRender(): void
81 {
82 $f = $this->getFieldFactory();
83 $label = "label";
84 $byline = "byline";
85 $name = "name_0";
86 $pwd = $f->password($label, $byline)->withNameFrom($this->name_source);
87 $expected = $this->getFormWrappedHtml(
88 'password-field-input',
89 $label,
90 '
91 <div class="c-field-password">
92 <input id="id_1" type="password" name="' . $name . '" autocomplete="off" />
93 </div>
94 ',
95 $byline,
96 'id_1'
97 );
98 $this->assertEquals($expected, $this->render($pwd));
99 }
100
101 public function testCommonRendering(): void
102 {
103 $f = $this->getFieldFactory();
104 $label = "label";
105 $pwd = $f->password($label)->withNameFrom($this->name_source);
106
107 $this->testWithError($pwd);
108 $this->testWithNoByline($pwd);
109 $this->testWithRequired($pwd);
110 $this->testWithDisabled($pwd);
111 $this->testWithAdditionalOnloadCodeRendersId($pwd);
112 }
113
114 public function testRenderValue(): void
115 {
116 $f = $this->getFieldFactory();
117 $label = "label";
118 $value = "value_0";
119 $name = "name_0";
120 $pwd = $f->password($label)->withValue($value)->withNameFrom($this->name_source);
121 $expected = $this->getFormWrappedHtml(
122 'password-field-input',
123 $label,
124 '
125 <div class="c-field-password">
126 <input id="id_1" type="password" name="' . $name . '" value="' . $value . '" autocomplete="off" />
127 </div>
128 ',
129 null,
130 'id_1'
131 );
132 $this->assertEquals($expected, $this->render($pwd));
133 }
134
135 public function testValueRequired(): void
136 {
137 $f = $this->getFieldFactory();
138 $label = "label";
139 $name = "name_0";
140 $pwd = $f->password($label)->withNameFrom($this->name_source)->withRequired(true);
141
142 $pwd1 = $pwd->withInput(new DefInputData([$name => "0"]));
143 $value1 = $pwd1->getContent();
144 $this->assertTrue($value1->isOk());
145
146 $pwd2 = $pwd->withInput(new DefInputData([$name => ""]));
147 $value2 = $pwd2->getContent();
148 $this->assertTrue($value2->isError());
149 }
150
151 public function testValueType(): void
152 {
153 $f = $this->getFieldFactory();
154 $label = "label";
155 $pwd = $f->password($label)->withNameFrom($this->name_source);
156 $this->assertNull($pwd->getValue());
157
158 $post = new _PWDInputData();
159 $pwd = $pwd->withInput($post);
160 $this->assertEquals($post->getOr('', ''), $pwd->getValue());
161 $this->assertInstanceOf(PWD::class, $pwd->getContent()->value());
162 }
163}
Builds data types.
Definition: Factory.php:36
A password is used as part of credentials for authentication.
Definition: Password.php:31
Definition: UI.php:24
Provides common functionality for UI tests.
Definition: Base.php:337
DefNamesource $name_source
getOr(string $name, $default)
@inheritcoc
has($name)
@inheritcoc
Describes how Input-Elements want to interact with posted data.
Definition: InputData.php:30
This describes commonalities between all inputs.
Definition: Input.php:47
$post
Definition: ltitoken.php:46
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.