ILIAS
release_5-4 Revision v5.4.26-12-gabc799a52e6
◀ ilDoc Overview
IsStringConstraintTest.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
IsStringConstraintTest
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->c = $this->f->isString();
18
}
19
20
public
function
testAccepts
()
21
{
22
$this->assertTrue($this->c->accepts(
"string"
));
23
}
24
25
public
function
testNotAccepts
()
26
{
27
$this->assertFalse($this->c->accepts(2));
28
}
29
30
public
function
testCheckSucceed
()
31
{
32
$this->c->check(
"string"
);
33
$this->assertTrue(
true
);
// does not throw
34
}
35
36
public
function
testCheckFails
()
37
{
38
$this->expectException(\UnexpectedValueException::class);
39
$this->c->check(2);
40
}
41
42
public
function
testNoProblemWith
()
43
{
44
$this->assertNull($this->c->problemWith(
"string"
));
45
}
46
47
public
function
testProblemWith
()
48
{
49
$this->lng
50
->expects($this->
once
())
51
->method(
"txt"
)
52
->with(
"not_a_string"
)
53
->willReturn(
"-%s-"
);
54
55
$this->assertEquals(
"-double-"
, $this->c->problemWith(2.2));
56
}
57
58
public
function
testRestrictOk
()
59
{
60
$ok
= $this->df->ok(
"string"
);
61
62
$res
= $this->c->restrict(
$ok
);
63
$this->assertTrue(
$res
->isOk());
64
}
65
66
public
function
testRestrictNotOk
()
67
{
68
$not_ok = $this->df->ok(2);
69
70
$res
= $this->c->restrict($not_ok);
71
$this->assertFalse(
$res
->isOk());
72
}
73
74
public
function
testRestrictError
()
75
{
76
$error = $this->df->error(
"error"
);
77
78
$res
= $this->c->restrict($error);
79
$this->assertSame($error,
$res
);
80
}
81
82
public
function
testWithProblemBuilder
()
83
{
84
$new_c = $this->c->withProblemBuilder(
function
() {
85
return
"This was a fault"
;
86
});
87
$this->assertEquals(
"This was a fault"
, $new_c->problemWith(2.2));
88
}
89
}
IsStringConstraintTest\testCheckSucceed
testCheckSucceed()
Definition:
IsStringConstraintTest.php:30
IsStringConstraintTest\testWithProblemBuilder
testWithProblemBuilder()
Definition:
IsStringConstraintTest.php:82
IsStringConstraintTest\testRestrictOk
testRestrictOk()
Definition:
IsStringConstraintTest.php:58
IsStringConstraintTest\testCheckFails
testCheckFails()
Definition:
IsStringConstraintTest.php:36
ILIAS\Validation
Definition:
Constraint.php:5
PHPUnit_Framework_TestCase
IsStringConstraintTest\testAccepts
testAccepts()
Definition:
IsStringConstraintTest.php:20
$res
foreach($_POST as $key=> $value) $res
Definition:
save_question_post_data.php:15
Sabre\Event\once
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
Definition:
EventEmitterTrait.php:59
IsStringConstraintTest\testRestrictError
testRestrictError()
Definition:
IsStringConstraintTest.php:74
IsStringConstraintTest\testProblemWith
testProblemWith()
Definition:
IsStringConstraintTest.php:47
$ok
$ok
Definition:
UtfNormalTest.php:80
IsStringConstraintTest\testRestrictNotOk
testRestrictNotOk()
Definition:
IsStringConstraintTest.php:66
IsStringConstraintTest
Definition:
IsStringConstraintTest.php:9
IsStringConstraintTest\setUp
setUp()
Definition:
IsStringConstraintTest.php:11
IsStringConstraintTest\testNoProblemWith
testNoProblemWith()
Definition:
IsStringConstraintTest.php:42
php
ILIAS\Data
Definition:
ClientId.php:4
IsStringConstraintTest\testNotAccepts
testNotAccepts()
Definition:
IsStringConstraintTest.php:25
tests
Validation
Constraints
IsStringConstraintTest.php
Generated on Thu Jan 16 2025 19:02:39 for ILIAS by
1.8.13 (using
Doxyfile
)