ILIAS  release_8 Revision v8.24
FormTest Class Reference

Test on form implementation. More...

+ Inheritance diagram for FormTest:
+ Collaboration diagram for FormTest:

Public Member Functions

 getUIFactory ()
 
 buildDataFactory ()
 
 test_getInputs ()
 
 test_extractPostData ()
 
 test_withRequest ()
 
 test_withRequest_respects_keys ()
 
 test_getData ()
 
 test_getData_respects_keys ()
 
 test_getData_faulty ()
 
 test_withAdditionalTransformation ()
 
 test_nameInputs_respects_keys ()
 
 testFormWithoutRequiredField ()
 
 testFormWithRequiredField ()
 
- 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 ()
 
 buildTransformation (Closure $trafo)
 
 inputMock ()
 
- 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

 $language
 
array $inputs
 

Detailed Description

Test on form implementation.

Definition at line 84 of file FormTest.php.

Member Function Documentation

◆ buildButtonFactory()

FormTest::buildButtonFactory ( )
protected

Definition at line 110 of file FormTest.php.

110 : I\Button\Factory
111 {
112 return new I\Button\Factory();
113 }

Referenced by getUIFactory().

+ Here is the caller graph for this function:

◆ buildDataFactory()

FormTest::buildDataFactory ( )

Definition at line 129 of file FormTest.php.

129 : Data\Factory
130 {
131 return new Data\Factory();
132 }

Referenced by test_getData(), test_getData_faulty(), test_getData_respects_keys(), test_withAdditionalTransformation(), test_withRequest(), and test_withRequest_respects_keys().

+ Here is the caller graph for this function:

◆ buildFactory()

FormTest::buildFactory ( )
protected

Definition at line 92 of file FormTest.php.

92 : Input\Container\Form\Factory
93 {
94 return new Input\Container\Form\Factory($this->buildInputFactory());
95 }
buildInputFactory()
Definition: FormTest.php:97

References buildInputFactory().

Referenced by test_getInputs(), testFormWithoutRequiredField(), and testFormWithRequiredField().

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

◆ buildInputFactory()

FormTest::buildInputFactory ( )
protected

Definition at line 97 of file FormTest.php.

97 : Input\Field\Factory
98 {
99 $df = new Data\Factory();
100 $this->language = $this->createMock(ilLanguage::class);
101 return new Input\Field\Factory(
102 $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
103 new SignalGenerator(),
104 $df,
105 new Refinery($df, $this->language),
106 $this->language
107 );
108 }
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.

References ILIAS\UI\examples\Symbol\Glyph\Language\language().

Referenced by buildFactory(), test_extractPostData(), test_getData(), test_getData_faulty(), test_getData_respects_keys(), test_getInputs(), test_nameInputs_respects_keys(), test_withAdditionalTransformation(), test_withRequest(), test_withRequest_respects_keys(), testFormWithoutRequiredField(), and testFormWithRequiredField().

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

◆ buildTransformation()

FormTest::buildTransformation ( Closure  $trafo)
protected

Definition at line 115 of file FormTest.php.

116 {
117 $dataFactory = new Data\Factory();
118 $language = $this->createMock(ilLanguage::class);
119 $refinery = new Refinery($dataFactory, $language);
120
121 return $refinery->custom()->transformation($trafo);
122 }
Transform values according to custom configuration.
Refinery Factory $refinery

References $language, and ILIAS\Repository\$refinery.

Referenced by test_withAdditionalTransformation().

+ Here is the caller graph for this function:

◆ getUIFactory()

FormTest::getUIFactory ( )

Reimplemented from ILIAS_UI_TestBase.

Definition at line 124 of file FormTest.php.

125 {
126 return new WithButtonNoUIFactory($this->buildButtonFactory());
127 }
buildButtonFactory()
Definition: FormTest.php:110

References buildButtonFactory().

+ Here is the call graph for this function:

◆ inputMock()

FormTest::inputMock ( )
protected
Returns
Input\Field\FormInputInternal|mixed|MockObject

Definition at line 428 of file FormTest.php.

429 {
430 static $no = 1000;
431 return $this
432 ->getMockBuilder(Input\Field\FormInputInternal::class)
433 ->onlyMethods([
434 "getName",
435 "withDedicatedName",
436 "withNameFrom",
437 "withInput",
438 "getContent",
439 "getLabel",
440 "withLabel",
441 "getByline",
442 "withByline",
443 "isRequired",
444 "withRequired",
445 "isDisabled",
446 "withDisabled",
447 "getValue",
448 "withValue",
449 "getError",
450 "withError",
451 "withAdditionalTransformation",
452 "getUpdateOnLoadCode",
453 "getCanonicalName",
454 "withOnLoadCode",
455 "withAdditionalOnLoadCode",
456 "getOnLoadCode",
457 "withOnUpdate",
458 "appendOnUpdate",
459 "withResetTriggeredSignals",
460 "getTriggeredSignals"
461 ])
462 ->setMockClassName("Mock_InputNo" . ($no++))
463 ->getMock();
464 }

Referenced by test_getData(), test_getData_faulty(), test_getData_respects_keys(), test_withAdditionalTransformation(), test_withRequest(), and test_withRequest_respects_keys().

+ Here is the caller graph for this function:

◆ test_extractPostData()

FormTest::test_extractPostData ( )

Definition at line 164 of file FormTest.php.

164 : void
165 {
166 $form = new ConcreteForm($this->buildInputFactory(), new DefNamesource(), []);
167 $request = $this->createMock(ServerRequestInterface::class);
168 $request
169 ->expects($this->once())
170 ->method("getParsedBody")
171 ->willReturn([]);
172 $input_data = $form->_extractRequestData($request);
173 $this->assertInstanceOf(InputData::class, $input_data);
174 }

References buildInputFactory().

+ Here is the call graph for this function:

◆ test_getData()

FormTest::test_getData ( )

Definition at line 254 of file FormTest.php.

254 : void
255 {
256 $df = $this->buildDataFactory();
257 $request = $this->createMock(ServerRequestInterface::class);
258 $request
259 ->expects($this->once())
260 ->method("getParsedBody")
261 ->willReturn([]);
262
263 $input_1 = $this->inputMock();
264 $input_1
265 ->expects($this->once())
266 ->method("getContent")
267 ->willReturn($df->ok(1));
268 $input_1
269 ->expects($this->once())
270 ->method("withInput")
271 ->willReturn($input_1);
272
273 $input_2 = $this->inputMock();
274 $input_2
275 ->expects($this->once())
276 ->method("getContent")
277 ->willReturn($df->ok(2));
278 $input_2
279 ->expects($this->once())
280 ->method("withInput")
281 ->willReturn($input_2);
282
283 $form = new ConcreteForm($this->buildInputFactory(), new DefNamesource(), []);
284 $form->setInputs([$input_1, $input_2]);
285 $form = $form->withRequest($request);
286 $this->assertEquals([1, 2], $form->getData());
287 }
buildDataFactory()
Definition: FormTest.php:129
inputMock()
Definition: FormTest.php:428

References buildDataFactory(), buildInputFactory(), and inputMock().

+ Here is the call graph for this function:

◆ test_getData_faulty()

FormTest::test_getData_faulty ( )

Definition at line 324 of file FormTest.php.

324 : void
325 {
326 $df = $this->buildDataFactory();
327 $request = $this->createMock(ServerRequestInterface::class);
328 $request
329 ->expects($this->once())
330 ->method("getParsedBody")
331 ->willReturn([]);
332
333 $input_1 = $this->inputMock();
334 $input_1
335 ->expects($this->once())
336 ->method("getContent")
337 ->willReturn($df->error("error"));
338 $input_1
339 ->expects($this->once())
340 ->method("withInput")
341 ->willReturn($input_1);
342
343 $input_2 = $this->inputMock();
344 $input_2
345 ->expects($this->once())
346 ->method("getContent")
347 ->willReturn($df->ok(2));
348 $input_2
349 ->expects($this->once())
350 ->method("withInput")
351 ->willReturn($input_2);
352
353 $form = new ConcreteForm($this->buildInputFactory(), new DefNamesource(), []);
354 $form->setInputs(["foo" => $input_1, "bar" => $input_2]);
355
356 $i18n = "THERE IS SOME ERROR IN THIS GROUP";
357 $this->language
358 ->expects($this->once())
359 ->method("txt")
360 ->with("ui_error_in_group")
361 ->willReturn($i18n);
362
363 //Todo: This is not good, this should throw an error or similar.
364 $form = $form->withRequest($request);
365 $this->assertEquals(null, null);
366 }

References buildDataFactory(), buildInputFactory(), inputMock(), and ILIAS\UI\examples\Symbol\Glyph\Language\language().

+ Here is the call graph for this function:

◆ test_getData_respects_keys()

FormTest::test_getData_respects_keys ( )

Definition at line 289 of file FormTest.php.

289 : void
290 {
291 $df = $this->buildDataFactory();
292 $request = $this->createMock(ServerRequestInterface::class);
293 $request
294 ->expects($this->once())
295 ->method("getParsedBody")
296 ->willReturn([]);
297
298 $input_1 = $this->inputMock();
299 $input_1
300 ->expects($this->once())
301 ->method("getContent")
302 ->willReturn($df->ok(1));
303 $input_1
304 ->expects($this->once())
305 ->method("withInput")
306 ->willReturn($input_1);
307
308 $input_2 = $this->inputMock();
309 $input_2
310 ->expects($this->once())
311 ->method("getContent")
312 ->willReturn($df->ok(2));
313 $input_2
314 ->expects($this->once())
315 ->method("withInput")
316 ->willReturn($input_2);
317
318 $form = new ConcreteForm($this->buildInputFactory(), new DefNamesource(), []);
319 $form->setInputs(["foo" => $input_1, "bar" => $input_2]);
320 $form = $form->withRequest($request);
321 $this->assertEquals(["foo" => 1, "bar" => 2], $form->getData());
322 }

References buildDataFactory(), buildInputFactory(), and inputMock().

+ Here is the call graph for this function:

◆ test_getInputs()

FormTest::test_getInputs ( )

Definition at line 134 of file FormTest.php.

134 : void
135 {
136 $this->buildFactory();
137 $if = $this->buildInputFactory();
138 $name_source = new FixedNameSource();
139
140 $inputs = [$if->text(""), $if->text("")];
141 $form = new ConcreteForm($this->buildInputFactory(), new DefNamesource(), $inputs);
142
143 $seen_names = [];
144 $form_inputs = $form->getInputs();
145 $this->assertSameSize($inputs, $form_inputs);
146
147 foreach ($form_inputs as $input) {
148 $name = $input->getName();
149 $name_source->name = $name;
150
151 // name is a string
152 $this->assertIsString($name);
153
154 // only name is attached
155 $input = array_shift($form_inputs);
156 $this->assertEquals($input->withNameFrom($name_source), $input);
157
158 // every name can only be contained once.
159 $this->assertNotContains($name, $seen_names);
160 $seen_names[] = $name;
161 }
162 }
buildFactory()
Definition: FormTest.php:92
array $inputs
Definition: FormTest.php:90
if($format !==null) $name
Definition: metadata.php:247

References $inputs, $name, buildFactory(), and buildInputFactory().

+ Here is the call graph for this function:

◆ test_nameInputs_respects_keys()

FormTest::test_nameInputs_respects_keys ( )

Definition at line 410 of file FormTest.php.

410 : void
411 {
412 $if = $this->buildInputFactory();
413 $inputs = [
414 2 => $if->text(""),
415 "foo" => $if->text(""),
416 1 => $if->text(""),
417 $if->text(""),
418 ];
419 $form = new ConcreteForm($this->buildInputFactory(), new DefNamesource(), []);
420 $form->setInputs($inputs);
421 $named_inputs = $form->getInputs();
422 $this->assertEquals(array_keys($inputs), array_keys($named_inputs));
423 }

References $inputs, and buildInputFactory().

+ Here is the call graph for this function:

◆ test_withAdditionalTransformation()

FormTest::test_withAdditionalTransformation ( )

Definition at line 368 of file FormTest.php.

368 : void
369 {
370 $df = $this->buildDataFactory();
371 $request = $this->createMock(ServerRequestInterface::class);
372 $request
373 ->expects($this->once())
374 ->method("getParsedBody")
375 ->willReturn([]);
376
377 $input_1 = $this->inputMock();
378 $input_1
379 ->expects($this->once())
380 ->method("getContent")
381 ->willReturn($df->ok(1));
382 $input_1
383 ->expects($this->once())
384 ->method("withInput")
385 ->willReturn($input_1);
386
387 $input_2 = $this->inputMock();
388 $input_2
389 ->expects($this->once())
390 ->method("getContent")
391 ->willReturn($df->ok(2));
392 $input_2
393 ->expects($this->once())
394 ->method("withInput")
395 ->willReturn($input_2);
396
397 $form = new ConcreteForm($this->buildInputFactory(), new DefNamesource(), []);
398 $form->setInputs([$input_1, $input_2]);
399
400 $form2 = $form->withAdditionalTransformation($this->buildTransformation(function () {
401 return "transformed";
402 }));
403
404 $this->assertNotSame($form2, $form);
405 $form2 = $form2->withRequest($request);
406
407 $this->assertEquals("transformed", $form2->getData());
408 }
buildTransformation(Closure $trafo)
Definition: FormTest.php:115

References buildDataFactory(), buildInputFactory(), buildTransformation(), and inputMock().

+ Here is the call graph for this function:

◆ test_withRequest()

FormTest::test_withRequest ( )

Definition at line 176 of file FormTest.php.

176 : void
177 {
178 $df = $this->buildDataFactory();
179 $request = $this->createMock(ServerRequestInterface::class);
180 $input_data = $this->createMock(InputData::class);
181
182 $input_1 = $this->inputMock();
183 $input_1
184 ->expects($this->once())
185 ->method("withInput")
186 ->with($input_data)
187 ->willReturn($input_1);
188 $input_1
189 ->expects($this->once())
190 ->method("getContent")
191 ->willReturn($df->ok(0));
192
193 $input_2 = $this->inputMock();
194 $input_2
195 ->expects($this->once())
196 ->method("withInput")
197 ->with($input_data)
198 ->willReturn($input_2);
199 $input_2
200 ->expects($this->once())
201 ->method("getContent")
202 ->willReturn($df->ok(0));
203
204 $form = new ConcreteForm($this->buildInputFactory(), new DefNamesource(), []);
205 $form->setInputs([$input_1, $input_2]);
206 $form->input_data = $input_data;
207
208 $form2 = $form->withRequest($request);
209
210 $this->assertNotSame($form2, $form);
211 $this->assertInstanceOf(Form::class, $form2);
212 $this->assertEquals([$input_1, $input_2], $form2->getInputs());
213 }

References buildDataFactory(), buildInputFactory(), and inputMock().

+ Here is the call graph for this function:

◆ test_withRequest_respects_keys()

FormTest::test_withRequest_respects_keys ( )

Definition at line 215 of file FormTest.php.

215 : void
216 {
217 $df = $this->buildDataFactory();
218 $request = $this->createMock(ServerRequestInterface::class);
219 $input_data = $this->createMock(InputData::class);
220
221 $input_1 = $this->inputMock();
222 $input_1
223 ->expects($this->once())
224 ->method("withInput")
225 ->with($input_data)
226 ->willReturn($input_1);
227 $input_1
228 ->expects($this->once())
229 ->method("getContent")
230 ->willReturn($df->ok(0));
231
232 $input_2 = $this->inputMock();
233 $input_2
234 ->expects($this->once())
235 ->method("withInput")
236 ->with($input_data)
237 ->willReturn($input_2);
238 $input_2
239 ->expects($this->once())
240 ->method("getContent")
241 ->willReturn($df->ok(0));
242
243 $form = new ConcreteForm($this->buildInputFactory(), new DefNamesource(), []);
244 $form->setInputs(["foo" => $input_1, "bar" => $input_2]);
245 $form->input_data = $input_data;
246
247 $form2 = $form->withRequest($request);
248
249 $this->assertNotSame($form2, $form);
250 $this->assertInstanceOf(Form::class, $form2);
251 $this->assertEquals(["foo" => $input_1, "bar" => $input_2], $form2->getInputs());
252 }

References buildDataFactory(), buildInputFactory(), and inputMock().

+ Here is the call graph for this function:

◆ testFormWithoutRequiredField()

FormTest::testFormWithoutRequiredField ( )

Definition at line 466 of file FormTest.php.

466 : void
467 {
468 $f = $this->buildFactory();
469 $if = $this->buildInputFactory();
470 $inputs = [$if->text(""), $if->text("")];
471 $form = new ConcreteForm($this->buildInputFactory(), new DefNamesource(), $inputs);
472
473 $this->assertFalse($form->hasRequiredInputs());
474 }

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

+ Here is the call graph for this function:

◆ testFormWithRequiredField()

FormTest::testFormWithRequiredField ( )

Definition at line 476 of file FormTest.php.

476 : void
477 {
478 $f = $this->buildFactory();
479 $if = $this->buildInputFactory();
480 $inputs = [
481 $if->text("")->withRequired(true),
482 $if->text("")
483 ];
484 $form = new ConcreteForm($this->buildInputFactory(), new DefNamesource(), $inputs);
485 $this->assertTrue($form->hasRequiredInputs());
486 }

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

+ Here is the call graph for this function:

Field Documentation

◆ $inputs

array FormTest::$inputs
protected

◆ $language

FormTest::$language
protected

Definition at line 89 of file FormTest.php.

Referenced by buildTransformation().


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