-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValidatorTest.php
123 lines (104 loc) · 4.6 KB
/
ValidatorTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
namespace Ely\TempMailBuster;
class ValidatorTest extends \PHPUnit_Framework_TestCase
{
public function testValidate()
{
$object = new Validator(new Storage());
$this->assertTrue($object->validate('[email protected]'));
$object = new Validator(new Storage());
$object->whitelistMode();
$this->assertFalse($object->validate('[email protected]'));
$object = new Validator(new Storage(['mojang\.com']));
$this->assertFalse($object->validate('[email protected]'));
$this->assertTrue($object->validate('[email protected]'));
$object = new Validator(new Storage(['gmail\.com']));
$object->whitelistMode();
$this->assertFalse($object->validate('[email protected]'));
$this->assertTrue($object->validate('[email protected]'));
$object = new Validator(new Storage(['mojang\.com', 'ely\.by']), new Storage(['ely\.by']));
$this->assertFalse($object->validate('[email protected]'));
$this->assertTrue($object->validate('[email protected]'));
$object = new Validator(new Storage(['gmail\.com', 'mail\.ru']), new Storage(['mail\.ru']));
$object->whitelistMode();
$this->assertTrue($object->validate('[email protected]'));
$this->assertFalse($object->validate('[email protected]'));
}
public function testGetPrimaryStorage()
{
$storage = new Storage(['test']);
$object = new Validator($storage);
$this->assertEquals($storage, $object->getPrimaryStorage());
}
public function testSetPrimaryStorage()
{
$storage = new Storage(['test2']);
$object = new Validator(new Storage(['test1']));
$this->assertEquals($object, $object->setPrimaryStorage($storage));
$this->assertEquals($storage, $object->getPrimaryStorage());
}
public function testGetSecondaryStorage()
{
$object = new Validator(new Storage());
$this->assertNull($object->getSecondaryStorage());
$storage = new Storage(['test']);
$object = new Validator(new Storage(), $storage);
$this->assertEquals($storage, $object->getSecondaryStorage());
}
public function testSetSecondaryStorage()
{
$storage = new Storage(['test2']);
$object = new Validator(new Storage());
$this->assertEquals($object, $object->setSecondaryStorage($storage));
$this->assertEquals($storage, $object->getSecondaryStorage());
$object->setSecondaryStorage(null);
$this->assertNull($object->getSecondaryStorage(), 'Set by null should work');
$object->setSecondaryStorage($storage);
$object->setSecondaryStorage();
$this->assertNull($object->getSecondaryStorage(), 'Set by empty value should work');
}
public function testGetDomain()
{
$object = new Validator(new Storage());
$this->assertEquals('ely.by', $this->callGetDomain($object, '[email protected]'));
$this->assertEquals('ely.by', $this->callGetDomain($object, '@ely.by'));
$this->assertEquals('ely.by', $this->callGetDomain($object, 'ely.by'));
}
public function testIsIsWhitelistMode()
{
$object = new Validator(new Storage());
$this->assertFalse($object->isIsWhitelistMode(), 'Default should be false');
$object->whitelistMode();
$this->assertTrue($object->isIsWhitelistMode());
}
public function testWhitelistMode()
{
$object = new Validator(new Storage());
$this->assertEquals($object, $object->whitelistMode());
$this->assertTrue($object->isIsWhitelistMode(), 'Default value should change mode to whitelist');
$object->whitelistMode(false);
$this->assertFalse($object->isIsWhitelistMode());
$object->whitelistMode(true);
$this->assertTrue($object->isIsWhitelistMode());
}
public function testBuildRegex()
{
$object = new Validator(new Storage());
$this->assertEquals('/^(simple)$/', $this->callBuildRegex($object, ['simple']));
$this->assertEquals('/^(simple|another)$/', $this->callBuildRegex($object, ['simple', 'another']));
}
private function callGetDomain($object, $email)
{
$class = new \ReflectionClass($object);
$method = $class->getMethod('getDomain');
$method->setAccessible(true);
return $method->invokeArgs($object, [$email]);
}
private function callBuildRegex($object, array $list)
{
$class = new \ReflectionClass($object);
$method = $class->getMethod('buildRegex');
$method->setAccessible(true);
return $method->invokeArgs($object, [$list]);
}
}