ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ValidationConstraintsCustomTest Class Reference

TestCase for the factory of constraints. More...

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

Public Member Functions

 testAccept ($constraint, $ok_value, $error_value, $message)
 constraintsProvider More...
 
 testCheck ($constraint, $ok_value, $error_value, $message)
 constraintsProvider More...
 
 testProblemWith ($constraint, $ok_value, $error_value, $message)
 constraintsProvider More...
 
 testRestrict ($constraint, $ok_value, $error_value, $message)
 constraintsProvider More...
 
 testWithProblemBuilder ($constraint, $ok_value, $error_value, $message)
 constraintsProvider More...
 
 constraintsProvider ()
 

Detailed Description

Member Function Documentation

◆ constraintsProvider()

ValidationConstraintsCustomTest::constraintsProvider ( )

Definition at line 89 of file ValidationConstraintsCustomTest.php.

References array.

90  {
91  $f = new Validation\Factory(new Data\Factory());
92 
93  return array(array($f->custom(function ($value) {
94  return $value > 1;
95  }, "Value is not greater"), 2, 1, "Value is not greater"),
96  array($f->custom(function ($value) {
97  return $value < 2;
98  }, "Value is not greater"), 1, 2, "Value is not greater")
99  );
100  }
Builds data types.
Definition: Factory.php:14
Create styles array
The data for the language used.

◆ testAccept()

ValidationConstraintsCustomTest::testAccept (   $constraint,
  $ok_value,
  $error_value,
  $message 
)

constraintsProvider

Definition at line 18 of file ValidationConstraintsCustomTest.php.

19  {
20  $this->assertTrue($constraint->accepts($ok_value));
21  $this->assertFalse($constraint->accepts($error_value));
22  }

◆ testCheck()

ValidationConstraintsCustomTest::testCheck (   $constraint,
  $ok_value,
  $error_value,
  $message 
)

constraintsProvider

Definition at line 27 of file ValidationConstraintsCustomTest.php.

References $message.

28  {
29  $raised = false;
30  try {
31  $constraint->check($ok_value);
32  } catch (UnexpectedValueException $e) {
33  $raised = true;
34  }
35 
36  $this->assertFalse($raised);
37 
38  try {
39  $constraint->check($error_value);
40  } catch (UnexpectedValueException $e) {
41  $this->assertEquals($message, $e->getMessage());
42  $raised = true;
43  }
44 
45  $this->assertTrue($raised);
46  }
catch(Exception $e) $message

◆ testProblemWith()

ValidationConstraintsCustomTest::testProblemWith (   $constraint,
  $ok_value,
  $error_value,
  $message 
)

constraintsProvider

Definition at line 51 of file ValidationConstraintsCustomTest.php.

References $message.

52  {
53  $this->assertNull($constraint->problemWith($ok_value));
54  $this->assertInternalType("string", $constraint->problemWith($error_value));
55  $this->assertEquals($message, $constraint->problemWith($error_value));
56  }
catch(Exception $e) $message

◆ testRestrict()

ValidationConstraintsCustomTest::testRestrict (   $constraint,
  $ok_value,
  $error_value,
  $message 
)

constraintsProvider

Definition at line 61 of file ValidationConstraintsCustomTest.php.

References $error, $ok, and $result.

62  {
63  $rf = new Data\Factory();
64  $ok = $rf->ok($ok_value);
65  $ok2 = $rf->ok($error_value);
66  $error = $rf->error("text");
67 
68  $result = $constraint->restrict($ok);
69  $this->assertTrue($result->isOk());
70 
71  $result = $constraint->restrict($ok2);
72  $this->assertTrue($result->isError());
73 
74  $result = $constraint->restrict($error);
75  $this->assertSame($error, $result);
76  }
$result
$error
Definition: Error.php:17

◆ testWithProblemBuilder()

ValidationConstraintsCustomTest::testWithProblemBuilder (   $constraint,
  $ok_value,
  $error_value,
  $message 
)

constraintsProvider

Definition at line 81 of file ValidationConstraintsCustomTest.php.

82  {
83  $new_constraint = $constraint->withProblemBuilder(function () {
84  return "This was a vault";
85  });
86  $this->assertEquals("This was a vault", $new_constraint->problemWith($error_value));
87  }

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