1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace coreTests\Rules; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use CommonTestClass; |
7
|
|
|
use kalanis\kw_table\core\Table\Rules; |
8
|
|
|
use kalanis\kw_table\core\TableException; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class SimpleRuleTest extends CommonTestClass |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @throws TableException |
15
|
|
|
*/ |
16
|
|
|
public function testAlways(): void |
17
|
|
|
{ |
18
|
|
|
$lib = new Rules\Always('name'); |
19
|
|
|
$this->assertTrue($lib->validate('name')); |
20
|
|
|
$this->assertTrue($lib->validate('diff')); |
21
|
|
|
$this->assertTrue($lib->validate('')); |
22
|
|
|
$this->assertTrue($lib->validate(false)); |
23
|
|
|
$this->assertTrue($lib->validate(null)); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @throws TableException |
28
|
|
|
*/ |
29
|
|
|
public function testExact(): void |
30
|
|
|
{ |
31
|
|
|
$lib = new Rules\Exact('name'); |
32
|
|
|
$this->assertTrue($lib->validate('name')); |
33
|
|
|
$this->assertFalse($lib->validate('diff')); |
34
|
|
|
$this->assertFalse($lib->validate('')); |
35
|
|
|
$this->assertFalse($lib->validate(null)); |
36
|
|
|
$this->assertFalse($lib->validate(false)); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @throws TableException |
41
|
|
|
*/ |
42
|
|
|
public function testEmpty(): void |
43
|
|
|
{ |
44
|
|
|
$lib = new Rules\REmpty('name'); |
45
|
|
|
$this->assertFalse($lib->validate('name')); |
46
|
|
|
$this->assertFalse($lib->validate(true)); |
47
|
|
|
$this->assertTrue($lib->validate('')); |
48
|
|
|
$this->assertTrue($lib->validate(null)); |
49
|
|
|
$this->assertTrue($lib->validate(false)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @throws TableException |
54
|
|
|
*/ |
55
|
|
|
public function testNegate(): void |
56
|
|
|
{ |
57
|
|
|
$lib = new Rules\Negate(new Rules\REmpty('name')); |
58
|
|
|
$this->assertTrue($lib->validate('name')); |
59
|
|
|
$this->assertTrue($lib->validate(true)); |
60
|
|
|
$this->assertFalse($lib->validate('')); |
61
|
|
|
$this->assertFalse($lib->validate(null)); |
62
|
|
|
$this->assertFalse($lib->validate(false)); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|