ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
FormTest Class Reference

Test on form implementation. More...

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

Public Member Functions

 getUIFactory ()
 
 buildDataFactory ()
 
 testGetInputs ()
 
 testExtractPostData ()
 
 testWithRequest ()
 
 testWithRequestRespectsKeys ()
 
 testGetData ()
 
 testGetDataRespectsKeys ()
 
 testGetDataFaulty ()
 
 testWithAdditionalTransformation ()
 
 testNameInputsRespectsKeys ()
 
 testFormWithoutRequiredField ()
 
 testFormWithRequiredField ()
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getRefinery ()
 
 getImagePathResolver ()
 
 getDataFactory ()
 
 getHelpTextRetriever ()
 
 getUploadLimitResolver ()
 
 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 85 of file FormTest.php.

Member Function Documentation

◆ buildButtonFactory()

FormTest::buildButtonFactory ( )
protected

Definition at line 111 of file FormTest.php.

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

◆ buildDataFactory()

FormTest::buildDataFactory ( )

Definition at line 130 of file FormTest.php.

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

◆ buildFactory()

FormTest::buildFactory ( )
protected

Definition at line 93 of file FormTest.php.

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

◆ buildInputFactory()

FormTest::buildInputFactory ( )
protected

Definition at line 98 of file FormTest.php.

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

98  : Input\Field\Factory
99  {
100  $df = new Data\Factory();
101  $this->language = $this->createMock(ilLanguage::class);
102  return new Input\Field\Factory(
103  $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
104  new SignalGenerator(),
105  $df,
106  new Refinery($df, $this->language),
107  $this->language
108  );
109  }
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This describes commonalities between all inputs.
Definition: Input.php:46
+ Here is the call graph for this function:

◆ buildTransformation()

FormTest::buildTransformation ( Closure  $trafo)
protected

Definition at line 116 of file FormTest.php.

References ILIAS\Repository\$refinery.

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

◆ getUIFactory()

FormTest::getUIFactory ( )

Definition at line 125 of file FormTest.php.

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

◆ inputMock()

FormTest::inputMock ( )
protected
Returns
Input|mixed|MockObject

Definition at line 429 of file FormTest.php.

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

◆ testExtractPostData()

FormTest::testExtractPostData ( )

Definition at line 165 of file FormTest.php.

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

◆ testFormWithoutRequiredField()

FormTest::testFormWithoutRequiredField ( )

Definition at line 467 of file FormTest.php.

References Vendor\Package\$f.

467  : void
468  {
469  $f = $this->buildFactory();
470  $if = $this->buildInputFactory();
471  $inputs = [$if->text(""), $if->text("")];
472  $form = new ConcreteForm($this->buildInputFactory(), new DefNamesource(), $inputs);
473 
474  $this->assertFalse($form->hasRequiredInputs());
475  }
buildInputFactory()
Definition: FormTest.php:98
array $inputs
Definition: FormTest.php:91
buildFactory()
Definition: FormTest.php:93

◆ testFormWithRequiredField()

FormTest::testFormWithRequiredField ( )

Definition at line 477 of file FormTest.php.

References Vendor\Package\$f.

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

◆ testGetData()

FormTest::testGetData ( )

Definition at line 255 of file FormTest.php.

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

◆ testGetDataFaulty()

FormTest::testGetDataFaulty ( )

Definition at line 325 of file FormTest.php.

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

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

◆ testGetDataRespectsKeys()

FormTest::testGetDataRespectsKeys ( )

Definition at line 290 of file FormTest.php.

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

◆ testGetInputs()

FormTest::testGetInputs ( )

Definition at line 135 of file FormTest.php.

References FixedNameSource\$name.

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

◆ testNameInputsRespectsKeys()

FormTest::testNameInputsRespectsKeys ( )

Definition at line 411 of file FormTest.php.

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

◆ testWithAdditionalTransformation()

FormTest::testWithAdditionalTransformation ( )

Definition at line 369 of file FormTest.php.

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

◆ testWithRequest()

FormTest::testWithRequest ( )

Definition at line 177 of file FormTest.php.

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

◆ testWithRequestRespectsKeys()

FormTest::testWithRequestRespectsKeys ( )

Definition at line 216 of file FormTest.php.

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

Field Documentation

◆ $inputs

array FormTest::$inputs
protected

Definition at line 91 of file FormTest.php.

◆ $language

FormTest::$language
protected

Definition at line 90 of file FormTest.php.


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