ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
GreaterThanConstraintTest.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2018 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
6 
7 require_once("libs/composer/vendor/autoload.php");
8 
9 use ILIAS\Data;
11 
13 {
17  private $df;
18 
22  private $lng;
23 
27  private $greater_than;
28 
29  public function setUp() : void
30  {
31  $this->df = new Data\Factory();
32  $this->lng = $this->getMockBuilder(\ilLanguage::class)
33  ->disableOriginalConstructor()
34  ->getMock();
35 
36  $this->greater_than = 10;
37 
38  $this->c = new \ILIAS\Refinery\Integer\GreaterThan(
39  $this->greater_than,
40  $this->df,
41  $this->lng
42  );
43  }
44 
45  public function testAccepts()
46  {
47  $this->assertTrue($this->c->accepts(12));
48  }
49 
50  public function testNotAccepts()
51  {
52  $this->assertFalse($this->c->accepts(2));
53  }
54 
55  public function testCheckSucceed()
56  {
57  $this->c->check(12);
58  $this->assertTrue(true); // does not throw
59  }
60 
61  public function testCheckFails()
62  {
63  $this->expectException(\UnexpectedValueException::class);
64  $this->c->check(2);
65  }
66 
67  public function testNoProblemWith()
68  {
69  $this->assertNull($this->c->problemWith(12));
70  }
71 
72  public function testProblemWith()
73  {
74  $this->lng
75  ->expects($this->once())
76  ->method("txt")
77  ->with("not_greater_than")
78  ->willReturn("-%s-%s-");
79 
80  $this->assertEquals("-2-10-", $this->c->problemWith(2));
81  }
82 
83  public function testRestrictOk()
84  {
85  $ok = $this->df->ok(12);
86 
87  $res = $this->c->applyTo($ok);
88  $this->assertTrue($res->isOk());
89  }
90 
91  public function testRestrictNotOk()
92  {
93  $not_ok = $this->df->ok(2);
94 
95  $res = $this->c->applyTo($not_ok);
96  $this->assertFalse($res->isOk());
97  }
98 
99  public function testRestrictError()
100  {
101  $error = $this->df->error("error");
102 
103  $res = $this->c->applyTo($error);
104  $this->assertSame($error, $res);
105  }
106 
107  public function testWithProblemBuilder()
108  {
109  $new_c = $this->c->withProblemBuilder(function () {
110  return "This was a fault";
111  });
112  $this->assertEquals("This was a fault", $new_c->problemWith(2));
113  }
114 }
foreach($_POST as $key=> $value) $res
Builds data types.
Definition: Factory.php:19