|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use kalanis\kw_rules\Rules; |
|
4
|
|
|
use kalanis\kw_rules\Exceptions\RuleException; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
class PatternRulesTest extends CommonTestClass |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @param string $checkValue |
|
11
|
|
|
* @param bool $isEmail |
|
12
|
|
|
* @param bool $isDomain |
|
13
|
|
|
* @throws RuleException |
|
14
|
|
|
* @dataProvider stringsProvider |
|
15
|
|
|
*/ |
|
16
|
|
|
public function testEmail(string $checkValue, bool $isEmail, bool $isDomain): void |
|
17
|
|
|
{ |
|
18
|
|
|
$data = new Rules\IsEmail(); |
|
19
|
|
|
$data->setAgainstValue(''); |
|
20
|
|
|
$this->assertInstanceOf(Rules\ARule::class, $data); |
|
21
|
|
|
|
|
22
|
|
|
$mock = MockEntry::init('foo', $checkValue); |
|
23
|
|
|
if (!$isEmail) $this->expectException(RuleException::class); |
|
24
|
|
|
$data->validate($mock); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param string $checkValue |
|
29
|
|
|
* @param bool $isEmail |
|
30
|
|
|
* @param bool $isDomain |
|
31
|
|
|
* @throws RuleException |
|
32
|
|
|
* @dataProvider stringsProvider |
|
33
|
|
|
*/ |
|
34
|
|
|
public function testDomain(string $checkValue, bool $isEmail, bool $isDomain): void |
|
35
|
|
|
{ |
|
36
|
|
|
$data = new Rules\IsDomain(); |
|
37
|
|
|
$data->setAgainstValue(''); |
|
38
|
|
|
$this->assertInstanceOf(Rules\ARule::class, $data); |
|
39
|
|
|
|
|
40
|
|
|
$mock = MockEntry::init('foo', $checkValue); |
|
41
|
|
|
if (!$isDomain) $this->expectException(RuleException::class); |
|
42
|
|
|
$data->validate($mock); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function stringsProvider(): array |
|
46
|
|
|
{ |
|
47
|
|
|
return [ |
|
48
|
|
|
['[email protected]', true, false], |
|
49
|
|
|
['[email protected]', true, false], |
|
50
|
|
|
['foo@[email protected]', false, false], |
|
51
|
|
|
['6', false, false], |
|
52
|
|
|
['bar.example', false, true ], |
|
53
|
|
|
['foo.bar.baz.example', false, false], |
|
54
|
|
|
]; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|