ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
SequentialConstraintTest.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 */
4 require_once("libs/composer/vendor/autoload.php");
5 
7 use ILIAS\Data;
9 
15 class SequentialTest extends TestCase
16 {
20  private $df;
21 
25  private $lng;
26 
30  private $refinery;
31 
35  private $greater_than_3;
36 
40  private $less_than_5;
41 
42  protected function setUp() : void
43  {
44  $this->df = new Data\Factory();
45  $this->lng = $this->createMock(\ilLanguage::class);
46  $this->refinery = new \ILIAS\Refinery\Factory($this->df, $this->lng);
47 
48  $group = $this->refinery->custom();
49 
50  $this->greater_than_3 = $group->constraint(
51  function ($value) {
52  return $value > 3;
53  },
54  "not_greater_than_3"
55  );
56 
57  $this->less_than_5 = $group->constraint(
58  function ($value) {
59  return $value < 5;
60  },
61  "not_less_than_5"
62  );
63 
64  $this->c = $this->refinery
65  ->logical()
66  ->sequential([$this->greater_than_3, $this->less_than_5]);
67  }
68 
69  public function testAccepts()
70  {
71  $this->assertTrue($this->c->accepts(4));
72  }
73 
74  public function testNotAccepts()
75  {
76  $this->assertFalse($this->c->accepts(2));
77  }
78 
79  public function testCheckSucceed()
80  {
81  $this->c->check(4);
82  $this->assertTrue(true); // does not throw
83  }
84 
85  public function testCheckFails()
86  {
87  $this->expectException(\UnexpectedValueException::class);
88  $this->c->check(2);
89  }
90 
91  public function testNoProblemWith()
92  {
93  $this->assertNull($this->c->problemWith(4));
94  }
95 
96  public function testProblemWith1()
97  {
98  $this->lng
99  ->expects($this->never())
100  ->method("txt");
101 
102  $this->assertEquals("not_greater_than_3", $this->c->problemWith(2));
103  }
104 
105  public function testProblemWith2()
106  {
107  $this->lng
108  ->expects($this->never())
109  ->method("txt");
110 
111  $this->assertEquals("not_less_than_5", $this->c->problemWith(6));
112  }
113 
114  public function testRestrictOk()
115  {
116  $ok = $this->df->ok(4);
117 
118  $res = $this->c->applyTo($ok);
119  $this->assertTrue($res->isOk());
120  }
121 
122  public function testRestrictNotOk()
123  {
124  $not_ok = $this->df->ok(7);
125 
126  $res = $this->c->applyTo($not_ok);
127  $this->assertFalse($res->isOk());
128  }
129 
130  public function testRestrictError()
131  {
132  $error = $this->df->error("error");
133 
134  $res = $this->c->applyTo($error);
135  $this->assertSame($error, $res);
136  }
137 
138  public function testWithProblemBuilder()
139  {
140  $new_c = $this->c->withProblemBuilder(function () {
141  return "This was a fault";
142  });
143  $this->assertEquals("This was a fault", $new_c->problemWith(7));
144  }
145 }
TestCase for the sequential constraint.
foreach($_POST as $key=> $value) $res