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

Class LogicalOrTest. More...

+ Inheritance diagram for LogicalOrTest:
+ Collaboration diagram for LogicalOrTest:

Public Member Functions

 testAccept (LogicalOr $constraint, $okValue, $errorValue)
 @dataProvider constraintsProvider More...
 
 testCheck (LogicalOr $constraint, $okValue, $errorValue)
 @dataProvider constraintsProvider More...
 
 testProblemWith (LogicalOr $constraint, $okValue, $errorValue)
 @dataProvider constraintsProvider More...
 
 testRestrict (LogicalOr $constraint, $okValue, $errorValue)
 @dataProvider constraintsProvider More...
 
 testWithProblemBuilder (LogicalOr $constraint, $okValue, $errorValue)
 @dataProvider constraintsProvider More...
 
 constraintsProvider ()
 

Detailed Description

Class LogicalOrTest.

Author
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de

Definition at line 14 of file LogicalOrTest.php.

Member Function Documentation

◆ constraintsProvider()

LogicalOrTest::constraintsProvider ( )
Returns
array

Definition at line 108 of file LogicalOrTest.php.

108 : array
109 {
110 $mock = $this->getMockBuilder(\ilLanguage::class)->disableOriginalConstructor()->getMock();
111 $f = new Validation\Factory(new Data\Factory(), $mock);
112
113 return [
114 [$f->or([$f->isInt(), $f->isString()]), '5', []],
115 [$f->or([$f->greaterThan(5), $f->lessThan(2)]), 7, 3]
116 ];
117 }
Builds data types.
Definition: Factory.php:15

References $f.

◆ testAccept()

LogicalOrTest::testAccept ( LogicalOr  $constraint,
  $okValue,
  $errorValue 
)

@dataProvider constraintsProvider

Parameters
LogicalOr$constraint
$okValue
$errorValue

Definition at line 22 of file LogicalOrTest.php.

23 {
24 $this->assertTrue($constraint->accepts($okValue));
25 $this->assertFalse($constraint->accepts($errorValue));
26 }
accepts($value)
Tells if the provided value complies.bool
Definition: Custom.php:72

References ILIAS\Validation\Constraints\Custom\accepts().

+ Here is the call graph for this function:

◆ testCheck()

LogicalOrTest::testCheck ( LogicalOr  $constraint,
  $okValue,
  $errorValue 
)

@dataProvider constraintsProvider

Parameters
LogicalOr$constraint
$okValue
$errorValue

Definition at line 34 of file LogicalOrTest.php.

35 {
36 $raised = false;
37
38 try {
39 $constraint->check($errorValue);
40 } catch (\UnexpectedValueException $e) {
41 $raised = true;
42 }
43
44 $this->assertTrue($raised);
45
46 try {
47 $constraint->check($okValue);
48 $raised = false;
49 } catch (\UnexpectedValueException $e) {
50 $raised = true;
51 }
52
53 $this->assertFalse($raised);
54 }
check($value)
Checks the provided value.Should not throw if accepts($value).UnexpectedValueException if value does ...
Definition: Custom.php:60

References ILIAS\Validation\Constraints\Custom\check().

+ Here is the call graph for this function:

◆ testProblemWith()

LogicalOrTest::testProblemWith ( LogicalOr  $constraint,
  $okValue,
  $errorValue 
)

@dataProvider constraintsProvider

Parameters
LogicalOr$constraint
$okValue
$errorValue

Definition at line 62 of file LogicalOrTest.php.

63 {
64 $this->assertNull($constraint->problemWith($okValue));
65 $this->assertInternalType('string', $constraint->problemWith($errorValue));
66 }
problemWith($value)
Tells what the problem with the provided value is.Should return null if accepts($value)....
Definition: Custom.php:80

References ILIAS\Validation\Constraints\Custom\problemWith().

+ Here is the call graph for this function:

◆ testRestrict()

LogicalOrTest::testRestrict ( LogicalOr  $constraint,
  $okValue,
  $errorValue 
)

@dataProvider constraintsProvider

Parameters
LogicalOr$constraint
$okValue
$errorValue

Definition at line 74 of file LogicalOrTest.php.

75 {
76 $rf = new Data\Factory();
77 $ok = $rf->ok($okValue);
78 $ok2 = $rf->ok($errorValue);
79 $error = $rf->error('text');
80
81 $result = $constraint->restrict($ok);
82 $this->assertTrue($result->isOk());
83
84 $result = $constraint->restrict($ok2);
85 $this->assertTrue($result->isError());
86
87 $result = $constraint->restrict($error);
88 $this->assertSame($error, $result);
89 }
$result
restrict(Result $result)
Restricts a Result.Must do nothing with the result if $result->isError(). Must replace the result wit...
Definition: Custom.php:92

References $ok, $result, and ILIAS\Validation\Constraints\Custom\restrict().

+ Here is the call graph for this function:

◆ testWithProblemBuilder()

LogicalOrTest::testWithProblemBuilder ( LogicalOr  $constraint,
  $okValue,
  $errorValue 
)

@dataProvider constraintsProvider

Parameters
LogicalOr$constraint
$okValue
$errorValue

Definition at line 97 of file LogicalOrTest.php.

98 {
99 $new_constraint = $constraint->withProblemBuilder(function () {
100 return "This was a vault";
101 });
102 $this->assertEquals("This was a vault", $new_constraint->problemWith($errorValue));
103 }
withProblemBuilder(callable $builder)
Get a constraint like this one with a builder for a custom error message.problemWith() must return an...
Definition: Custom.php:110

References ILIAS\Validation\Constraints\Custom\withProblemBuilder().

+ Here is the call graph for this function:

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