ILIAS  release_7 Revision v7.30-3-g800a261c036
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_withDisabled ()
 
 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 ()
 
 getRefinery ()
 
 getImagePathResolver ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
 
 getDecoratedRenderer (Renderer $default)
 
 normalizeHTML ($html)
 
 assertHTMLEquals ($expected_html_as_string, $html_as_string)
 

Private Attributes

 $refinery
 

Additional Inherited Members

- Protected Member Functions inherited from ILIAS_UI_TestBase
 brutallyTrimHTML ($html)
 A more radical version of normalizeHTML. More...
 

Detailed Description

Test on input implementation.

Definition at line 95 of file InputTest.php.

Member Function Documentation

◆ setUp()

InputTest::setUp ( )

Reimplemented from ILIAS_UI_TestBase.

Definition at line 103 of file InputTest.php.

103 : void
104 {
105 $this->data_factory = new DataFactory();
106 $language = $this->createMock(\ilLanguage::class);
107 $this->refinery = new \ILIAS\Refinery\Factory($this->data_factory, $language);
108 $this->input = new DefInput(
109 $this->data_factory,
110 $this->refinery,
111 "label",
112 "byline"
113 );
114 $this->name_source = new DefNamesource();
115 }

◆ test_constructor()

InputTest::test_constructor ( )

Definition at line 118 of file InputTest.php.

119 {
120 $this->assertEquals("label", $this->input->getLabel());
121 $this->assertEquals("byline", $this->input->getByline());
122 }

◆ test_getContent()

InputTest::test_getContent ( )

Definition at line 209 of file InputTest.php.

210 {
211 $this->expectException(\LogicException::class);
212
213 $this->input->getContent();
214 }

◆ test_only_run_withInput_with_name()

InputTest::test_only_run_withInput_with_name ( )

Definition at line 236 of file InputTest.php.

237 {
238 $raised = false;
239 try {
240 $this->input->withInput(new DefInputData([]));
241 $this->assertFalse("This should not happen.");
242 } catch (\LogicException $e) {
243 $raised = true;
244 }
245 $this->assertTrue($raised);
246 }

References Vendor\Package\$e.

◆ test_withByline()

InputTest::test_withByline ( )

Definition at line 134 of file InputTest.php.

135 {
136 $byline = "new byline";
137 $input = $this->input->withByline($byline);
138 $this->assertEquals($byline, $input->getByline());
139 $this->assertNotSame($this->input, $input);
140 }

◆ test_withDisabled()

InputTest::test_withDisabled ( )

Definition at line 153 of file InputTest.php.

154 {
155 $this->assertFalse($this->input->isDisabled());
156 $input = $this->input->withDisabled(true);
157 $this->assertTrue($input->isDisabled());
158 $input = $input->withDisabled(false);
159 $this->assertFalse($input->isDisabled());
160 }

◆ test_withError()

InputTest::test_withError ( )

Definition at line 199 of file InputTest.php.

200 {
201 $error = "error";
202 $input = $this->input->withError($error);
203 $this->assertEquals(null, $this->input->getError());
204 $this->assertEquals($error, $input->getError());
205 $this->assertNotSame($this->input, $input);
206 }

◆ test_withInput()

InputTest::test_withInput ( )

Definition at line 217 of file InputTest.php.

218 {
219 $name = "name_0";
220 $value = "valu";
221 $input = $this->input->withNameFrom($this->name_source);
222 $values = new DefInputData([$name => $value]);
223
224 $input2 = $input->withInput($values);
225 $res = $input2->getContent();
226
227 $this->assertInstanceOf(Result::class, $res);
228 $this->assertTrue($res->isOk());
229 $this->assertEquals($value, $res->value());
230
231 $this->assertNotSame($input, $input2);
232 $this->assertEquals($value, $input2->getValue());
233 }
if($format !==null) $name
Definition: metadata.php:230
foreach($_POST as $key=> $value) $res

References $name, and $res.

◆ test_withInput_and_constraint_fails()

InputTest::test_withInput_and_constraint_fails ( )

Definition at line 323 of file InputTest.php.

324 {
325 $name = "name_0";
326 $value = "value";
327 $error = "an error";
328 $input = $this->input->withNameFrom($this->name_source);
329 $values = new DefInputData([$name => $value]);
330
331 $input2 = $input->withAdditionalTransformation($this->refinery->custom()->constraint(function ($_) {
332 return false;
333 }, $error))->withInput($values);
334 $res = $input2->getContent();
335
336 $this->assertInstanceOf(Result::class, $res);
337 $this->assertTrue($res->isError());
338 $this->assertEquals($error, $res->error());
339
340 $this->assertNotSame($input, $input2);
341 $this->assertEquals($value, $input2->getValue());
342 $this->assertEquals($error, $input2->getError());
343 }

References $name, and $res.

◆ test_withInput_and_constraint_fails_different_order()

InputTest::test_withInput_and_constraint_fails_different_order ( )

Definition at line 346 of file InputTest.php.

347 {
348 $rc = $this->refinery->custom();
349
350 $name = "name_0";
351 $value = "value";
352 $error = "an error";
353 $input = $this->input->withNameFrom($this->name_source);
354 $values = new DefInputData([$name => $value]);
355
356 $input2 = $input
357 ->withInput($values)
358 ->withAdditionalTransformation($rc->constraint(function ($_) {
359 return false;
360 }, $error));
361
362 $res = $input2->getContent();
363
364 $this->assertInstanceOf(Result::class, $res);
365 $this->assertTrue($res->isError());
366 $this->assertEquals($error, $res->error());
367
368 $this->assertNotSame($input, $input2);
369 $this->assertEquals($value, $input2->getValue());
370 $this->assertEquals($error, $input2->getError());
371 }

References $name, and $res.

◆ test_withInput_and_constraint_successfull()

InputTest::test_withInput_and_constraint_successfull ( )

Definition at line 300 of file InputTest.php.

301 {
302 $name = "name_0";
303 $value = "value";
304 $error = "an error";
305 $input = $this->input->withNameFrom($this->name_source);
306 $values = new DefInputData([$name => $value]);
307
308 $input2 = $input->withAdditionalTransformation($this->refinery->custom()->constraint(function ($_) {
309 return true;
310 }, $error))->withInput($values);
311 $res = $input2->getContent();
312
313 $this->assertInstanceOf(Result::class, $res);
314 $this->assertTrue($res->isOk());
315 $this->assertEquals($value, $res->value());
316
317 $this->assertNotSame($input, $input2);
318 $this->assertEquals($value, $input2->getValue());
319 $this->assertEquals(null, $input2->getError());
320 }

References $name, and $res.

◆ test_withInput_and_transformation()

InputTest::test_withInput_and_transformation ( )

Definition at line 249 of file InputTest.php.

250 {
251 $name = "name_0";
252 $value = "value";
253 $transform_to = "other value";
254 $input = $this->input->withNameFrom($this->name_source);
255 $values = new DefInputData([$name => $value]);
256
257 $input2 = $input->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) use ($value, $transform_to) {
258 $this->assertEquals($value, $v);
259
260 return $transform_to;
261 }))->withInput($values);
262 $res = $input2->getContent();
263
264 $this->assertInstanceOf(Result::class, $res);
265 $this->assertTrue($res->isOk());
266 $this->assertEquals($transform_to, $res->value());
267
268 $this->assertNotSame($input, $input2);
269 $this->assertEquals($value, $input2->getValue());
270 }

References $name, and $res.

◆ test_withInput_and_transformation_different_order()

InputTest::test_withInput_and_transformation_different_order ( )

Definition at line 273 of file InputTest.php.

274 {
275 $name = "name_0";
276 $value = "value";
277 $transform_to = "other value";
278 $input = $this->input->withNameFrom($this->name_source);
279 $values = new DefInputData([$name => $value]);
280
281 $input2 = $input->withInput($values)->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) use (
282 $value,
283 $transform_to
284 ) {
285 $this->assertEquals($value, $v);
286
287 return $transform_to;
288 }));
289 $res = $input2->getContent();
290
291 $this->assertInstanceOf(Result::class, $res);
292 $this->assertTrue($res->isOk());
293 $this->assertEquals($transform_to, $res->value());
294
295 $this->assertNotSame($input, $input2);
296 $this->assertEquals($value, $input2->getValue());
297 }

References $name, and $res.

◆ test_withInput_constraint_and_transformation()

InputTest::test_withInput_constraint_and_transformation ( )

Definition at line 437 of file InputTest.php.

438 {
439 $name = "name_0";
440 $value = "value";
441 $transform_to = "other value";
442 $error = "an error";
443 $input = $this->input->withNameFrom($this->name_source);
444 $values = new DefInputData([$name => $value]);
445
446 $input2 = $input->withAdditionalTransformation($this->refinery->custom()->constraint(function ($v) use ($value) {
447 $this->assertEquals($value, $v);
448
449 return true;
450 }, $error))->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) use ($value, $transform_to) {
451 $this->assertEquals($value, $v);
452
453 return $transform_to;
454 }))->withInput($values);
455 $res = $input2->getContent();
456
457 $this->assertInstanceOf(Result::class, $res);
458 $this->assertTrue($res->isOk());
459 $this->assertEquals($transform_to, $res->value());
460
461 $this->assertNotSame($input, $input2);
462 $this->assertEquals($value, $input2->getValue());
463 $this->assertEquals(null, $input2->getError());
464 }

References $name, and $res.

◆ test_withInput_constraint_fails_and_transformation()

InputTest::test_withInput_constraint_fails_and_transformation ( )

Definition at line 467 of file InputTest.php.

468 {
469 $rc = $this->refinery->custom();
470
471 $name = "name_0";
472 $value = "value";
473 $transform_to = "other value";
474 $error = "an error";
475 $input = $this->input->withNameFrom($this->name_source);
476 $values = new DefInputData([$name => $value]);
477
478 $input2 = $input
479 ->withAdditionalTransformation($rc->constraint(function ($v) use ($value) {
480 $this->assertEquals($value, $v);
481
482 return false;
483 }, $error))
484 ->withAdditionalTransformation($rc->transformation(function ($v) use ($value, $transform_to) {
485 $this->assertFalse("This should not happen");
486
487 return $transform_to;
488 }))->withInput($values);
489 $res = $input2->getContent();
490
491 $this->assertInstanceOf(Result::class, $res);
492 $this->assertTrue($res->isError());
493 $this->assertEquals($error, $res->error());
494
495 $this->assertNotSame($input, $input2);
496 $this->assertEquals($value, $input2->getValue());
497 $this->assertEquals($error, $input2->getError());
498 }

References $name, and $res.

◆ test_withInput_constraint_fails_and_transformation_different_order()

InputTest::test_withInput_constraint_fails_and_transformation_different_order ( )

Definition at line 501 of file InputTest.php.

502 {
503 $name = "name_0";
504 $value = "value";
505 $transform_to = "other value";
506 $error = "an error";
507 $input = $this->input->withNameFrom($this->name_source);
508 $values = new DefInputData([$name => $value]);
509
510 $input2 = $input->withInput($values)->withAdditionalTransformation($this->refinery->custom()->constraint(function ($v) use ($value) {
511 $this->assertEquals($value, $v);
512
513 return false;
514 }, $error))->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) use ($value, $transform_to) {
515 $this->assertFalse("This should not happen");
516
517 return $transform_to;
518 }));
519 $res = $input2->getContent();
520
521 $this->assertInstanceOf(Result::class, $res);
522 $this->assertTrue($res->isError());
523 $this->assertEquals($error, $res->error());
524
525 $this->assertNotSame($input, $input2);
526 $this->assertEquals($value, $input2->getValue());
527 $this->assertEquals($error, $input2->getError());
528 }

References $name, and $res.

◆ test_withInput_requirement_constraint()

InputTest::test_withInput_requirement_constraint ( )

Definition at line 531 of file InputTest.php.

532 {
533 $name = "name_0";
534 $value = "value";
535 $error = "an error";
536 $input = $this->input->withNameFrom($this->name_source);
537 $values = new DefInputData([$name => $value]);
538
539 $input->requirement_constraint = $this->refinery->custom()->constraint(function ($_) {
540 return false;
541 }, $error);
542
543 $input2 = $input->withRequired(true)->withInput($values);
544 $res = $input2->getContent();
545
546 $this->assertInstanceOf(Result::class, $res);
547 $this->assertTrue($res->isError());
548 $this->assertEquals($error, $res->error());
549
550 $this->assertNotSame($input, $input2);
551 $this->assertEquals($value, $input2->getValue());
552 $this->assertEquals($error, $input2->getError());
553 }

References $name, and $res.

◆ test_withInput_toggle_requirement()

InputTest::test_withInput_toggle_requirement ( )

Definition at line 556 of file InputTest.php.

557 {
558 $name = "name_0";
559 $value = "value";
560 $error = "an error";
561 $input = $this->input->withNameFrom($this->name_source);
562 $values = new DefInputData([$name => $value]);
563
564 $input->requirement_constraint = $this->refinery->custom()->constraint(function ($_) {
565 return false;
566 }, $error);
567
568 $input2 = $input->withRequired(true)->withRequired(false)->withInput($values);
569 $res = $input2->getContent();
570
571 $this->assertInstanceOf(Result::class, $res);
572 $this->assertFalse($res->isError());
573 $this->assertEquals($value, $res->value());
574 }

References $name, and $res.

◆ test_withInput_transformation_and_constraint()

InputTest::test_withInput_transformation_and_constraint ( )

Definition at line 374 of file InputTest.php.

375 {
376 $name = "name_0";
377 $value = "value";
378 $transform_to = "other value";
379 $error = "an error";
380 $input = $this->input->withNameFrom($this->name_source);
381 $values = new DefInputData([$name => $value]);
382
383 $input2 = $input->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) use ($value, $transform_to) {
384 $this->assertEquals($value, $v);
385
386 return $transform_to;
387 }))->withAdditionalTransformation($this->refinery->custom()->constraint(function ($v) use ($transform_to) {
388 $this->assertEquals($transform_to, $v);
389
390 return true;
391 }, $error))->withInput($values);
392 $res = $input2->getContent();
393
394 $this->assertInstanceOf(Result::class, $res);
395 $this->assertTrue($res->isOk());
396 $this->assertEquals($transform_to, $res->value());
397
398 $this->assertNotSame($input, $input2);
399 $this->assertEquals($value, $input2->getValue());
400 $this->assertEquals(null, $input2->getError());
401 }

References $name, and $res.

◆ test_withInput_transformation_and_constraint_different_order()

InputTest::test_withInput_transformation_and_constraint_different_order ( )

Definition at line 404 of file InputTest.php.

405 {
406 $name = "name_0";
407 $value = "value";
408 $transform_to = "other value";
409 $error = "an error";
410 $input = $this->input->withNameFrom($this->name_source);
411 $values = new DefInputData([$name => $value]);
412
413 $input2 = $input->withInput($values)->withAdditionalTransformation($this->refinery->custom()->transformation(function ($v) use (
414 $value,
415 $transform_to
416 ) {
417 $this->assertEquals($value, $v);
418
419 return $transform_to;
420 }))->withAdditionalTransformation($this->refinery->custom()->constraint(function ($v) use ($transform_to) {
421 $this->assertEquals($transform_to, $v);
422
423 return true;
424 }, $error));
425 $res = $input2->getContent();
426
427 $this->assertInstanceOf(Result::class, $res);
428 $this->assertTrue($res->isOk());
429 $this->assertEquals($transform_to, $res->value());
430
431 $this->assertNotSame($input, $input2);
432 $this->assertEquals($value, $input2->getValue());
433 $this->assertEquals(null, $input2->getError());
434 }

References $name, and $res.

◆ test_withLabel()

InputTest::test_withLabel ( )

Definition at line 125 of file InputTest.php.

126 {
127 $label = "new label";
128 $input = $this->input->withLabel($label);
129 $this->assertEquals($label, $input->getLabel());
130 $this->assertNotSame($this->input, $input);
131 }

◆ test_withName()

InputTest::test_withName ( )

Definition at line 188 of file InputTest.php.

189 {
190 $name = "name_0";
191 $input = $this->input->withNameFrom($this->name_source);
192 $this->assertEquals(null, $this->input->getName());
193 $this->assertEquals($name, $input->getName());
194 $this->assertNotSame($this->input, $input);
195 $this->assertEquals(1, $this->name_source->count);
196 }

References $name.

◆ test_withRequired()

InputTest::test_withRequired ( )

Definition at line 143 of file InputTest.php.

144 {
145 $this->assertFalse($this->input->isRequired());
146 $input = $this->input->withRequired(true);
147 $this->assertTrue($input->isRequired());
148 $input = $input->withRequired(false);
149 $this->assertFalse($input->isRequired());
150 }

◆ test_withValue()

InputTest::test_withValue ( )

Definition at line 163 of file InputTest.php.

164 {
165 $value = "some value";
166 $input = $this->input->withValue($value);
167 $this->assertEquals(null, $this->input->getValue());
168 $this->assertEquals($value, $input->getValue());
169 $this->assertNotSame($this->input, $input);
170 }

◆ test_withValue_throws()

InputTest::test_withValue_throws ( )

Definition at line 173 of file InputTest.php.

174 {
175 $this->input->value_ok = false;
176 $raised = false;
177 try {
178 $this->input->withValue("foo");
179 $this->assertFalse("This should not happen.");
180 } catch (\InvalidArgumentException $e) {
181 $raised = true;
182 }
183 $this->assertTrue($raised);
184 $this->assertEquals(null, $this->input->getValue());
185 }

References Vendor\Package\$e.

Field Documentation

◆ $refinery

InputTest::$refinery
private

Definition at line 101 of file InputTest.php.


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