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
|
<?php
/**
*
* @package testing
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
class phpbb_regex_email_test extends phpbb_test_case
{
protected $regex;
public function setUp()
{
$this->regex = '#^' . get_preg_expression('email') . '$#i';
}
public function positive_match_data()
{
return array(
array('nobody@phpbb.com'),
array('Nobody@sub.phpbb.com'),
array('alice.bob@foo.phpbb.com'),
array('alice-foo@bar.phpbb.com'),
array('alice_foo@bar.phpbb.com'),
array('alice+tag@foo.phpbb.com'),
array('alice&tag@foo.phpbb.com'),
array('alice@phpbb.australia'),
array('alice@phpbb.topZlevelZdomainZnamesZcanZbeZupZtoZsixtyZthreeZcharactersZlong'),
//array('"John Doe"@example.com'),
//array('Alice@[192.168.2.1]'), // IPv4
//array('Bob@[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]'), // IPv6
// http://fightingforalostcause.net/misc/2006/compare-email-regex.php
array('l3tt3rsAndNumb3rs@domain.com'),
array('has-dash@domain.com'),
array('hasApostrophe.o\'leary@domain.org'),
array('uncommonTLD@domain.museum'),
array('uncommonTLD@domain.travel'),
array('uncommonTLD@domain.mobi'),
array('countryCodeTLD@domain.uk'),
array('countryCodeTLD@domain.rw'),
array('numbersInDomain@911.com'),
array('underscore_inLocal@domain.net'),
array('IPInsteadOfDomain@127.0.0.1'),
array('IPAndPort@127.0.0.1:25'),
array('subdomain@sub.domain.com'),
array('local@dash-inDomain.com'),
array('dot.inLocal@foo.com'),
array('a@singleLetterLocal.org'),
array('singleLetterDomain@x.org'),
array('&*=?^+{}\'~@validCharsInLocal.net'),
array('foor@bar.newTLD'),
);
}
public function negative_match_data()
{
return array(
array('foo.example.com'), // @ is missing
array('.foo.example.com'), // . as first character
array('Foo.@example.com'), // . is last in local part
array('foo..123@example.com'), // . doubled
array('a@b@c@example.com'), // @ doubled
array('()[]\;:,<>@example.com'), // invalid characters
array('abc(def@example.com'), // invalid character (
array('abc)def@example.com'), // invalid character )
array('abc[def@example.com'), // invalid character [
array('abc]def@example.com'), // invalid character ]
array('abc\def@example.com'), // invalid character \
array('abc;def@example.com'), // invalid character ;
array('abc:def@example.com'), // invalid character :
array('abc,def@example.com'), // invalid character ,
array('abc<def@example.com'), // invalid character <
array('abc>def@example.com'), // invalid character >
// http://fightingforalostcause.net/misc/2006/compare-email-regex.php
array('missingDomain@.com'),
array('@missingLocal.org'),
array('missingatSign.net'),
array('missingDot@com'),
array('two@@signs.com'),
array('colonButNoPort@127.0.0.1:'),
array(''),
array('someone-else@127.0.0.1.26'),
array('.localStartsWithDot@domain.com'),
array('localEndsWithDot.@domain.com'),
array('two..consecutiveDots@domain.com'),
array('domainStartsWithDash@-domain.com'),
array('domainEndsWithDash@domain-.com'),
array('numbersInTLD@domain.c0m'),
array('missingTLD@domain.'),
array('! "#$%(),/;<>[]`|@invalidCharsInLocal.org'),
array('invalidCharsInDomain@! "#$%(),/;<>_[]`|.org'),
array('local@SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org'),
array('alice@phpbb.topZlevelZdomainZnamesZcanZbeZupZtoZsixtyZthreeZcharactersZlongZ'),
);
}
/**
* @dataProvider positive_match_data
*/
public function test_positive_match($email)
{
$this->assertEquals(1, preg_match($this->regex, $email));
}
/**
* @dataProvider negative_match_data
*/
public function test_negative_match($email)
{
$this->assertEquals(0, preg_match($this->regex, $email));
}
}
|