ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
All Data Structures Namespaces Files Functions Variables Typedefs Modules Pages
InputTest Class Reference

Test on input implementation. More...

+ Inheritance diagram for InputTest:
+ Collaboration diagram for InputTest:

Public Member Functions

 setUp ()
 
 test_constructor ()
 
 test_withLabel ()
 
 test_withByline ()
 
 test_withRequired ()
 
 test_withValue ()
 
 test_withValue_throws ()
 
 test_withName ()
 
 test_withError ()
 
 test_getContent ()
 
 test_withInput ()
 
 test_only_run_withInput_with_name ()
 
 test_withInput_and_transformation ()
 
 test_withInput_and_transformation_different_order ()
 
 test_withInput_and_constraint_successfull ()
 
 test_withInput_and_constraint_fails ()
 
 test_withInput_and_constraint_fails_different_order ()
 
 test_withInput_transformation_and_constraint ()
 
 test_withInput_transformation_and_constraint_different_order ()
 
 test_withInput_constraint_and_transformation ()
 
 test_withInput_constraint_fails_and_transformation ()
 
 test_withInput_constraint_fails_and_transformation_different_order ()
 
 test_withInput_requirement_constraint ()
 
 test_withInput_toggle_requirement ()
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null)
 
 normalizeHTML ($html)
 
 assertHTMLEquals ($expected_html_as_string, $html_as_string)
 

Detailed Description

Test on input implementation.

Definition at line 90 of file InputTest.php.

Member Function Documentation

◆ setUp()

InputTest::setUp ( )

Definition at line 92 of file InputTest.php.

References input.

93  {
94  $this->data_factory = new DataFactory();
95  $this->transformation_factory = new TransformationFactory();
96  $this->validation_factory = new ValidationFactory($this->data_factory, $this->createMock(\ilLanguage::class));
97  $this->input = new DefInput($this->data_factory, $this->validation_factory, $this->transformation_factory, "label", "byline");
98  $this->name_source = new DefNamesource();
99  }
input
Definition: langcheck.php:166

◆ test_constructor()

InputTest::test_constructor ( )

Definition at line 102 of file InputTest.php.

References input.

103  {
104  $this->assertEquals("label", $this->input->getLabel());
105  $this->assertEquals("byline", $this->input->getByline());
106  }
input
Definition: langcheck.php:166

◆ test_getContent()

InputTest::test_getContent ( )

Definition at line 183 of file InputTest.php.

References input.

184  {
185  $this->expectException(\LogicException::class);
186 
187  $this->input->getContent();
188  }
input
Definition: langcheck.php:166

◆ test_only_run_withInput_with_name()

InputTest::test_only_run_withInput_with_name ( )

Definition at line 210 of file InputTest.php.

References input.

211  {
212  $raised = false;
213  try {
214  $this->input->withInput(new DefPostData([]));
215  $this->assertFalse("This should not happen.");
216  } catch (\LogicException $e) {
217  $raised = true;
218  }
219  $this->assertTrue($raised);
220  }
input
Definition: langcheck.php:166

◆ test_withByline()

InputTest::test_withByline ( )

Definition at line 118 of file InputTest.php.

References ILIAS\UI\Implementation\Component\Input\Field\Input\$byline, $input, and input.

119  {
120  $byline = "new byline";
121  $input = $this->input->withByline($byline);
122  $this->assertEquals($byline, $input->getByline());
123  $this->assertNotSame($this->input, $input);
124  }
input
Definition: langcheck.php:166

◆ test_withError()

InputTest::test_withError ( )

Definition at line 173 of file InputTest.php.

References ILIAS\UI\Implementation\Component\Input\Field\Input\$error, $input, and input.

174  {
175  $error = "error";
176  $input = $this->input->withError($error);
177  $this->assertEquals(null, $this->input->getError());
178  $this->assertEquals($error, $input->getError());
179  $this->assertNotSame($this->input, $input);
180  }
input
Definition: langcheck.php:166

◆ test_withInput()

InputTest::test_withInput ( )

Definition at line 191 of file InputTest.php.

References $input, ILIAS\UI\Implementation\Component\Input\Field\Input\$name, $res, ILIAS\UI\Implementation\Component\Input\Field\Input\$value, $values, and input.

192  {
193  $name = "name_0";
194  $value = "valu";
195  $input = $this->input->withNameFrom($this->name_source);
196  $values = new DefPostData([$name => $value]);
197 
198  $input2 = $input->withInput($values);
199  $res = $input2->getContent();
200 
201  $this->assertInstanceOf(Result::class, $res);
202  $this->assertTrue($res->isOk());
203  $this->assertEquals($value, $res->value());
204 
205  $this->assertNotSame($input, $input2);
206  $this->assertEquals($value, $input2->getValue());
207  }
foreach($_POST as $key=> $value) $res
$values
input
Definition: langcheck.php:166

◆ test_withInput_and_constraint_fails()

InputTest::test_withInput_and_constraint_fails ( )

Definition at line 297 of file InputTest.php.

References ILIAS\UI\Implementation\Component\Input\Field\Input\$error, $input, ILIAS\UI\Implementation\Component\Input\Field\Input\$name, $res, ILIAS\UI\Implementation\Component\Input\Field\Input\$value, $values, and input.

298  {
299  $name = "name_0";
300  $value = "value";
301  $error = "an error";
302  $input = $this->input->withNameFrom($this->name_source);
303  $values = new DefPostData([$name => $value]);
304 
305  $input2 = $input->withAdditionalConstraint($this->validation_factory->custom(function ($_) {
306  return false;
307  }, $error))->withInput($values);
308  $res = $input2->getContent();
309 
310  $this->assertInstanceOf(Result::class, $res);
311  $this->assertTrue($res->isError());
312  $this->assertEquals($error, $res->error());
313 
314  $this->assertNotSame($input, $input2);
315  $this->assertEquals($value, $input2->getValue());
316  $this->assertEquals($error, $input2->getError());
317  }
foreach($_POST as $key=> $value) $res
$values
input
Definition: langcheck.php:166

◆ test_withInput_and_constraint_fails_different_order()

InputTest::test_withInput_and_constraint_fails_different_order ( )

Definition at line 320 of file InputTest.php.

References ILIAS\UI\Implementation\Component\Input\Field\Input\$error, $input, ILIAS\UI\Implementation\Component\Input\Field\Input\$name, $res, ILIAS\UI\Implementation\Component\Input\Field\Input\$value, $values, and input.

321  {
322  $name = "name_0";
323  $value = "value";
324  $error = "an error";
325  $input = $this->input->withNameFrom($this->name_source);
326  $values = new DefPostData([$name => $value]);
327 
328  $input2 = $input->withInput($values)->withAdditionalConstraint($this->validation_factory->custom(function ($_) {
329  return false;
330  }, $error));
331  $res = $input2->getContent();
332 
333  $this->assertInstanceOf(Result::class, $res);
334  $this->assertTrue($res->isError());
335  $this->assertEquals($error, $res->error());
336 
337  $this->assertNotSame($input, $input2);
338  $this->assertEquals($value, $input2->getValue());
339  $this->assertEquals($error, $input2->getError());
340  }
foreach($_POST as $key=> $value) $res
$values
input
Definition: langcheck.php:166

◆ test_withInput_and_constraint_successfull()

InputTest::test_withInput_and_constraint_successfull ( )

Definition at line 274 of file InputTest.php.

References ILIAS\UI\Implementation\Component\Input\Field\Input\$error, $input, ILIAS\UI\Implementation\Component\Input\Field\Input\$name, $res, ILIAS\UI\Implementation\Component\Input\Field\Input\$value, $values, and input.

275  {
276  $name = "name_0";
277  $value = "value";
278  $error = "an error";
279  $input = $this->input->withNameFrom($this->name_source);
280  $values = new DefPostData([$name => $value]);
281 
282  $input2 = $input->withAdditionalConstraint($this->validation_factory->custom(function ($_) {
283  return true;
284  }, $error))->withInput($values);
285  $res = $input2->getContent();
286 
287  $this->assertInstanceOf(Result::class, $res);
288  $this->assertTrue($res->isOk());
289  $this->assertEquals($value, $res->value());
290 
291  $this->assertNotSame($input, $input2);
292  $this->assertEquals($value, $input2->getValue());
293  $this->assertEquals(null, $input2->getError());
294  }
foreach($_POST as $key=> $value) $res
$values
input
Definition: langcheck.php:166

◆ test_withInput_and_transformation()

InputTest::test_withInput_and_transformation ( )

Definition at line 223 of file InputTest.php.

References $input, ILIAS\UI\Implementation\Component\Input\Field\Input\$name, $res, ILIAS\UI\Implementation\Component\Input\Field\Input\$value, $values, and input.

224  {
225  $name = "name_0";
226  $value = "value";
227  $transform_to = "other value";
228  $input = $this->input->withNameFrom($this->name_source);
229  $values = new DefPostData([$name => $value]);
230 
231  $input2 = $input->withAdditionalTransformation($this->transformation_factory->custom(function ($v) use ($value, $transform_to) {
232  $this->assertEquals($value, $v);
233 
234  return $transform_to;
235  }))->withInput($values);
236  $res = $input2->getContent();
237 
238  $this->assertInstanceOf(Result::class, $res);
239  $this->assertTrue($res->isOk());
240  $this->assertEquals($transform_to, $res->value());
241 
242  $this->assertNotSame($input, $input2);
243  $this->assertEquals($value, $input2->getValue());
244  }
foreach($_POST as $key=> $value) $res
$values
input
Definition: langcheck.php:166

◆ test_withInput_and_transformation_different_order()

InputTest::test_withInput_and_transformation_different_order ( )

Definition at line 247 of file InputTest.php.

References $input, ILIAS\UI\Implementation\Component\Input\Field\Input\$name, $res, ILIAS\UI\Implementation\Component\Input\Field\Input\$value, $values, and input.

248  {
249  $name = "name_0";
250  $value = "value";
251  $transform_to = "other value";
252  $input = $this->input->withNameFrom($this->name_source);
253  $values = new DefPostData([$name => $value]);
254 
255  $input2 = $input->withInput($values)->withAdditionalTransformation($this->transformation_factory->custom(function ($v) use (
256  $value,
257  $transform_to
258  ) {
259  $this->assertEquals($value, $v);
260 
261  return $transform_to;
262  }));
263  $res = $input2->getContent();
264 
265  $this->assertInstanceOf(Result::class, $res);
266  $this->assertTrue($res->isOk());
267  $this->assertEquals($transform_to, $res->value());
268 
269  $this->assertNotSame($input, $input2);
270  $this->assertEquals($value, $input2->getValue());
271  }
foreach($_POST as $key=> $value) $res
$values
input
Definition: langcheck.php:166

◆ test_withInput_constraint_and_transformation()

InputTest::test_withInput_constraint_and_transformation ( )

Definition at line 406 of file InputTest.php.

References ILIAS\UI\Implementation\Component\Input\Field\Input\$error, $input, ILIAS\UI\Implementation\Component\Input\Field\Input\$name, $res, ILIAS\UI\Implementation\Component\Input\Field\Input\$value, $values, and input.

407  {
408  $name = "name_0";
409  $value = "value";
410  $transform_to = "other value";
411  $error = "an error";
412  $input = $this->input->withNameFrom($this->name_source);
413  $values = new DefPostData([$name => $value]);
414 
415  $input2 = $input->withAdditionalConstraint($this->validation_factory->custom(function ($v) use ($value) {
416  $this->assertEquals($value, $v);
417 
418  return true;
419  }, $error))->withAdditionalTransformation($this->transformation_factory->custom(function ($v) use ($value, $transform_to) {
420  $this->assertEquals($value, $v);
421 
422  return $transform_to;
423  }))->withInput($values);
424  $res = $input2->getContent();
425 
426  $this->assertInstanceOf(Result::class, $res);
427  $this->assertTrue($res->isOk());
428  $this->assertEquals($transform_to, $res->value());
429 
430  $this->assertNotSame($input, $input2);
431  $this->assertEquals($value, $input2->getValue());
432  $this->assertEquals(null, $input2->getError());
433  }
foreach($_POST as $key=> $value) $res
$values
input
Definition: langcheck.php:166

◆ test_withInput_constraint_fails_and_transformation()

InputTest::test_withInput_constraint_fails_and_transformation ( )

Definition at line 436 of file InputTest.php.

References ILIAS\UI\Implementation\Component\Input\Field\Input\$error, $input, ILIAS\UI\Implementation\Component\Input\Field\Input\$name, $res, ILIAS\UI\Implementation\Component\Input\Field\Input\$value, $values, and input.

437  {
438  $name = "name_0";
439  $value = "value";
440  $transform_to = "other value";
441  $error = "an error";
442  $input = $this->input->withNameFrom($this->name_source);
443  $values = new DefPostData([$name => $value]);
444 
445  $input2 = $input->withAdditionalConstraint($this->validation_factory->custom(function ($v) use ($value) {
446  $this->assertEquals($value, $v);
447 
448  return false;
449  }, $error))->withAdditionalTransformation($this->transformation_factory->custom(function ($v) use ($value, $transform_to) {
450  $this->assertFalse("This should not happen");
451 
452  return $transform_to;
453  }))->withInput($values);
454  $res = $input2->getContent();
455 
456  $this->assertInstanceOf(Result::class, $res);
457  $this->assertTrue($res->isError());
458  $this->assertEquals($error, $res->error());
459 
460  $this->assertNotSame($input, $input2);
461  $this->assertEquals($value, $input2->getValue());
462  $this->assertEquals($error, $input2->getError());
463  }
foreach($_POST as $key=> $value) $res
$values
input
Definition: langcheck.php:166

◆ test_withInput_constraint_fails_and_transformation_different_order()

InputTest::test_withInput_constraint_fails_and_transformation_different_order ( )

Definition at line 466 of file InputTest.php.

References ILIAS\UI\Implementation\Component\Input\Field\Input\$error, $input, ILIAS\UI\Implementation\Component\Input\Field\Input\$name, $res, ILIAS\UI\Implementation\Component\Input\Field\Input\$value, $values, and input.

467  {
468  $name = "name_0";
469  $value = "value";
470  $transform_to = "other value";
471  $error = "an error";
472  $input = $this->input->withNameFrom($this->name_source);
473  $values = new DefPostData([$name => $value]);
474 
475  $input2 = $input->withInput($values)->withAdditionalConstraint($this->validation_factory->custom(function ($v) use ($value) {
476  $this->assertEquals($value, $v);
477 
478  return false;
479  }, $error))->withAdditionalTransformation($this->transformation_factory->custom(function ($v) use ($value, $transform_to) {
480  $this->assertFalse("This should not happen");
481 
482  return $transform_to;
483  }));
484  $res = $input2->getContent();
485 
486  $this->assertInstanceOf(Result::class, $res);
487  $this->assertTrue($res->isError());
488  $this->assertEquals($error, $res->error());
489 
490  $this->assertNotSame($input, $input2);
491  $this->assertEquals($value, $input2->getValue());
492  $this->assertEquals($error, $input2->getError());
493  }
foreach($_POST as $key=> $value) $res
$values
input
Definition: langcheck.php:166

◆ test_withInput_requirement_constraint()

InputTest::test_withInput_requirement_constraint ( )

Definition at line 496 of file InputTest.php.

References ILIAS\UI\Implementation\Component\Input\Field\Input\$error, $input, ILIAS\UI\Implementation\Component\Input\Field\Input\$name, $res, ILIAS\UI\Implementation\Component\Input\Field\Input\$value, $values, and input.

497  {
498  $name = "name_0";
499  $value = "value";
500  $error = "an error";
501  $input = $this->input->withNameFrom($this->name_source);
502  $values = new DefPostData([$name => $value]);
503 
504  $input->requirement_constraint = $this->validation_factory->custom(function ($_) {
505  return false;
506  }, $error);
507 
508  $input2 = $input->withRequired(true)->withInput($values);
509  $res = $input2->getContent();
510 
511  $this->assertInstanceOf(Result::class, $res);
512  $this->assertTrue($res->isError());
513  $this->assertEquals($error, $res->error());
514 
515  $this->assertNotSame($input, $input2);
516  $this->assertEquals($value, $input2->getValue());
517  $this->assertEquals($error, $input2->getError());
518  }
foreach($_POST as $key=> $value) $res
$values
input
Definition: langcheck.php:166

◆ test_withInput_toggle_requirement()

InputTest::test_withInput_toggle_requirement ( )

Definition at line 521 of file InputTest.php.

References ILIAS\UI\Implementation\Component\Input\Field\Input\$error, $input, ILIAS\UI\Implementation\Component\Input\Field\Input\$name, $res, ILIAS\UI\Implementation\Component\Input\Field\Input\$value, $values, and input.

522  {
523  $name = "name_0";
524  $value = "value";
525  $error = "an error";
526  $input = $this->input->withNameFrom($this->name_source);
527  $values = new DefPostData([$name => $value]);
528 
529  $input->requirement_constraint = $this->validation_factory->custom(function ($_) {
530  return false;
531  }, $error);
532 
533  $input2 = $input->withRequired(true)->withRequired(false)->withInput($values);
534  $res = $input2->getContent();
535 
536  $this->assertInstanceOf(Result::class, $res);
537  $this->assertFalse($res->isError());
538  $this->assertEquals($value, $res->value());
539  }
foreach($_POST as $key=> $value) $res
$values
input
Definition: langcheck.php:166

◆ test_withInput_transformation_and_constraint()

InputTest::test_withInput_transformation_and_constraint ( )

Definition at line 343 of file InputTest.php.

References ILIAS\UI\Implementation\Component\Input\Field\Input\$error, $input, ILIAS\UI\Implementation\Component\Input\Field\Input\$name, $res, ILIAS\UI\Implementation\Component\Input\Field\Input\$value, $values, and input.

344  {
345  $name = "name_0";
346  $value = "value";
347  $transform_to = "other value";
348  $error = "an error";
349  $input = $this->input->withNameFrom($this->name_source);
350  $values = new DefPostData([$name => $value]);
351 
352  $input2 = $input->withAdditionalTransformation($this->transformation_factory->custom(function ($v) use ($value, $transform_to) {
353  $this->assertEquals($value, $v);
354 
355  return $transform_to;
356  }))->withAdditionalConstraint($this->validation_factory->custom(function ($v) use ($transform_to) {
357  $this->assertEquals($transform_to, $v);
358 
359  return true;
360  }, $error))->withInput($values);
361  $res = $input2->getContent();
362 
363  $this->assertInstanceOf(Result::class, $res);
364  $this->assertTrue($res->isOk());
365  $this->assertEquals($transform_to, $res->value());
366 
367  $this->assertNotSame($input, $input2);
368  $this->assertEquals($value, $input2->getValue());
369  $this->assertEquals(null, $input2->getError());
370  }
foreach($_POST as $key=> $value) $res
$values
input
Definition: langcheck.php:166

◆ test_withInput_transformation_and_constraint_different_order()

InputTest::test_withInput_transformation_and_constraint_different_order ( )

Definition at line 373 of file InputTest.php.

References ILIAS\UI\Implementation\Component\Input\Field\Input\$error, $input, ILIAS\UI\Implementation\Component\Input\Field\Input\$name, $res, ILIAS\UI\Implementation\Component\Input\Field\Input\$value, $values, and input.

374  {
375  $name = "name_0";
376  $value = "value";
377  $transform_to = "other value";
378  $error = "an error";
379  $input = $this->input->withNameFrom($this->name_source);
380  $values = new DefPostData([$name => $value]);
381 
382  $input2 = $input->withInput($values)->withAdditionalTransformation($this->transformation_factory->custom(function ($v) use (
383  $value,
384  $transform_to
385  ) {
386  $this->assertEquals($value, $v);
387 
388  return $transform_to;
389  }))->withAdditionalConstraint($this->validation_factory->custom(function ($v) use ($transform_to) {
390  $this->assertEquals($transform_to, $v);
391 
392  return true;
393  }, $error));
394  $res = $input2->getContent();
395 
396  $this->assertInstanceOf(Result::class, $res);
397  $this->assertTrue($res->isOk());
398  $this->assertEquals($transform_to, $res->value());
399 
400  $this->assertNotSame($input, $input2);
401  $this->assertEquals($value, $input2->getValue());
402  $this->assertEquals(null, $input2->getError());
403  }
foreach($_POST as $key=> $value) $res
$values
input
Definition: langcheck.php:166

◆ test_withLabel()

InputTest::test_withLabel ( )

Definition at line 109 of file InputTest.php.

References $input, ILIAS\UI\Implementation\Component\Input\Field\Input\$label, and input.

110  {
111  $label = "new label";
112  $input = $this->input->withLabel($label);
113  $this->assertEquals($label, $input->getLabel());
114  $this->assertNotSame($this->input, $input);
115  }
input
Definition: langcheck.php:166

◆ test_withName()

InputTest::test_withName ( )

Definition at line 162 of file InputTest.php.

References $input, ILIAS\UI\Implementation\Component\Input\Field\Input\$name, and input.

163  {
164  $name = "name_0";
165  $input = $this->input->withNameFrom($this->name_source);
166  $this->assertEquals(null, $this->input->getName());
167  $this->assertEquals($name, $input->getName());
168  $this->assertNotSame($this->input, $input);
169  $this->assertEquals(1, $this->name_source->count);
170  }
input
Definition: langcheck.php:166

◆ test_withRequired()

InputTest::test_withRequired ( )

Definition at line 127 of file InputTest.php.

References $input, and input.

128  {
129  $this->assertFalse($this->input->isRequired());
130  $input = $this->input->withRequired(true);
131  $this->assertTrue($input->isRequired());
132  $input = $input->withRequired(false);
133  $this->assertFalse($input->isRequired());
134  }
input
Definition: langcheck.php:166

◆ test_withValue()

InputTest::test_withValue ( )

Definition at line 137 of file InputTest.php.

References $input, ILIAS\UI\Implementation\Component\Input\Field\Input\$value, and input.

138  {
139  $value = "some value";
140  $input = $this->input->withValue($value);
141  $this->assertEquals(null, $this->input->getValue());
142  $this->assertEquals($value, $input->getValue());
143  $this->assertNotSame($this->input, $input);
144  }
input
Definition: langcheck.php:166

◆ test_withValue_throws()

InputTest::test_withValue_throws ( )

Definition at line 147 of file InputTest.php.

References input.

148  {
149  $this->input->value_ok = false;
150  $raised = false;
151  try {
152  $this->input->withValue("foo");
153  $this->assertFalse("This should not happen.");
154  } catch (\InvalidArgumentException $e) {
155  $raised = true;
156  }
157  $this->assertTrue($raised);
158  $this->assertEquals(null, $this->input->getValue());
159  }
input
Definition: langcheck.php:166

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