ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ValidationConstraintsCustomTest Class Reference

TestCase for the custom constraints. More...

+ Inheritance diagram for ValidationConstraintsCustomTest:
+ Collaboration diagram for ValidationConstraintsCustomTest:

Public Member Functions

 setUp ()
 
 testWithProblemBuilder ()
 
 testProblemBuilderRetrievesLngClosure ()
 
 test_use_txt ()
 
 test_exception_on_no_parameter ()
 
 test_no_sprintf_on_one_parameter ()
 
 test_gracefully_handle_arrays_and_objects ()
 

Protected Attributes

 $f = null
 

Detailed Description

TestCase for the custom constraints.

Author
Richard Klees richa.nosp@m.rd.k.nosp@m.lees@.nosp@m.conc.nosp@m.epts-.nosp@m.and-.nosp@m.train.nosp@m.ing..nosp@m.de

Definition at line 32 of file CustomTest.php.

Member Function Documentation

◆ setUp()

ValidationConstraintsCustomTest::setUp ( )

Definition at line 39 of file CustomTest.php.

References $txt.

40  {
41  $is_ok = function ($value) {
42  return false;
43  };
44  $this->txt_id = "TXT_ID";
45  $error = function (callable $txt, $value) use ($txt_id) {
46  return $txt($txt_id, $value);
47  };
48  $this->lng = $this->createMock(\ilLanguage::class);
49  $this->constraint = new MyValidationConstraintsCustom($is_ok, $error, new Data\Factory(), $this->lng);
50  }
Builds data types.
Definition: Factory.php:14
$txt
Definition: error.php:11

◆ test_exception_on_no_parameter()

ValidationConstraintsCustomTest::test_exception_on_no_parameter ( )

Definition at line 85 of file CustomTest.php.

86  {
87  $lng_closure = $this->constraint->_getLngClosure();
88 
89  $this->expectException(\InvalidArgumentException::class);
90 
91  $lng_closure();
92  }

◆ test_gracefully_handle_arrays_and_objects()

ValidationConstraintsCustomTest::test_gracefully_handle_arrays_and_objects ( )

Definition at line 110 of file CustomTest.php.

References $res, and Sabre\Event\once().

111  {
112  $lng_closure = $this->constraint->_getLngClosure();
113 
114  $this->lng
115  ->expects($this->once())
116  ->method("txt")
117  ->with("id")
118  ->willReturn("%s-%s-%s-%s-");
119 
120  $to_string = new MyToStringClass("foo");
121 
122  $res = $lng_closure("id", [], new \stdClass(), "foo", null);
123 
124  $this->assertEquals("array-" . \stdClass::class . "-foo-null-", $res);
125  }
foreach($_POST as $key=> $value) $res
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
+ Here is the call graph for this function:

◆ test_no_sprintf_on_one_parameter()

ValidationConstraintsCustomTest::test_no_sprintf_on_one_parameter ( )

Definition at line 94 of file CustomTest.php.

References $res, and Sabre\Event\once().

95  {
96  $lng_closure = $this->constraint->_getLngClosure();
97 
98  $txt_out = "txt";
99  $this->lng
100  ->expects($this->once())
101  ->method("txt")
102  ->with($this->txt_id)
103  ->willReturn($txt_out);
104 
105  $res = $lng_closure($this->txt_id);
106 
107  $this->assertEquals($txt_out, $res);
108  }
foreach($_POST as $key=> $value) $res
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
+ Here is the call graph for this function:

◆ test_use_txt()

ValidationConstraintsCustomTest::test_use_txt ( )

Definition at line 70 of file CustomTest.php.

References Sabre\Event\once().

71  {
72  $txt_out = "'%s'";
73  $this->lng
74  ->expects($this->once())
75  ->method("txt")
76  ->with($txt_id)
77  ->willReturn($txt_out);
78 
79  $value = "VALUE";
80  $problem = $this->constraint->problemWith($value);
81 
82  $this->assertEquals(sprintf($txt_out, $value), $problem);
83  }
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
+ Here is the call graph for this function:

◆ testProblemBuilderRetrievesLngClosure()

ValidationConstraintsCustomTest::testProblemBuilderRetrievesLngClosure ( )

Definition at line 60 of file CustomTest.php.

References $c, and $txt.

61  {
62  $c = $this->constraint->withProblemBuilder(function ($txt) {
63  $this->cls = $txt;
64  return "";
65  });
66  $c->problemWith("");
67  $this->assertTrue(is_callable($this->cls));
68  }
$txt
Definition: error.php:11

◆ testWithProblemBuilder()

ValidationConstraintsCustomTest::testWithProblemBuilder ( )

Definition at line 52 of file CustomTest.php.

53  {
54  $new_constraint = $this->constraint->withProblemBuilder(function () {
55  return "This was a fault";
56  });
57  $this->assertEquals("This was a fault", $new_constraint->problemWith(""));
58  }

Field Documentation

◆ $f

ValidationConstraintsCustomTest::$f = null
protected

Definition at line 37 of file CustomTest.php.


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