ILIAS
release_5-4 Revision v5.4.26-12-gabc799a52e6
◀ ilDoc Overview
HasMinLengthConstraintTest.php
Go to the documentation of this file.
1
<?
php
2
3
/* Copyright (c) 2018 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
require_once(
"libs/composer/vendor/autoload.php"
);
5
6
use
ILIAS\Validation
;
7
use
ILIAS\Data
;
8
9
class
HasMinLengthConstraintTest
extends
PHPUnit_Framework_TestCase
10
{
11
public
function
setUp
()
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->min_length = 10;
18
19
$this->c = $this->f->hasMinLength($this->min_length);
20
}
21
22
public
function
testAccepts1
()
23
{
24
$this->assertTrue($this->c->accepts(
"1234567890"
));
25
}
26
27
public
function
testAccepts2
()
28
{
29
$this->assertTrue($this->c->accepts(
"12345678901"
));
30
}
31
32
public
function
testNotAccepts
()
33
{
34
$this->assertFalse($this->c->accepts(
"123456789"
));
35
}
36
37
public
function
testCheckSucceed
()
38
{
39
$this->c->check(
"1234567890"
);
40
$this->assertTrue(
true
);
// does not throw
41
}
42
43
public
function
testCheckFails
()
44
{
45
$this->expectException(\UnexpectedValueException::class);
46
$this->c->check(
""
);
47
}
48
49
public
function
testNoProblemWith
()
50
{
51
$this->assertNull($this->c->problemWith(
"1234567890"
));
52
}
53
54
public
function
testProblemWith
()
55
{
56
$this->lng
57
->expects($this->
once
())
58
->method(
"txt"
)
59
->with(
"not_min_length"
)
60
->willReturn(
"-%s-%s-"
);
61
62
$this->assertEquals(
"-3-10-"
, $this->c->problemWith(
"123"
));
63
}
64
65
public
function
testRestrictOk
()
66
{
67
$ok
= $this->df->ok(
"1234567890"
);
68
69
$res
= $this->c->restrict(
$ok
);
70
$this->assertTrue(
$res
->isOk());
71
}
72
73
public
function
testRestrictNotOk
()
74
{
75
$not_ok = $this->df->ok(
"1234"
);
76
77
$res
= $this->c->restrict($not_ok);
78
$this->assertFalse(
$res
->isOk());
79
}
80
81
public
function
testRestrictError
()
82
{
83
$error = $this->df->error(
"error"
);
84
85
$res
= $this->c->restrict($error);
86
$this->assertSame($error,
$res
);
87
}
88
89
public
function
testWithProblemBuilder
()
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(
""
));
95
}
96
}
HasMinLengthConstraintTest\testCheckFails
testCheckFails()
Definition:
HasMinLengthConstraintTest.php:43
ILIAS\Validation
Definition:
Constraint.php:5
PHPUnit_Framework_TestCase
HasMinLengthConstraintTest\testCheckSucceed
testCheckSucceed()
Definition:
HasMinLengthConstraintTest.php:37
$res
foreach($_POST as $key=> $value) $res
Definition:
save_question_post_data.php:15
HasMinLengthConstraintTest
Definition:
HasMinLengthConstraintTest.php:9
HasMinLengthConstraintTest\testAccepts1
testAccepts1()
Definition:
HasMinLengthConstraintTest.php:22
HasMinLengthConstraintTest\testWithProblemBuilder
testWithProblemBuilder()
Definition:
HasMinLengthConstraintTest.php:89
Sabre\Event\once
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
Definition:
EventEmitterTrait.php:59
$ok
$ok
Definition:
UtfNormalTest.php:80
HasMinLengthConstraintTest\testProblemWith
testProblemWith()
Definition:
HasMinLengthConstraintTest.php:54
HasMinLengthConstraintTest\testNoProblemWith
testNoProblemWith()
Definition:
HasMinLengthConstraintTest.php:49
php
HasMinLengthConstraintTest\testNotAccepts
testNotAccepts()
Definition:
HasMinLengthConstraintTest.php:32
HasMinLengthConstraintTest\testRestrictError
testRestrictError()
Definition:
HasMinLengthConstraintTest.php:81
HasMinLengthConstraintTest\testRestrictNotOk
testRestrictNotOk()
Definition:
HasMinLengthConstraintTest.php:73
HasMinLengthConstraintTest\testRestrictOk
testRestrictOk()
Definition:
HasMinLengthConstraintTest.php:65
HasMinLengthConstraintTest\setUp
setUp()
Definition:
HasMinLengthConstraintTest.php:11
HasMinLengthConstraintTest\testAccepts2
testAccepts2()
Definition:
HasMinLengthConstraintTest.php:27
ILIAS\Data
Definition:
ClientId.php:4
tests
Validation
Constraints
HasMinLengthConstraintTest.php
Generated on Thu Jan 16 2025 19:02:39 for ILIAS by
1.8.13 (using
Doxyfile
)