ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
HasMaxLengthConstraintTest Class Reference
+ Inheritance diagram for HasMaxLengthConstraintTest:
+ Collaboration diagram for HasMaxLengthConstraintTest:

Public Member Functions

 setUp ()
 
 testAccepts1 ()
 
 testAccepts2 ()
 
 testNotAccepts ()
 
 testCheckSucceed ()
 
 testCheckFails ()
 
 testNoProblemWith ()
 
 testProblemWith ()
 
 testRestrictOk ()
 
 testRestrictNotOk ()
 
 testRestrictError ()
 
 testWithProblemBuilder ()
 

Detailed Description

Definition at line 9 of file HasMaxLengthConstraintTest.php.

Member Function Documentation

◆ setUp()

HasMaxLengthConstraintTest::setUp ( )

Definition at line 11 of file HasMaxLengthConstraintTest.php.

12  {
13  $this->df = new Data\Factory();
14  $this->lng = $this->createMock(\ilLanguage::class);
15  $this->f = new Validation\Factory($this->df, $this->lng);
16 
17  $this->max_length = 2;
18 
19  $this->c = $this->f->hasMaxLength($this->max_length);
20  }

◆ testAccepts1()

HasMaxLengthConstraintTest::testAccepts1 ( )

Definition at line 22 of file HasMaxLengthConstraintTest.php.

23  {
24  $this->assertTrue($this->c->accepts("12"));
25  }

◆ testAccepts2()

HasMaxLengthConstraintTest::testAccepts2 ( )

Definition at line 27 of file HasMaxLengthConstraintTest.php.

28  {
29  $this->assertTrue($this->c->accepts("1"));
30  }

◆ testCheckFails()

HasMaxLengthConstraintTest::testCheckFails ( )

Definition at line 43 of file HasMaxLengthConstraintTest.php.

44  {
45  $this->expectException(\UnexpectedValueException::class);
46  $this->c->check("123");
47  }

◆ testCheckSucceed()

HasMaxLengthConstraintTest::testCheckSucceed ( )

Definition at line 37 of file HasMaxLengthConstraintTest.php.

38  {
39  $this->c->check("12");
40  $this->assertTrue(true); // does not throw
41  }

◆ testNoProblemWith()

HasMaxLengthConstraintTest::testNoProblemWith ( )

Definition at line 49 of file HasMaxLengthConstraintTest.php.

50  {
51  $this->assertNull($this->c->problemWith("12"));
52  }

◆ testNotAccepts()

HasMaxLengthConstraintTest::testNotAccepts ( )

Definition at line 32 of file HasMaxLengthConstraintTest.php.

33  {
34  $this->assertFalse($this->c->accepts("123"));
35  }

◆ testProblemWith()

HasMaxLengthConstraintTest::testProblemWith ( )

Definition at line 54 of file HasMaxLengthConstraintTest.php.

References Sabre\Event\once().

55  {
56  $this->lng
57  ->expects($this->once())
58  ->method("txt")
59  ->with("not_max_length")
60  ->willReturn("-%s-");
61 
62  $this->assertEquals("-2-", $this->c->problemWith("123"));
63  }
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
+ Here is the call graph for this function:

◆ testRestrictError()

HasMaxLengthConstraintTest::testRestrictError ( )

Definition at line 81 of file HasMaxLengthConstraintTest.php.

References $res.

82  {
83  $error = $this->df->error("error");
84 
85  $res = $this->c->restrict($error);
86  $this->assertSame($error, $res);
87  }
foreach($_POST as $key=> $value) $res

◆ testRestrictNotOk()

HasMaxLengthConstraintTest::testRestrictNotOk ( )

Definition at line 73 of file HasMaxLengthConstraintTest.php.

References $res.

74  {
75  $not_ok = $this->df->ok("123");
76 
77  $res = $this->c->restrict($not_ok);
78  $this->assertFalse($res->isOk());
79  }
foreach($_POST as $key=> $value) $res

◆ testRestrictOk()

HasMaxLengthConstraintTest::testRestrictOk ( )

Definition at line 65 of file HasMaxLengthConstraintTest.php.

References $ok, and $res.

66  {
67  $ok = $this->df->ok("12");
68 
69  $res = $this->c->restrict($ok);
70  $this->assertTrue($res->isOk());
71  }
foreach($_POST as $key=> $value) $res

◆ testWithProblemBuilder()

HasMaxLengthConstraintTest::testWithProblemBuilder ( )

Definition at line 89 of file HasMaxLengthConstraintTest.php.

90  {
91  $new_c = $this->c->withProblemBuilder(function () {
92  return "This was a fault";
93  });
94  $this->assertEquals("This was a fault", $new_c->problemWith("123"));
95  }

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