ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 require_once("libs/composer/vendor/autoload.php");
5 
7 use ILIAS\Data;
8 
10 {
11  public function setUp()
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->greater_than = 10;
18 
19  $this->c = $this->f->greaterThan($this->greater_than);
20  }
21 
22  public function testAccepts()
23  {
24  $this->assertTrue($this->c->accepts(12));
25  }
26 
27  public function testNotAccepts()
28  {
29  $this->assertFalse($this->c->accepts(2));
30  }
31 
32  public function testCheckSucceed()
33  {
34  $this->c->check(12);
35  $this->assertTrue(true); // does not throw
36  }
37 
38  public function testCheckFails()
39  {
40  $this->expectException(\UnexpectedValueException::class);
41  $this->c->check(2);
42  }
43 
44  public function testNoProblemWith()
45  {
46  $this->assertNull($this->c->problemWith(12));
47  }
48 
49  public function testProblemWith()
50  {
51  $this->lng
52  ->expects($this->once())
53  ->method("txt")
54  ->with("not_greater_than")
55  ->willReturn("-%s-%s-");
56 
57  $this->assertEquals("-2-10-", $this->c->problemWith(2));
58  }
59 
60  public function testRestrictOk()
61  {
62  $ok = $this->df->ok(12);
63 
64  $res = $this->c->restrict($ok);
65  $this->assertTrue($res->isOk());
66  }
67 
68  public function testRestrictNotOk()
69  {
70  $not_ok = $this->df->ok(2);
71 
72  $res = $this->c->restrict($not_ok);
73  $this->assertFalse($res->isOk());
74  }
75 
76  public function testRestrictError()
77  {
78  $error = $this->df->error("error");
79 
80  $res = $this->c->restrict($error);
81  $this->assertSame($error, $res);
82  }
83 
84  public function testWithProblemBuilder()
85  {
86  $new_c = $this->c->withProblemBuilder(function () {
87  return "This was a fault";
88  });
89  $this->assertEquals("This was a fault", $new_c->problemWith(2));
90  }
91 }
foreach($_POST as $key=> $value) $res
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.