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
<?php
namespace yiiunit\framework\validators;
use yii\validators\EmailValidator;
use yiiunit\data\validators\models\FakedValidationModel;
use yiiunit\TestCase;
/**
* EmailValidatorTest
* @group validators
*/
class EmailValidatorTest extends TestCase
{
protected function setUp()
{
parent::setUp();
$this->mockApplication();
}
public function testValidateValue()
{
$validator = new EmailValidator();
$this->assertTrue($validator->validate('sam@rmcreative.ru'));
$this->assertTrue($validator->validate('5011@gmail.com'));
$this->assertFalse($validator->validate('rmcreative.ru'));
$this->assertFalse($validator->validate('Carsten Brandt <mail@cebe.cc>'));
$this->assertFalse($validator->validate('"Carsten Brandt" <mail@cebe.cc>'));
$this->assertFalse($validator->validate('<mail@cebe.cc>'));
$this->assertFalse($validator->validate('info@örtliches.de'));
$this->assertFalse($validator->validate('sam@рмкреатиф.ru'));
$validator->allowName = true;
$this->assertTrue($validator->validate('sam@rmcreative.ru'));
$this->assertTrue($validator->validate('5011@gmail.com'));
$this->assertFalse($validator->validate('rmcreative.ru'));
$this->assertTrue($validator->validate('Carsten Brandt <mail@cebe.cc>'));
$this->assertTrue($validator->validate('"Carsten Brandt" <mail@cebe.cc>'));
$this->assertTrue($validator->validate('<mail@cebe.cc>'));
$this->assertFalse($validator->validate('info@örtliches.de'));
$this->assertFalse($validator->validate('sam@рмкреатиф.ru'));
$this->assertFalse($validator->validate('Informtation info@oertliches.de'));
$this->assertTrue($validator->validate('test@example.com'));
$this->assertTrue($validator->validate('John Smith <john.smith@example.com>'));
$this->assertFalse($validator->validate('John Smith <example.com>'));
}
public function testValidateValueIdn()
{
if (!function_exists('idn_to_ascii')) {
$this->markTestSkipped('Intl extension required');
return;
}
$validator = new EmailValidator();
$validator->enableIDN = true;
$this->assertTrue($validator->validate('5011@example.com'));
$this->assertTrue($validator->validate('example@äüößìà.de'));
$this->assertTrue($validator->validate('example@xn--zcack7ayc9a.de'));
$this->assertTrue($validator->validate('info@örtliches.de'));
$this->assertTrue($validator->validate('sam@рмкреатиф.ru'));
$this->assertTrue($validator->validate('sam@rmcreative.ru'));
$this->assertTrue($validator->validate('5011@gmail.com'));
$this->assertFalse($validator->validate('rmcreative.ru'));
$this->assertFalse($validator->validate('Carsten Brandt <mail@cebe.cc>'));
$this->assertFalse($validator->validate('"Carsten Brandt" <mail@cebe.cc>'));
$this->assertFalse($validator->validate('<mail@cebe.cc>'));
$validator->allowName = true;
$this->assertTrue($validator->validate('info@örtliches.de'));
$this->assertTrue($validator->validate('Informtation <info@örtliches.de>'));
$this->assertFalse($validator->validate('Informtation info@örtliches.de'));
$this->assertTrue($validator->validate('sam@рмкреатиф.ru'));
$this->assertTrue($validator->validate('sam@rmcreative.ru'));
$this->assertTrue($validator->validate('5011@gmail.com'));
$this->assertFalse($validator->validate('rmcreative.ru'));
$this->assertTrue($validator->validate('Carsten Brandt <mail@cebe.cc>'));
$this->assertTrue($validator->validate('"Carsten Brandt" <mail@cebe.cc>'));
$this->assertTrue($validator->validate('<mail@cebe.cc>'));
$this->assertTrue($validator->validate('test@example.com'));
$this->assertTrue($validator->validate('John Smith <john.smith@example.com>'));
$this->assertFalse($validator->validate('John Smith <example.com>'));
}
public function testValidateValueMx()
{
$validator = new EmailValidator();
$validator->checkDNS = true;
$this->assertTrue($validator->validate('5011@gmail.com'));
$validator->checkDNS = false;
$this->assertTrue($validator->validate('test@nonexistingsubdomain.example.com'));
$validator->checkDNS = true;
$this->assertFalse($validator->validate('test@nonexistingsubdomain.example.com'));
}
public function testValidateAttribute()
{
$val = new EmailValidator();
$model = new FakedValidationModel();
$model->attr_email = '5011@gmail.com';
$val->validateAttribute($model, 'attr_email');
$this->assertFalse($model->hasErrors('attr_email'));
}
}