ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
LogicalOrTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 
27 class LogicalOrTest extends TestCase
28 {
29  #[DataProvider('constraintsProvider')]
30  public function testAccept(LogicalOr $constraint, mixed $okValue, mixed $errorValue): void
31  {
32  $this->assertTrue($constraint->accepts($okValue));
33  $this->assertFalse($constraint->accepts($errorValue));
34  }
35 
36  #[DataProvider('constraintsProvider')]
37  public function testCheck(LogicalOr $constraint, mixed $okValue, mixed $errorValue): void
38  {
39  $raised = false;
40 
41  try {
42  $constraint->check($errorValue);
43  } catch (UnexpectedValueException $e) {
44  $raised = true;
45  }
46 
47  $this->assertTrue($raised);
48 
49  try {
50  $constraint->check($okValue);
51  $raised = false;
52  } catch (UnexpectedValueException $e) {
53  $raised = true;
54  }
55 
56  $this->assertFalse($raised);
57  }
58 
59  #[DataProvider('constraintsProvider')]
60  public function testProblemWith(LogicalOr $constraint, mixed $okValue, mixed $errorValue): void
61  {
62  $this->assertNull($constraint->problemWith($okValue));
63  $this->assertIsString($constraint->problemWith($errorValue));
64  }
65 
66  #[DataProvider('constraintsProvider')]
67  public function testRestrict(LogicalOr $constraint, mixed $okValue, mixed $errorValue): void
68  {
69  $rf = new DataFactory();
70  $ok = $rf->ok($okValue);
71  $ok2 = $rf->ok($errorValue);
72  $error = $rf->error('text');
73 
74  $result = $constraint->applyTo($ok);
75  $this->assertTrue($result->isOk());
76 
77  $result = $constraint->applyTo($ok2);
78  $this->assertTrue($result->isError());
79 
80  $result = $constraint->applyTo($error);
81  $this->assertSame($error, $result);
82  }
83 
84  #[DataProvider('constraintsProvider')]
85  public function testWithProblemBuilder(LogicalOr $constraint, mixed $okValue, mixed $errorValue): void
86  {
87  $new_constraint = $constraint->withProblemBuilder(static function (): string {
88  return "This was a vault";
89  });
90  $this->assertEquals("This was a vault", $new_constraint->problemWith($errorValue));
91  }
92 
96  public static function constraintsProvider(): array
97  {
98  $language = new class () implements \ILIAS\Language\Language {
99  public function txt(string $a_topic, string $a_default_lang_fallback_mod = ""): string
100  {
101  return $a_topic;
102  }
103  public function loadLanguageModule(string $a_module): void
104  {
105  }
106  public function getLangKey(): string
107  {
108  return '';
109  }
110  public function toJS($key): void
111  {
112  }
113  };
114  $data_factory = new DataFactory();
115 
116  $refinery = new Refinery($data_factory, $language);
117  return [
118  [
119  $refinery->logical()->logicalOr([
120  $refinery->int()->isLessThan(6),
121  $refinery->int()->isGreaterThan(100)
122  ]),
123  '5',
124  8
125  ],
126  [
127  $refinery->logical()->logicalOr([$refinery->int()->isGreaterThan(5), $refinery->int()->isLessThan(2)]),
128  7,
129  3
130  ]
131  ];
132  }
133 }
problemWith($value)
Tells what the problem with the provided value is.
Interface Observer Contains several chained tasks and infos about them.
withProblemBuilder(callable $builder)
Get a constraint like this one with a builder for a custom error message.
testRestrict(LogicalOr $constraint, mixed $okValue, mixed $errorValue)
applyTo(Result $result)
Restricts a Result.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testAccept(LogicalOr $constraint, mixed $okValue, mixed $errorValue)
testCheck(LogicalOr $constraint, mixed $okValue, mixed $errorValue)
testWithProblemBuilder(LogicalOr $constraint, mixed $okValue, mixed $errorValue)
static constraintsProvider()
accepts($value)
Tells if the provided value complies.
check($value)
Checks the provided value.
testProblemWith(LogicalOr $constraint, mixed $okValue, mixed $errorValue)