ILIAS  release_8 Revision v8.24
TextInputTest Class Reference
+ Inheritance diagram for TextInputTest:
+ Collaboration diagram for TextInputTest:

Public Member Functions

 setUp ()
 
 test_implements_factory_interface ()
 
 test_render ()
 
 test_render_error ()
 
 test_render_no_byline ()
 
 test_render_value ()
 
 test_render_value_0 ()
 
 test_render_required ()
 
 test_render_disabled ()
 
 test_max_length ()
 
 test_render_max_value ()
 
 test_value_required ()
 
 test_stripsTags ()
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getRefinery ()
 
 getImagePathResolver ()
 
 getDataFactory ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
 
 getDecoratedRenderer (Renderer $default)
 
 normalizeHTML (string $html)
 
 assertHTMLEquals (string $expected_html_as_string, string $html_as_string)
 

Protected Member Functions

 buildFactory ()
 
- Protected Member Functions inherited from ILIAS_UI_TestBase
 brutallyTrimHTML (string $html)
 A more radical version of normalizeHTML. More...
 
 brutallyTrimSignals (string $html)
 A naive replacement of all il_signal-ids with dots to ease comparisons of rendered output. More...
 

Protected Attributes

DefNamesource $name_source
 

Detailed Description

Definition at line 31 of file TextInputTest.php.

Member Function Documentation

◆ buildFactory()

TextInputTest::buildFactory ( )
protected

Definition at line 40 of file TextInputTest.php.

40 : I\Input\Field\Factory
41 {
42 $df = new Data\Factory();
43 $language = $this->createMock(ilLanguage::class);
44 return new I\Input\Field\Factory(
45 $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
46 new SignalGenerator(),
47 $df,
48 new Refinery($df, $language),
49 $language
50 );
51 }
This is a legacy support of Component\Input\Field\Input that has been moved to Component\Input\Contai...
Definition: Input.php:32
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.

Referenced by test_implements_factory_interface(), test_max_length(), test_render(), test_render_disabled(), test_render_error(), test_render_max_value(), test_render_no_byline(), test_render_required(), test_render_value(), test_render_value_0(), test_stripsTags(), and test_value_required().

+ Here is the caller graph for this function:

◆ setUp()

TextInputTest::setUp ( )

Reimplemented from ILIAS_UI_TestBase.

Definition at line 35 of file TextInputTest.php.

35 : void
36 {
37 $this->name_source = new DefNamesource();
38 }

◆ test_implements_factory_interface()

TextInputTest::test_implements_factory_interface ( )

Definition at line 53 of file TextInputTest.php.

53 : void
54 {
55 $f = $this->buildFactory();
56
57 $text = $f->text("label", "byline");
58
59 $this->assertInstanceOf(\ILIAS\UI\Component\Input\Container\Form\FormInput::class, $text);
60 $this->assertInstanceOf(Field\Text::class, $text);
61 }

References Vendor\Package\$f, and buildFactory().

+ Here is the call graph for this function:

◆ test_max_length()

TextInputTest::test_max_length ( )

Definition at line 201 of file TextInputTest.php.

201 : void
202 {
203 $f = $this->buildFactory();
204
205 $text = $f->text("")
206 ->withMaxLength(4);
207
208 $this->assertEquals(4, $text->getMaxLength());
209
210 $text1 = $text->withValue("1234");
211 $this->assertEquals("1234", $text1->getValue());
212
213 $this->expectException(InvalidArgumentException::class);
214 $this->expectExceptionMessage("Argument 'value': Display value does not match input type.");
215 $text->withValue("12345");
216 }

References Vendor\Package\$f, and buildFactory().

+ Here is the call graph for this function:

◆ test_render()

TextInputTest::test_render ( )

Definition at line 63 of file TextInputTest.php.

63 : void
64 {
65 $f = $this->buildFactory();
66 $label = "label";
67 $byline = "byline";
68 $text = $f->text($label, $byline)->withNameFrom($this->name_source);
69
70 $r = $this->getDefaultRenderer();
71 $html = $this->brutallyTrimHTML($r->render($text));
72
73 $expected = $this->brutallyTrimHTML('
74<div class="form-group row">
75 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
76 <div class="col-sm-8 col-md-9 col-lg-10">
77 <input id="id_1" type="text" name="name_0" class="form-control form-control-sm" />
78 <div class="help-block">byline</div>
79 </div>
80</div>
81');
82 $this->assertEquals($expected, $html);
83 }
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:444
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355

References Vendor\Package\$f, ILIAS_UI_TestBase\brutallyTrimHTML(), buildFactory(), and ILIAS_UI_TestBase\getDefaultRenderer().

+ Here is the call graph for this function:

◆ test_render_disabled()

TextInputTest::test_render_disabled ( )

Definition at line 183 of file TextInputTest.php.

183 : void
184 {
185 $f = $this->buildFactory();
186 $label = "label";
187 $text = $f->text($label)->withNameFrom($this->name_source)->withDisabled(true);
188
189 $r = $this->getDefaultRenderer();
190 $html = $this->brutallyTrimHTML($r->render($text));
191
192 $expected = $this->brutallyTrimHTML('
193<div class="form-group row">
194 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
195 <div class="col-sm-8 col-md-9 col-lg-10"><input id="id_1" type="text" name="name_0" disabled="disabled" class="form-control form-control-sm" /></div>
196</div>
197');
198 $this->assertEquals($expected, $html);
199 }

References Vendor\Package\$f, ILIAS_UI_TestBase\brutallyTrimHTML(), buildFactory(), and ILIAS_UI_TestBase\getDefaultRenderer().

+ Here is the call graph for this function:

◆ test_render_error()

TextInputTest::test_render_error ( )

Definition at line 85 of file TextInputTest.php.

85 : void
86 {
87 $f = $this->buildFactory();
88 $label = "label";
89 $byline = "byline";
90 $error = "an_error";
91 $text = $f->text($label, $byline)->withNameFrom($this->name_source)->withError($error);
92
93 $r = $this->getDefaultRenderer();
94 $html = $this->brutallyTrimHTML($r->render($text));
95
96 $expected = $this->brutallyTrimHTML('
97<div class="form-group row">
98 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
99 <div class="col-sm-8 col-md-9 col-lg-10">
100 <div class="help-block alert alert-danger" aria-describedby="id_1" role="alert">an_error</div>
101 <input id="id_1" type="text" name="name_0" class="form-control form-control-sm" />
102 <div class="help-block">byline</div>
103 </div>
104</div>
105');
106 $this->assertEquals($expected, $html);
107 }

References Vendor\Package\$f, ILIAS_UI_TestBase\brutallyTrimHTML(), buildFactory(), and ILIAS_UI_TestBase\getDefaultRenderer().

+ Here is the call graph for this function:

◆ test_render_max_value()

TextInputTest::test_render_max_value ( )

Definition at line 218 of file TextInputTest.php.

218 : void
219 {
220 $f = $this->buildFactory();
221 $label = "label";
222 $text = $f->text($label)->withNameFrom($this->name_source)->withMaxLength(8);
223
224 $r = $this->getDefaultRenderer();
225 $html = $this->brutallyTrimHTML($r->render($text));
226
227 $expected = $this->brutallyTrimHTML('
228<div class="form-group row">
229 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
230 <div class="col-sm-8 col-md-9 col-lg-10"> <input id="id_1" type="text" name="name_0" maxlength="8" class="form-control form-control-sm" /> </div>
231</div>
232');
233 $this->assertEquals($expected, $html);
234 }

References Vendor\Package\$f, ILIAS_UI_TestBase\brutallyTrimHTML(), buildFactory(), and ILIAS_UI_TestBase\getDefaultRenderer().

+ Here is the call graph for this function:

◆ test_render_no_byline()

TextInputTest::test_render_no_byline ( )

Definition at line 109 of file TextInputTest.php.

109 : void
110 {
111 $f = $this->buildFactory();
112 $label = "label";
113 $text = $f->text($label)->withNameFrom($this->name_source);
114
115 $r = $this->getDefaultRenderer();
116 $html = $this->brutallyTrimHTML($r->render($text));
117
118 $expected = $this->brutallyTrimHTML('
119<div class="form-group row">
120 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
121 <div class="col-sm-8 col-md-9 col-lg-10"><input id="id_1" type="text" name="name_0" class="form-control form-control-sm" /></div>
122</div>
123');
124 $this->assertEquals($expected, $html);
125 }

References Vendor\Package\$f, ILIAS_UI_TestBase\brutallyTrimHTML(), buildFactory(), and ILIAS_UI_TestBase\getDefaultRenderer().

+ Here is the call graph for this function:

◆ test_render_required()

TextInputTest::test_render_required ( )

Definition at line 165 of file TextInputTest.php.

165 : void
166 {
167 $f = $this->buildFactory();
168 $label = "label";
169 $text = $f->text($label)->withNameFrom($this->name_source)->withRequired(true);
170
171 $r = $this->getDefaultRenderer();
172 $html = $this->brutallyTrimHTML($r->render($text));
173
174 $expected = $this->brutallyTrimHTML('
175<div class="form-group row">
176 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label<span class="asterisk">*</span></label>
177 <div class="col-sm-8 col-md-9 col-lg-10"><input id="id_1" type="text" name="name_0" class="form-control form-control-sm" /></div>
178</div>
179');
180 $this->assertEquals($expected, $html);
181 }

References Vendor\Package\$f, ILIAS_UI_TestBase\brutallyTrimHTML(), buildFactory(), and ILIAS_UI_TestBase\getDefaultRenderer().

+ Here is the call graph for this function:

◆ test_render_value()

TextInputTest::test_render_value ( )

Definition at line 127 of file TextInputTest.php.

127 : void
128 {
129 $f = $this->buildFactory();
130 $label = "label";
131 $value = "value";
132 $text = $f->text($label)->withValue($value)->withNameFrom($this->name_source);
133
134 $r = $this->getDefaultRenderer();
135 $html = $this->brutallyTrimHTML($r->render($text));
136
137 $expected = $this->brutallyTrimHTML('
138<div class="form-group row">
139 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
140 <div class="col-sm-8 col-md-9 col-lg-10"><input id="id_1" type="text" value="value" name="name_0" class="form-control form-control-sm" /></div>
141</div>
142');
143 $this->assertEquals($expected, $html);
144 }

References Vendor\Package\$f, ILIAS_UI_TestBase\brutallyTrimHTML(), buildFactory(), and ILIAS_UI_TestBase\getDefaultRenderer().

+ Here is the call graph for this function:

◆ test_render_value_0()

TextInputTest::test_render_value_0 ( )

Definition at line 146 of file TextInputTest.php.

146 : void
147 {
148 $f = $this->buildFactory();
149 $label = "label";
150 $value = "0";
151 $text = $f->text($label)->withValue($value)->withNameFrom($this->name_source);
152
153 $r = $this->getDefaultRenderer();
154 $html = $this->brutallyTrimHTML($r->render($text));
155
156 $expected = $this->brutallyTrimHTML('
157<div class="form-group row">
158 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
159 <div class="col-sm-8 col-md-9 col-lg-10"><input id="id_1" type="text" value="0" name="name_0" class="form-control form-control-sm" /></div>
160</div>
161');
162 $this->assertEquals($expected, $html);
163 }

References Vendor\Package\$f, ILIAS_UI_TestBase\brutallyTrimHTML(), buildFactory(), and ILIAS_UI_TestBase\getDefaultRenderer().

+ Here is the call graph for this function:

◆ test_stripsTags()

TextInputTest::test_stripsTags ( )

Definition at line 253 of file TextInputTest.php.

253 : void
254 {
255 $f = $this->buildFactory();
256 $name = "name_0";
257 $text = $f->text("")
258 ->withNameFrom($this->name_source)
259 ->withInput(new DefInputData([$name => "<script>alert()</script>"]));
260
261 $content = $text->getContent();
262 $this->assertEquals("alert()", $content->value());
263 }
if($format !==null) $name
Definition: metadata.php:247

References Vendor\Package\$f, $name, and buildFactory().

+ Here is the call graph for this function:

◆ test_value_required()

TextInputTest::test_value_required ( )

Definition at line 236 of file TextInputTest.php.

236 : void
237 {
238 $f = $this->buildFactory();
239 $label = "label";
240 $name = "name_0";
241 $text = $f->text($label)->withNameFrom($this->name_source)->withRequired(true);
242
243 $text1 = $text->withInput(new DefInputData([$name => "0"]));
244 $value1 = $text1->getContent();
245 $this->assertTrue($value1->isOk());
246 $this->assertEquals("0", $value1->value());
247
248 $text2 = $text->withInput(new DefInputData([$name => ""]));
249 $value2 = $text2->getContent();
250 $this->assertTrue($value2->isError());
251 }

References Vendor\Package\$f, $name, and buildFactory().

+ Here is the call graph for this function:

Field Documentation

◆ $name_source

DefNamesource TextInputTest::$name_source
protected

Definition at line 33 of file TextInputTest.php.


The documentation for this class was generated from the following file: