ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 ()
 

Private Attributes

 $df
 
 $lng
 
 $max_length
 
 $c
 

Detailed Description

Definition at line 10 of file HasMaxLengthConstraintTest.php.

Member Function Documentation

◆ setUp()

HasMaxLengthConstraintTest::setUp ( )

Definition at line 32 of file HasMaxLengthConstraintTest.php.

32  : void
33  {
34  $this->df = new Data\Factory();
35  $this->lng = $this->createMock(\ilLanguage::class);
36 
37  $this->max_length = 2;
38 
39  $this->c = new \ILIAS\Refinery\String\HasMaxLength(
40  $this->max_length,
41  $this->df,
42  $this->lng
43  );
44  }

◆ testAccepts1()

HasMaxLengthConstraintTest::testAccepts1 ( )

Definition at line 46 of file HasMaxLengthConstraintTest.php.

47  {
48  $this->assertTrue($this->c->accepts("12"));
49  }

◆ testAccepts2()

HasMaxLengthConstraintTest::testAccepts2 ( )

Definition at line 51 of file HasMaxLengthConstraintTest.php.

52  {
53  $this->assertTrue($this->c->accepts("1"));
54  }

◆ testCheckFails()

HasMaxLengthConstraintTest::testCheckFails ( )

Definition at line 67 of file HasMaxLengthConstraintTest.php.

68  {
69  $this->expectException(\UnexpectedValueException::class);
70  $this->c->check("123");
71  }

◆ testCheckSucceed()

HasMaxLengthConstraintTest::testCheckSucceed ( )

Definition at line 61 of file HasMaxLengthConstraintTest.php.

62  {
63  $this->c->check("12");
64  $this->assertTrue(true); // does not throw
65  }

◆ testNoProblemWith()

HasMaxLengthConstraintTest::testNoProblemWith ( )

Definition at line 73 of file HasMaxLengthConstraintTest.php.

74  {
75  $this->assertNull($this->c->problemWith("12"));
76  }

◆ testNotAccepts()

HasMaxLengthConstraintTest::testNotAccepts ( )

Definition at line 56 of file HasMaxLengthConstraintTest.php.

57  {
58  $this->assertFalse($this->c->accepts("123"));
59  }

◆ testProblemWith()

HasMaxLengthConstraintTest::testProblemWith ( )

Definition at line 78 of file HasMaxLengthConstraintTest.php.

79  {
80  $this->lng
81  ->expects($this->once())
82  ->method("txt")
83  ->with("not_max_length")
84  ->willReturn("-%s-");
85 
86  $this->assertEquals("-2-", $this->c->problemWith("123"));
87  }

◆ testRestrictError()

HasMaxLengthConstraintTest::testRestrictError ( )

Definition at line 105 of file HasMaxLengthConstraintTest.php.

References $res.

106  {
107  $error = $this->df->error("error");
108 
109  $res = $this->c->applyTo($error);
110  $this->assertSame($error, $res);
111  }
foreach($_POST as $key=> $value) $res

◆ testRestrictNotOk()

HasMaxLengthConstraintTest::testRestrictNotOk ( )

Definition at line 97 of file HasMaxLengthConstraintTest.php.

References $res.

98  {
99  $not_ok = $this->df->ok("123");
100 
101  $res = $this->c->applyTo($not_ok);
102  $this->assertFalse($res->isOk());
103  }
foreach($_POST as $key=> $value) $res

◆ testRestrictOk()

HasMaxLengthConstraintTest::testRestrictOk ( )

Definition at line 89 of file HasMaxLengthConstraintTest.php.

References $ok, and $res.

90  {
91  $ok = $this->df->ok("12");
92 
93  $res = $this->c->applyTo($ok);
94  $this->assertTrue($res->isOk());
95  }
foreach($_POST as $key=> $value) $res

◆ testWithProblemBuilder()

HasMaxLengthConstraintTest::testWithProblemBuilder ( )

Definition at line 113 of file HasMaxLengthConstraintTest.php.

114  {
115  $new_c = $this->c->withProblemBuilder(function () {
116  return "This was a fault";
117  });
118  $this->assertEquals("This was a fault", $new_c->problemWith("123"));
119  }

Field Documentation

◆ $c

HasMaxLengthConstraintTest::$c
private

Definition at line 30 of file HasMaxLengthConstraintTest.php.

◆ $df

HasMaxLengthConstraintTest::$df
private

Definition at line 15 of file HasMaxLengthConstraintTest.php.

◆ $lng

HasMaxLengthConstraintTest::$lng
private

Definition at line 20 of file HasMaxLengthConstraintTest.php.

◆ $max_length

HasMaxLengthConstraintTest::$max_length
private

Definition at line 25 of file HasMaxLengthConstraintTest.php.


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