ILIAS  release_8 Revision v8.24
StandardFormTest Class Reference

Test on standard form implementation. More...

+ Inheritance diagram for StandardFormTest:
+ Collaboration diagram for StandardFormTest:

Public Member Functions

 getUIFactory ()
 
 test_getPostURL ()
 
 test_render ()
 
 test_submit_caption ()
 
 test_submit_caption_render ()
 
 test_render_no_url ()
 
 testRenderWithErrorOnField ()
 
 testRenderWithErrorOnForm ()
 
 testStandardFormRenderWithRequired ()
 
- 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 ()
 
 buildInputFactory ()
 
 buildButtonFactory ()
 
- 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...
 

Detailed Description

Test on standard form implementation.

Definition at line 72 of file StandardFormTest.php.

Member Function Documentation

◆ buildButtonFactory()

StandardFormTest::buildButtonFactory ( )
protected

Definition at line 92 of file StandardFormTest.php.

92 : I\Button\Factory
93 {
94 return new I\Button\Factory();
95 }

Referenced by getUIFactory().

+ Here is the caller graph for this function:

◆ buildFactory()

StandardFormTest::buildFactory ( )
protected

Definition at line 74 of file StandardFormTest.php.

74 : I\Input\Container\Form\Factory
75 {
76 return new I\Input\Container\Form\Factory($this->buildInputFactory());
77 }

References buildInputFactory().

Referenced by test_getPostURL(), test_render(), test_render_no_url(), test_submit_caption(), test_submit_caption_render(), and testStandardFormRenderWithRequired().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildInputFactory()

StandardFormTest::buildInputFactory ( )
protected

Definition at line 79 of file StandardFormTest.php.

79 : I\Input\Field\Factory
80 {
81 $df = new Data\Factory();
82 $language = $this->createMock(ilLanguage::class);
83 return new I\Input\Field\Factory(
84 $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
85 new SignalGenerator(),
86 $df,
87 new \ILIAS\Refinery\Factory($df, $language),
88 $language
89 );
90 }
Builds data types.
Definition: Factory.php:21
This describes commonalities between all inputs.
Definition: Input.php:49
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 buildFactory(), test_getPostURL(), test_render(), test_render_no_url(), test_submit_caption(), test_submit_caption_render(), and testStandardFormRenderWithRequired().

+ Here is the caller graph for this function:

◆ getUIFactory()

StandardFormTest::getUIFactory ( )

Reimplemented from ILIAS_UI_TestBase.

Definition at line 97 of file StandardFormTest.php.

References buildButtonFactory().

+ Here is the call graph for this function:

◆ test_getPostURL()

StandardFormTest::test_getPostURL ( )

Definition at line 102 of file StandardFormTest.php.

102 : void
103 {
104 $f = $this->buildFactory();
105 $if = $this->buildInputFactory();
106 $url = "MY_URL";
107 $form = $f->standard($url, [$if->text("label")]);
108 $this->assertEquals($url, $form->getPostURL());
109 }
$url

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

+ Here is the call graph for this function:

◆ test_render()

StandardFormTest::test_render ( )

Definition at line 111 of file StandardFormTest.php.

111 : void
112 {
113 $f = $this->buildFactory();
114 $if = $this->buildInputFactory();
115
116 $url = "MY_URL";
117 $form = $f->standard($url, [
118 $if->text("label", "byline"),
119 ]);
120
121 $r = $this->getDefaultRenderer();
122 $html = $this->brutallyTrimHTML($r->render($form));
123
124 $expected = $this->brutallyTrimHTML('
125<form role="form" class="il-standard-form form-horizontal" enctype="multipart/form-data" action="MY_URL" method="post" novalidate="novalidate">
126 <div class="il-standard-form-header clearfix">
127 <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">save</button></div>
128 </div>
129 <div class="form-group row">
130 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
131 <div class="col-sm-8 col-md-9 col-lg-10">
132 <input id="id_1" type="text" name="form/input_0" class="form-control form-control-sm"/>
133 <div class="help-block">byline</div>
134 </div>
135 </div>
136 <div class="il-standard-form-footer clearfix">
137 <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">save</button></div>
138 </div>
139</form>
140 ');
141 $this->assertHTMLEquals($expected, $html);
142 }
assertHTMLEquals(string $expected_html_as_string, string $html_as_string)
Definition: Base.php:427
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, $url, ILIAS_UI_TestBase\assertHTMLEquals(), ILIAS_UI_TestBase\brutallyTrimHTML(), buildFactory(), buildInputFactory(), and ILIAS_UI_TestBase\getDefaultRenderer().

+ Here is the call graph for this function:

◆ test_render_no_url()

StandardFormTest::test_render_no_url ( )

Definition at line 195 of file StandardFormTest.php.

195 : void
196 {
197 $f = $this->buildFactory();
198 $if = $this->buildInputFactory();
199
200 $url = "";
201 $form = $f->standard($url, [
202 $if->text("label", "byline"),
203 ]);
204
205 $r = $this->getDefaultRenderer();
206 $html = $this->brutallyTrimHTML($r->render($form));
207
208 $expected = $this->brutallyTrimHTML('
209<form role="form" class="il-standard-form form-horizontal" enctype="multipart/form-data" method="post" novalidate="novalidate">
210 <div class="il-standard-form-header clearfix">
211 <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">save</button></div>
212 </div>
213 <div class="form-group row">
214 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
215 <div class="col-sm-8 col-md-9 col-lg-10">
216 <input id="id_1" type="text" name="form/input_0" class="form-control form-control-sm"/>
217 <div class="help-block">byline</div>
218 </div>
219 </div>
220 <div class="il-standard-form-footer clearfix">
221 <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">save</button></div>
222 </div>
223</form>
224 ');
225 $this->assertHTMLEquals($expected, $html);
226 }

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

+ Here is the call graph for this function:

◆ test_submit_caption()

StandardFormTest::test_submit_caption ( )

Definition at line 144 of file StandardFormTest.php.

144 : void
145 {
146 $f = $this->buildFactory();
147 $if = $this->buildInputFactory();
148
149 $url = "MY_URL";
150 $form = $f->standard($url, [
151 $if->text("label", "byline"),
152 ]);
153
154 $this->assertNull($form->getSubmitCaption());
155
156 $caption = 'Caption';
157 $form = $form->withSubmitCaption($caption);
158
159 $this->assertEquals($caption, $form->getSubmitCaption());
160 }

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

+ Here is the call graph for this function:

◆ test_submit_caption_render()

StandardFormTest::test_submit_caption_render ( )

Definition at line 162 of file StandardFormTest.php.

162 : void
163 {
164 $f = $this->buildFactory();
165 $if = $this->buildInputFactory();
166
167 $url = "MY_URL";
168 $form = $f->standard($url, [
169 $if->text("label", "byline"),
170 ])->withSubmitCaption('create');
171
172 $r = $this->getDefaultRenderer();
173 $html = $this->brutallyTrimHTML($r->render($form));
174
175 $expected = $this->brutallyTrimHTML('
176<form role="form" class="il-standard-form form-horizontal" enctype="multipart/form-data" action="MY_URL" method="post" novalidate="novalidate">
177 <div class="il-standard-form-header clearfix">
178 <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">create</button></div>
179 </div>
180 <div class="form-group row">
181 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
182 <div class="col-sm-8 col-md-9 col-lg-10">
183 <input id="id_1" type="text" name="form/input_0" class="form-control form-control-sm"/>
184 <div class="help-block">byline</div>
185 </div>
186 </div>
187 <div class="il-standard-form-footer clearfix">
188 <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">create</button></div>
189 </div>
190</form>
191 ');
192 $this->assertHTMLEquals($expected, $html);
193 }

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

+ Here is the call graph for this function:

◆ testRenderWithErrorOnField()

StandardFormTest::testRenderWithErrorOnField ( )

Definition at line 229 of file StandardFormTest.php.

229 : void
230 {
231 $r = $this->getDefaultRenderer();
232 $df = new Data\Factory();
233 $language = $this->createMock(\ilLanguage::class);
234 $language
235 ->expects($this->once())
236 ->method("txt")
237 ->willReturn('testing error message');
238
239 $refinery = new \ILIAS\Refinery\Factory($df, $language);
240
242 $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
243 new SignalGenerator(),
244 $df,
245 $refinery,
246 $language
247 );
248
249 $fail = $refinery->custom()->constraint(function ($v) {
250 return false;
251 }, "This is invalid...");
252 $input = $if->text("label", "byline");
253
254 $input = $input->withAdditionalTransformation($fail);
255
256 $form = new Form\Standard($if, new InputNameSource(), '', [$input]);
257
258 $request = $this->createMock(ServerRequestInterface::class);
259 $request
260 ->expects($this->once())
261 ->method("getParsedBody")
262 ->willReturn([
263 'form_0/input_1' => ''
264 ]);
265
266 $form = $form->withRequest($request);
267 $this->assertNull($form->getData());
268
269 $html = $this->brutallyTrimHTML($r->render($form));
270 $expected = $this->brutallyTrimHTML('
271 <form role="form" class="il-standard-form form-horizontal" enctype="multipart/form-data" method="post" novalidate="novalidate">
272 <div class="il-standard-form-header clearfix">
273 <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">save</button></div>
274 </div>
275
276 <div class="help-block alert alert-danger" role="alert">testing error message</div>
277
278 <div class="form-group row">
279 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
280 <div class="col-sm-8 col-md-9 col-lg-10">
281 <div class="help-block alert alert-danger" aria-describedby="id_1" role="alert">This is invalid...</div>
282 <input id="id_1" type="text" name="form_0/input_1" class="form-control form-control-sm" />
283 <div class="help-block">byline</div>
284 </div>
285 </div>
286 <div class="il-standard-form-footer clearfix">
287 <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">save</button></div>
288 </div>
289 </form>
290 ');
291 $this->assertHTMLEquals($expected, $html);
292 }
Factory for Date Formats.
Definition: Factory.php:27
Refinery Factory $refinery

References ILIAS\Repository\$refinery, ILIAS_UI_TestBase\assertHTMLEquals(), ILIAS_UI_TestBase\brutallyTrimHTML(), and ILIAS_UI_TestBase\getDefaultRenderer().

+ Here is the call graph for this function:

◆ testRenderWithErrorOnForm()

StandardFormTest::testRenderWithErrorOnForm ( )

Definition at line 295 of file StandardFormTest.php.

295 : void
296 {
297 $r = $this->getDefaultRenderer();
298 $df = new Data\Factory();
299 $language = $this->createMock(\ilLanguage::class);
300 $refinery = new \ILIAS\Refinery\Factory($df, $language);
301
303 $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
304 new SignalGenerator(),
305 $df,
306 $refinery,
307 $language
308 );
309
310 $fail = $refinery->custom()->constraint(function ($v) {
311 return false;
312 }, "This is a fail on form.");
313 $input = $if->text("label", "byline");
314
315 $form = new Form\Standard($if, new InputNameSource(), '', [$input]);
316 $form = $form->withAdditionalTransformation($fail);
317
318 $request = $this->createMock(ServerRequestInterface::class);
319 $request
320 ->expects($this->once())
321 ->method("getParsedBody")
322 ->willReturn([
323 'form_0/input_1' => ''
324 ]);
325
326 $form = $form->withRequest($request);
327 $this->assertNull($form->getData());
328
329 $html = $this->brutallyTrimHTML($r->render($form));
330 $expected = $this->brutallyTrimHTML('
331 <form role="form" class="il-standard-form form-horizontal" enctype="multipart/form-data" method="post" novalidate="novalidate">
332 <div class="il-standard-form-header clearfix">
333 <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">save</button></div>
334 </div>
335
336 <div class="help-block alert alert-danger" role="alert">This is a fail on form.</div>
337
338 <div class="form-group row">
339 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label</label>
340 <div class="col-sm-8 col-md-9 col-lg-10">
341 <input id="id_1" type="text" name="form_0/input_1" class="form-control form-control-sm" />
342 <div class="help-block">byline</div>
343 </div>
344 </div>
345 <div class="il-standard-form-footer clearfix">
346 <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">save</button></div>
347 </div>
348 </form>
349 ');
350 $this->assertHTMLEquals($expected, $html);
351 }

References ILIAS\Repository\$refinery, ILIAS_UI_TestBase\assertHTMLEquals(), ILIAS_UI_TestBase\brutallyTrimHTML(), and ILIAS_UI_TestBase\getDefaultRenderer().

+ Here is the call graph for this function:

◆ testStandardFormRenderWithRequired()

StandardFormTest::testStandardFormRenderWithRequired ( )

Definition at line 353 of file StandardFormTest.php.

353 : void
354 {
355 $f = $this->buildFactory();
356 $if = $this->buildInputFactory();
357
358 $url = "MY_URL";
359 $form = $f->standard($url, [$if->text("label", "byline")->withRequired(true)]);
360
361 $r = $this->getDefaultRenderer();
362 $html = $this->brutallyTrimHTML($r->render($form));
363
364 $expected = $this->brutallyTrimHTML('
365<form role="form" class="il-standard-form form-horizontal" enctype="multipart/form-data" action="MY_URL" method="post" novalidate="novalidate">
366 <div class="il-standard-form-header clearfix">
367 <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">save</button></div>
368 </div>
369 <div class="form-group row">
370 <label for="id_1" class="control-label col-sm-4 col-md-3 col-lg-2">label<span class="asterisk">*</span></label>
371 <div class="col-sm-8 col-md-9 col-lg-10">
372 <input id="id_1" type="text" name="form/input_0" class="form-control form-control-sm"/>
373 <div class="help-block">byline</div>
374 </div>
375 </div>
376 <div class="il-standard-form-footer clearfix">
377 <span class="asterisk">*</span><span class="small"> required_field</span>
378 </div>
379 <div class="il-standard-form-footer clearfix">
380 <div class="il-standard-form-cmd"><button class="btn btn-default" data-action="">save</button></div>
381 </div>
382</form>
383 ');
384 $this->assertHTMLEquals($expected, $html);
385 }

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

+ Here is the call graph for this function:

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