ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 ()
 

Protected Member Functions

 buildFactory ()
 
 buildInputFactory ()
 
 buildButtonFactory ()
 
 buildTransformation (Closure $trafo)
 
 inputMock ()
 

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 114 of file FormTest.php.

114  : I\Button\Factory
115  {
116  return new I\Button\Factory();
117  }

◆ buildDataFactory()

FormTest::buildDataFactory ( )

Definition at line 133 of file FormTest.php.

133  : Data\Factory
134  {
135  return new Data\Factory();
136  }

◆ 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(
96  $this->buildInputFactory(),
97  new SignalGenerator()
98  );
99  }
buildInputFactory()
Definition: FormTest.php:101

◆ buildInputFactory()

FormTest::buildInputFactory ( )
protected

Definition at line 101 of file FormTest.php.

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

101  : Input\Field\Factory
102  {
103  $df = new Data\Factory();
104  $this->language = $this->createMock(ILIAS\Language\Language::class);
105  return new Input\Field\Factory(
106  $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
107  new SignalGenerator(),
108  $df,
109  new Refinery($df, $this->language),
110  $this->language
111  );
112  }
Interface Observer Contains several chained tasks and infos about them.
This describes commonalities between all inputs.
Definition: Input.php:46
language()
description: > Example for rendring a language glyph.
Definition: language.php:41
+ Here is the call graph for this function:

◆ buildTransformation()

FormTest::buildTransformation ( Closure  $trafo)
protected

Definition at line 119 of file FormTest.php.

References ILIAS\UI\examples\Layout\Page\Standard\$refinery.

120  {
121  $dataFactory = new Data\Factory();
122  $language = $this->createMock(ILIAS\Language\Language::class);
123  $refinery = new Refinery($dataFactory, $language);
124 
125  return $refinery->custom()->transformation($trafo);
126  }
Transform values according to custom configuration.
Interface Observer Contains several chained tasks and infos about them.

◆ getUIFactory()

FormTest::getUIFactory ( )

Definition at line 128 of file FormTest.php.

128  : NoUIFactory
129  {
130  return new WithButtonNoUIFactory($this->buildButtonFactory());
131  }
buildButtonFactory()
Definition: FormTest.php:114

◆ inputMock()

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

Definition at line 432 of file FormTest.php.

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

◆ testExtractPostData()

FormTest::testExtractPostData ( )

Definition at line 168 of file FormTest.php.

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

◆ testFormWithoutRequiredField()

FormTest::testFormWithoutRequiredField ( )

Definition at line 470 of file FormTest.php.

References Vendor\Package\$f.

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

◆ testFormWithRequiredField()

FormTest::testFormWithRequiredField ( )

Definition at line 480 of file FormTest.php.

References Vendor\Package\$f.

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

◆ testGetData()

FormTest::testGetData ( )

Definition at line 258 of file FormTest.php.

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

◆ testGetDataFaulty()

FormTest::testGetDataFaulty ( )

Definition at line 328 of file FormTest.php.

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

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

◆ testGetDataRespectsKeys()

FormTest::testGetDataRespectsKeys ( )

Definition at line 293 of file FormTest.php.

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

◆ testGetInputs()

FormTest::testGetInputs ( )

Definition at line 138 of file FormTest.php.

References FixedNameSource\$name.

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

◆ testNameInputsRespectsKeys()

FormTest::testNameInputsRespectsKeys ( )

Definition at line 414 of file FormTest.php.

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

◆ testWithAdditionalTransformation()

FormTest::testWithAdditionalTransformation ( )

Definition at line 372 of file FormTest.php.

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

◆ testWithRequest()

FormTest::testWithRequest ( )

Definition at line 180 of file FormTest.php.

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

◆ testWithRequestRespectsKeys()

FormTest::testWithRequestRespectsKeys ( )

Definition at line 219 of file FormTest.php.

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

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: