4 require_once(
"libs/composer/vendor/autoload.php");
13 $this->df =
new Data\Factory();
14 $this->lng = $this->createMock(\ilLanguage::class);
15 $this->f =
new Validation\Factory($this->df, $this->lng);
17 $this->on_element = $this->createMock(Validation\Constraint::class);
19 $this->c = $this->f->isArrayOf($this->on_element);
25 ->expects($this->exactly(2))
27 ->withConsecutive([1], [2])
28 ->will($this->onConsecutiveCalls(
true,
true));
30 $this->assertTrue($this->c->accepts([1, 2]));
36 ->expects($this->exactly(2))
38 ->withConsecutive([1], [2])
39 ->will($this->onConsecutiveCalls(
true,
false));
41 $this->assertFalse($this->c->accepts([1, 2, 3]));
46 $this->assertFalse($this->c->accepts(1));
52 ->expects($this->exactly(2))
54 ->withConsecutive([1], [2])
55 ->will($this->onConsecutiveCalls(
true,
true));
57 $this->c->check([1, 2]);
58 $this->assertTrue(
true);
64 ->expects($this->exactly(2))
66 ->withConsecutive([1], [2])
67 ->will($this->onConsecutiveCalls(
true,
false));
69 $this->expectException(\UnexpectedValueException::class);
70 $this->c->check([1, 2]);
76 $this->expectException(\UnexpectedValueException::class);
83 ->expects($this->exactly(2))
85 ->withConsecutive([1], [2])
86 ->will($this->onConsecutiveCalls(
true,
true));
88 $this->assertNull($this->c->problemWith([1, 2]));
94 ->expects($this->exactly(3))
95 ->method(
"problemWith")
96 ->withConsecutive([1], [2], [3])
97 ->will($this->onConsecutiveCalls(null,
"2",
"3"));
100 ->expects($this->exactly(1))
102 ->withConsecutive([
"not_an_array_of"])
103 ->willReturn(
"-%s-");
105 $this->assertEquals(
"-2 3-", $this->c->problemWith([1,2,3]));
111 ->expects($this->exactly(1))
113 ->withConsecutive([
"not_an_array"])
114 ->willReturn(
"-%s-");
116 $this->assertEquals(
"-integer-", $this->c->problemWith(1));
122 ->expects($this->exactly(2))
124 ->withConsecutive([1], [2])
125 ->will($this->onConsecutiveCalls(
true,
true));
127 $ok = $this->df->ok([1, 2]);
129 $res = $this->c->restrict(
$ok);
130 $this->assertTrue(
$res->isOk());
136 ->expects($this->exactly(2))
138 ->withConsecutive([1], [2])
139 ->will($this->onConsecutiveCalls(
true,
false));
141 $not_ok = $this->df->ok([1,2]);
143 $res = $this->c->restrict($not_ok);
144 $this->assertFalse(
$res->isOk());
149 $not_ok = $this->df->ok(1);
151 $res = $this->c->restrict($not_ok);
152 $this->assertFalse(
$res->isOk());
157 $error = $this->df->error(
"error");
159 $res = $this->c->restrict($error);
160 $this->assertSame($error,
$res);
165 $new_c = $this->c->withProblemBuilder(
function () {
166 return "This was a fault";
168 $this->assertEquals(
"This was a fault", $new_c->problemWith(2));
testCheckFailsOnNoneArray()
testProblemWithNoneArray()
testNotAcceptsNoneArrays()
foreach($_POST as $key=> $value) $res
testRestrictNotOkForNoneArray()