ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
IsArrayOfConstraintTest Class Reference
+ Inheritance diagram for IsArrayOfConstraintTest:
+ Collaboration diagram for IsArrayOfConstraintTest:

Public Member Functions

 setUp ()
 
 testAccepts ()
 
 testNotAccepts ()
 
 testNotAcceptsNoneArrays ()
 
 testCheckSucceed ()
 
 testCheckFails ()
 
 testCheckFailsOnNoneArray ()
 
 testNoProblemWith ()
 
 testProblemWith ()
 
 testProblemWithNoneArray ()
 
 testRestrictOk ()
 
 testRestrictNotOk ()
 
 testRestrictNotOkForNoneArray ()
 
 testRestrictError ()
 
 testWithProblemBuilder ()
 

Detailed Description

Definition at line 9 of file IsArrayOfConstraintTest.php.

Member Function Documentation

◆ setUp()

IsArrayOfConstraintTest::setUp ( )

Definition at line 11 of file IsArrayOfConstraintTest.php.

12  {
13  $this->df = new Data\Factory();
14  $this->lng = $this->createMock(\ilLanguage::class);
15  $this->f = new Validation\Factory($this->df, $this->lng);
16 
17  $this->on_element = $this->createMock(Validation\Constraint::class);
18 
19  $this->c = $this->f->isArrayOf($this->on_element);
20  }

◆ testAccepts()

IsArrayOfConstraintTest::testAccepts ( )

Definition at line 22 of file IsArrayOfConstraintTest.php.

23  {
24  $this->on_element
25  ->expects($this->exactly(2))
26  ->method("accepts")
27  ->withConsecutive([1], [2])
28  ->will($this->onConsecutiveCalls(true, true));
29 
30  $this->assertTrue($this->c->accepts([1, 2]));
31  }

◆ testCheckFails()

IsArrayOfConstraintTest::testCheckFails ( )

Definition at line 61 of file IsArrayOfConstraintTest.php.

62  {
63  $this->on_element
64  ->expects($this->exactly(2))
65  ->method("accepts")
66  ->withConsecutive([1], [2])
67  ->will($this->onConsecutiveCalls(true, false));
68 
69  $this->expectException(\UnexpectedValueException::class);
70  $this->c->check([1, 2]);
71  }

◆ testCheckFailsOnNoneArray()

IsArrayOfConstraintTest::testCheckFailsOnNoneArray ( )

Definition at line 74 of file IsArrayOfConstraintTest.php.

75  {
76  $this->expectException(\UnexpectedValueException::class);
77  $this->c->check(1);
78  }

◆ testCheckSucceed()

IsArrayOfConstraintTest::testCheckSucceed ( )

Definition at line 49 of file IsArrayOfConstraintTest.php.

50  {
51  $this->on_element
52  ->expects($this->exactly(2))
53  ->method("accepts")
54  ->withConsecutive([1], [2])
55  ->will($this->onConsecutiveCalls(true, true));
56 
57  $this->c->check([1, 2]);
58  $this->assertTrue(true); // does not throw
59  }

◆ testNoProblemWith()

IsArrayOfConstraintTest::testNoProblemWith ( )

Definition at line 80 of file IsArrayOfConstraintTest.php.

81  {
82  $this->on_element
83  ->expects($this->exactly(2))
84  ->method("accepts")
85  ->withConsecutive([1], [2])
86  ->will($this->onConsecutiveCalls(true, true));
87 
88  $this->assertNull($this->c->problemWith([1, 2]));
89  }

◆ testNotAccepts()

IsArrayOfConstraintTest::testNotAccepts ( )

Definition at line 33 of file IsArrayOfConstraintTest.php.

34  {
35  $this->on_element
36  ->expects($this->exactly(2))
37  ->method("accepts")
38  ->withConsecutive([1], [2])
39  ->will($this->onConsecutiveCalls(true, false));
40 
41  $this->assertFalse($this->c->accepts([1, 2, 3]));
42  }

◆ testNotAcceptsNoneArrays()

IsArrayOfConstraintTest::testNotAcceptsNoneArrays ( )

Definition at line 44 of file IsArrayOfConstraintTest.php.

45  {
46  $this->assertFalse($this->c->accepts(1));
47  }

◆ testProblemWith()

IsArrayOfConstraintTest::testProblemWith ( )

Definition at line 91 of file IsArrayOfConstraintTest.php.

92  {
93  $this->on_element
94  ->expects($this->exactly(3))
95  ->method("problemWith")
96  ->withConsecutive([1], [2], [3])
97  ->will($this->onConsecutiveCalls(null, "2", "3"));
98 
99  $this->lng
100  ->expects($this->exactly(1))
101  ->method("txt")
102  ->withConsecutive(["not_an_array_of"])
103  ->willReturn("-%s-");
104 
105  $this->assertEquals("-2 3-", $this->c->problemWith([1,2,3]));
106  }

◆ testProblemWithNoneArray()

IsArrayOfConstraintTest::testProblemWithNoneArray ( )

Definition at line 108 of file IsArrayOfConstraintTest.php.

109  {
110  $this->lng
111  ->expects($this->exactly(1))
112  ->method("txt")
113  ->withConsecutive(["not_an_array"])
114  ->willReturn("-%s-");
115 
116  $this->assertEquals("-integer-", $this->c->problemWith(1));
117  }

◆ testRestrictError()

IsArrayOfConstraintTest::testRestrictError ( )

Definition at line 155 of file IsArrayOfConstraintTest.php.

References $res.

156  {
157  $error = $this->df->error("error");
158 
159  $res = $this->c->restrict($error);
160  $this->assertSame($error, $res);
161  }
foreach($_POST as $key=> $value) $res

◆ testRestrictNotOk()

IsArrayOfConstraintTest::testRestrictNotOk ( )

Definition at line 133 of file IsArrayOfConstraintTest.php.

References $res.

134  {
135  $this->on_element
136  ->expects($this->exactly(2))
137  ->method("accepts")
138  ->withConsecutive([1], [2])
139  ->will($this->onConsecutiveCalls(true, false));
140 
141  $not_ok = $this->df->ok([1,2]);
142 
143  $res = $this->c->restrict($not_ok);
144  $this->assertFalse($res->isOk());
145  }
foreach($_POST as $key=> $value) $res

◆ testRestrictNotOkForNoneArray()

IsArrayOfConstraintTest::testRestrictNotOkForNoneArray ( )

Definition at line 147 of file IsArrayOfConstraintTest.php.

References $res.

148  {
149  $not_ok = $this->df->ok(1);
150 
151  $res = $this->c->restrict($not_ok);
152  $this->assertFalse($res->isOk());
153  }
foreach($_POST as $key=> $value) $res

◆ testRestrictOk()

IsArrayOfConstraintTest::testRestrictOk ( )

Definition at line 119 of file IsArrayOfConstraintTest.php.

References $ok, and $res.

120  {
121  $this->on_element
122  ->expects($this->exactly(2))
123  ->method("accepts")
124  ->withConsecutive([1], [2])
125  ->will($this->onConsecutiveCalls(true, true));
126 
127  $ok = $this->df->ok([1, 2]);
128 
129  $res = $this->c->restrict($ok);
130  $this->assertTrue($res->isOk());
131  }
foreach($_POST as $key=> $value) $res

◆ testWithProblemBuilder()

IsArrayOfConstraintTest::testWithProblemBuilder ( )

Definition at line 163 of file IsArrayOfConstraintTest.php.

164  {
165  $new_c = $this->c->withProblemBuilder(function () {
166  return "This was a fault";
167  });
168  $this->assertEquals("This was a fault", $new_c->problemWith(2));
169  }

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