ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
NotConstraintTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2017, 2018, Stefan Hecken <stefan.hecken@concepts-and-training.de>, Richard Klees <richard.klees@concepts-and-training.de, Extended GPL, see docs/LICENSE */
4require_once("libs/composer/vendor/autoload.php");
5
7use 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->not_true = $this->f->not($this->f->custom(
18 function ($v) {
19 return true;
20 },
21 "not_true"
22 ));
23
24 $this->not_false = $this->f->not($this->f->custom(
25 function ($v) {
26 return false;
27 },
28 "not_false"
29 ));
30 }
31
32 public function testAccepts()
33 {
34 $this->assertTrue($this->not_false->accepts(null));
35 }
36
37 public function testNotAccepts()
38 {
39 $this->assertFalse($this->not_true->accepts(null));
40 }
41
42 public function testCheckSucceed()
43 {
44 $this->not_false->check(null);
45 $this->assertTrue(true); // does not throw
46 }
47
48 public function testCheckFails()
49 {
50 $this->expectException(\UnexpectedValueException::class);
51 $this->not_true->check(null);
52 }
53
54 public function testNoProblemWith()
55 {
56 $this->assertNull($this->not_false->problemWith(null));
57 }
58
59 public function testProblemWith()
60 {
61 $this->lng
62 ->expects($this->once())
63 ->method("txt")
64 ->with("not_generic")
65 ->willReturn("-%s-");
66
67 $this->assertEquals("-not_true-", $this->not_true->problemWith(null));
68 }
69
70 public function testRestrictOk()
71 {
72 $ok = $this->df->ok(null);
73
74 $res = $this->not_false->restrict($ok);
75 $this->assertTrue($res->isOk());
76 }
77
78 public function testRestrictNotOk()
79 {
80 $not_ok = $this->df->ok(null);
81
82 $res = $this->not_true->restrict($not_ok);
83 $this->assertFalse($res->isOk());
84 }
85
86 public function testRestrictError()
87 {
88 $error = $this->df->error("error");
89
90 $res = $this->not_false->restrict($error);
91 $this->assertSame($error, $res);
92 }
93
94 public function testWithProblemBuilder()
95 {
96 $new_c = $this->not_true->withProblemBuilder(function () {
97 return "This was a fault";
98 });
99 $this->assertEquals("This was a fault", $new_c->problemWith(null));
100 }
101}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:15
testWithProblemBuilder()
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
foreach($_POST as $key=> $value) $res