ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ParallelConstraintsTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2017 Stefan Hecken <stefan.hecken@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4require_once("libs/composer/vendor/autoload.php");
5
7use ILIAS\Data;
8
15{
16 protected function setUp()
17 {
18 $this->df = new Data\Factory();
19 $this->lng = $this->createMock(\ilLanguage::class);
20 $this->f = new Validation\Factory($this->df, $this->lng);
21
22 $this->less_than_3 = $this->f->custom(
23 function ($value) {
24 return $value < 3;
25 },
26 "not_less_than_3"
27 );
28
29 $this->less_than_5 = $this->f->custom(
30 function ($value) {
31 return $value < 5;
32 },
33 "not_less_than_5"
34 );
35
36 $this->c = $this->f->parallel([$this->less_than_3, $this->less_than_5]);
37 }
38
39 public function testAccepts()
40 {
41 $this->assertTrue($this->c->accepts(2));
42 }
43
44 public function testNotAccepts()
45 {
46 $this->assertFalse($this->c->accepts(4));
47 }
48
49 public function testCheckSucceed()
50 {
51 $this->c->check(2);
52 $this->assertTrue(true); // does not throw
53 }
54
55 public function testCheckFails()
56 {
57 $this->expectException(\UnexpectedValueException::class);
58 $this->c->check(6);
59 }
60
61 public function testNoProblemWith()
62 {
63 $this->assertNull($this->c->problemWith(2));
64 }
65
66 public function testProblemWith1()
67 {
68 $this->lng
69 ->expects($this->never())
70 ->method("txt");
71
72 $this->assertEquals("not_less_than_3", $this->c->problemWith(4));
73 }
74
75 public function testProblemWith2()
76 {
77 $this->lng
78 ->expects($this->never())
79 ->method("txt");
80
81 $this->assertEquals("not_less_than_3 not_less_than_5", $this->c->problemWith(6));
82 }
83
84 public function testRestrictOk()
85 {
86 $ok = $this->df->ok(2);
87
88 $res = $this->c->restrict($ok);
89 $this->assertTrue($res->isOk());
90 }
91
92 public function testRestrictNotOk()
93 {
94 $not_ok = $this->df->ok(7);
95
96 $res = $this->c->restrict($not_ok);
97 $this->assertFalse($res->isOk());
98 }
99
100 public function testRestrictError()
101 {
102 $error = $this->df->error("error");
103
104 $res = $this->c->restrict($error);
105 $this->assertSame($error, $res);
106 }
107
108 public function testWithProblemBuilder()
109 {
110 $new_c = $this->c->withProblemBuilder(function () {
111 return "This was a fault";
112 });
113 $this->assertEquals("This was a fault", $new_c->problemWith(7));
114 }
115}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:15
TestCase for the parellel constraint.
foreach($_POST as $key=> $value) $res