ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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
 
 $txt_id = ''
 

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 33 of file CustomTest.php.

Member Function Documentation

◆ setUp()

ValidationConstraintsCustomTest::setUp ( )

Definition at line 42 of file CustomTest.php.

References $txt.

42  : void
43  {
44  $is_ok = function ($value) {
45  return false;
46  };
47  $this->txt_id = "TXT_ID";
48  $error = function (callable $txt, $value) {
49  return $txt($this->txt_id, $value);
50  };
51  $this->lng = $this->createMock(\ilLanguage::class);
52  $this->constraint = new MyValidationConstraintsConstraint($is_ok, $error, new Data\Factory(), $this->lng);
53  }
Builds data types.
Definition: Factory.php:19
$txt
Definition: error.php:13

◆ test_exception_on_no_parameter()

ValidationConstraintsCustomTest::test_exception_on_no_parameter ( )

Definition at line 88 of file CustomTest.php.

89  {
90  $lng_closure = $this->constraint->_getLngClosure();
91 
92  $this->expectException(\InvalidArgumentException::class);
93 
94  $lng_closure();
95  }

◆ test_gracefully_handle_arrays_and_objects()

ValidationConstraintsCustomTest::test_gracefully_handle_arrays_and_objects ( )

Definition at line 113 of file CustomTest.php.

References $res.

114  {
115  $lng_closure = $this->constraint->_getLngClosure();
116 
117  $this->lng
118  ->expects($this->once())
119  ->method("txt")
120  ->with("id")
121  ->willReturn("%s-%s-%s-%s-");
122 
123  $to_string = new MyToStringClass("foo");
124 
125  $res = $lng_closure("id", [], new \stdClass(), "foo", null);
126 
127  $this->assertEquals("array-" . \stdClass::class . "-foo-null-", $res);
128  }
foreach($_POST as $key=> $value) $res

◆ test_no_sprintf_on_one_parameter()

ValidationConstraintsCustomTest::test_no_sprintf_on_one_parameter ( )

Definition at line 97 of file CustomTest.php.

References $res.

98  {
99  $lng_closure = $this->constraint->_getLngClosure();
100 
101  $txt_out = "txt";
102  $this->lng
103  ->expects($this->once())
104  ->method("txt")
105  ->with($this->txt_id)
106  ->willReturn($txt_out);
107 
108  $res = $lng_closure($this->txt_id);
109 
110  $this->assertEquals($txt_out, $res);
111  }
foreach($_POST as $key=> $value) $res

◆ test_use_txt()

ValidationConstraintsCustomTest::test_use_txt ( )

Definition at line 73 of file CustomTest.php.

74  {
75  $txt_out = "'%s'";
76  $this->lng
77  ->expects($this->once())
78  ->method("txt")
79  ->with($this->txt_id)
80  ->willReturn($txt_out);
81 
82  $value = "VALUE";
83  $problem = $this->constraint->problemWith($value);
84 
85  $this->assertEquals(sprintf($txt_out, $value), $problem);
86  }

◆ testProblemBuilderRetrievesLngClosure()

ValidationConstraintsCustomTest::testProblemBuilderRetrievesLngClosure ( )

Definition at line 63 of file CustomTest.php.

References $c, and $txt.

64  {
65  $c = $this->constraint->withProblemBuilder(function ($txt) {
66  $this->cls = $txt;
67  return "";
68  });
69  $c->problemWith("");
70  $this->assertTrue(is_callable($this->cls));
71  }
$c
Definition: cli.php:37
$txt
Definition: error.php:13

◆ testWithProblemBuilder()

ValidationConstraintsCustomTest::testWithProblemBuilder ( )

Definition at line 55 of file CustomTest.php.

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

Field Documentation

◆ $f

ValidationConstraintsCustomTest::$f = null
protected

Definition at line 38 of file CustomTest.php.

◆ $txt_id

ValidationConstraintsCustomTest::$txt_id = ''
protected

Definition at line 40 of file CustomTest.php.


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