ILIAS  release_8 Revision v8.24
ValidationConstraintsCustomTest Class Reference
+ Inheritance diagram for ValidationConstraintsCustomTest:
+ Collaboration diagram for ValidationConstraintsCustomTest:

Public Member Functions

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

Protected Member Functions

 setUp ()
 

Private Attributes

string $txt_id = ''
 
ilLanguage $lng
 
MyValidationConstraintsConstraint $constraint
 

Detailed Description

Definition at line 43 of file CustomTest.php.

Member Function Documentation

◆ setUp()

ValidationConstraintsCustomTest::setUp ( )
protected

Definition at line 49 of file CustomTest.php.

49 : void
50 {
51 $is_ok = static function ($value): bool {
52 return false;
53 };
54 $this->txt_id = "TXT_ID";
55 $error = function (callable $txt, $value): string {
56 return $txt($this->txt_id, $value);
57 };
58 $this->lng = $this->createMock(ilLanguage::class);
59 $this->constraint = new MyValidationConstraintsConstraint($is_ok, $error, new DataFactory(), $this->lng);
60 }
$txt
Definition: error.php:13

References $txt, and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ test_exception_on_no_parameter()

ValidationConstraintsCustomTest::test_exception_on_no_parameter ( )

Definition at line 96 of file CustomTest.php.

96 : void
97 {
98 $lng_closure = $this->constraint->_getLngClosure();
99
100 $this->expectException(InvalidArgumentException::class);
101
102 $lng_closure();
103 }

◆ test_gracefully_handle_arrays_and_objects()

ValidationConstraintsCustomTest::test_gracefully_handle_arrays_and_objects ( )

Definition at line 121 of file CustomTest.php.

121 : void
122 {
123 $lng_closure = $this->constraint->_getLngClosure();
124
125 $this->lng
126 ->expects($this->once())
127 ->method("txt")
128 ->with("id")
129 ->willReturn("%s-%s-%s-%s-");
130
131 $to_string = new MyToStringClass();
132
133 $res = $lng_closure("id", [], new stdClass(), "foo", null);
134
135 $this->assertEquals("array-" . stdClass::class . "-foo-null-", $res);
136 }
$res
Definition: ltiservices.php:69

References $res, and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ test_no_sprintf_on_one_parameter()

ValidationConstraintsCustomTest::test_no_sprintf_on_one_parameter ( )

Definition at line 105 of file CustomTest.php.

105 : void
106 {
107 $lng_closure = $this->constraint->_getLngClosure();
108
109 $txt_out = "txt";
110 $this->lng
111 ->expects($this->once())
112 ->method("txt")
113 ->with($this->txt_id)
114 ->willReturn($txt_out);
115
116 $res = $lng_closure($this->txt_id);
117
118 $this->assertEquals($txt_out, $res);
119 }

References $res, and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ test_use_txt()

ValidationConstraintsCustomTest::test_use_txt ( )

Definition at line 81 of file CustomTest.php.

81 : void
82 {
83 $txt_out = "'%s'";
84 $this->lng
85 ->expects($this->once())
86 ->method("txt")
87 ->with($this->txt_id)
88 ->willReturn($txt_out);
89
90 $value = "VALUE";
91 $problem = $this->constraint->problemWith($value);
92
93 $this->assertEquals(sprintf($txt_out, $value), $problem);
94 }

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ testProblemBuilderRetrievesLngClosure()

ValidationConstraintsCustomTest::testProblemBuilderRetrievesLngClosure ( )

Definition at line 70 of file CustomTest.php.

70 : void
71 {
72 $cls = null;
73 $c = $this->constraint->withProblemBuilder(function ($txt) use (&$cls): string {
74 $cls = $txt;
75 return "";
76 });
77 $c->problemWith("");
78 $this->assertIsCallable($cls);
79 }
$c
Definition: cli.php:38

References $c, and $txt.

◆ testWithProblemBuilder()

ValidationConstraintsCustomTest::testWithProblemBuilder ( )

Definition at line 62 of file CustomTest.php.

62 : void
63 {
64 $new_constraint = $this->constraint->withProblemBuilder(static function (): string {
65 return "This was a fault";
66 });
67 $this->assertEquals("This was a fault", $new_constraint->problemWith(""));
68 }

Field Documentation

◆ $constraint

MyValidationConstraintsConstraint ValidationConstraintsCustomTest::$constraint
private

Definition at line 47 of file CustomTest.php.

◆ $lng

ilLanguage ValidationConstraintsCustomTest::$lng
private

Definition at line 46 of file CustomTest.php.

◆ $txt_id

string ValidationConstraintsCustomTest::$txt_id = ''
private

Definition at line 45 of file CustomTest.php.


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