Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
4.29% |
3 / 70 |
|
60.00% |
3 / 5 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_regex_email_test | |
4.29% |
3 / 70 |
|
60.00% |
3 / 5 |
26.92 | |
0.00% |
0 / 1 |
| setUp | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| positive_match_data | |
0.00% |
0 / 30 |
|
0.00% |
0 / 1 |
2 | |||
| negative_match_data | |
0.00% |
0 / 37 |
|
0.00% |
0 / 1 |
2 | |||
| test_positive_match | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_negative_match | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | class phpbb_regex_email_test extends phpbb_test_case |
| 15 | { |
| 16 | protected $regex; |
| 17 | |
| 18 | protected function setUp(): void |
| 19 | { |
| 20 | $this->regex = '#^' . get_preg_expression('email') . '$#i'; |
| 21 | } |
| 22 | |
| 23 | public static function positive_match_data() |
| 24 | { |
| 25 | return array( |
| 26 | array('nobody@phpbb.com'), |
| 27 | array('Nobody@sub.phpbb.com'), |
| 28 | array('alice.bob@foo.phpbb.com'), |
| 29 | array('alice-foo@bar.phpbb.com'), |
| 30 | array('alice_foo@bar.phpbb.com'), |
| 31 | array('alice+tag@foo.phpbb.com'), |
| 32 | array('alice&tag@foo.phpbb.com'), |
| 33 | array('alice@phpbb.australia'), |
| 34 | array('alice@phpbb.topZlevelZdomainZnamesZcanZbeZupZtoZsixtyZthreeZcharactersZlong'), |
| 35 | |
| 36 | //array('"John Doe"@example.com'), |
| 37 | //array('Alice@[192.168.2.1]'), // IPv4 |
| 38 | //array('Bob@[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]'), // IPv6 |
| 39 | |
| 40 | // http://fightingforalostcause.net/misc/2006/compare-email-regex.php |
| 41 | array('l3tt3rsAndNumb3rs@domain.com'), |
| 42 | array('has-dash@domain.com'), |
| 43 | array('hasApostrophe.o\'leary@domain.org'), |
| 44 | array('uncommonTLD@domain.museum'), |
| 45 | array('uncommonTLD@domain.travel'), |
| 46 | array('uncommonTLD@domain.mobi'), |
| 47 | array('countryCodeTLD@domain.uk'), |
| 48 | array('countryCodeTLD@domain.rw'), |
| 49 | array('numbersInDomain@911.com'), |
| 50 | array('underscore_inLocal@domain.net'), |
| 51 | array('IPInsteadOfDomain@127.0.0.1'), |
| 52 | array('IPAndPort@127.0.0.1:25'), |
| 53 | array('subdomain@sub.domain.com'), |
| 54 | array('local@dash-inDomain.com'), |
| 55 | array('dot.inLocal@foo.com'), |
| 56 | array('a@singleLetterLocal.org'), |
| 57 | array('singleLetterDomain@x.org'), |
| 58 | array('&*=?^+{}\'~@validCharsInLocal.net'), |
| 59 | array('foor@bar.newTLD'), |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | public static function negative_match_data() |
| 64 | { |
| 65 | return array( |
| 66 | array('foo.example.com'), // @ is missing |
| 67 | array('.foo.example.com'), // . as first character |
| 68 | array('Foo.@example.com'), // . is last in local part |
| 69 | array('foo..123@example.com'), // . doubled |
| 70 | array('a@b@c@example.com'), // @ doubled |
| 71 | |
| 72 | array('()[]\;:,<>@example.com'), // invalid characters |
| 73 | array('abc(def@example.com'), // invalid character ( |
| 74 | array('abc)def@example.com'), // invalid character ) |
| 75 | array('abc[def@example.com'), // invalid character [ |
| 76 | array('abc]def@example.com'), // invalid character ] |
| 77 | array('abc\def@example.com'), // invalid character \ |
| 78 | array('abc;def@example.com'), // invalid character ; |
| 79 | array('abc:def@example.com'), // invalid character : |
| 80 | array('abc,def@example.com'), // invalid character , |
| 81 | array('abc<def@example.com'), // invalid character < |
| 82 | array('abc>def@example.com'), // invalid character > |
| 83 | |
| 84 | // http://fightingforalostcause.net/misc/2006/compare-email-regex.php |
| 85 | array('missingDomain@.com'), |
| 86 | array('@missingLocal.org'), |
| 87 | array('missingatSign.net'), |
| 88 | array('missingDot@com'), |
| 89 | array('two@@signs.com'), |
| 90 | array('colonButNoPort@127.0.0.1:'), |
| 91 | array(''), |
| 92 | array('someone-else@127.0.0.1.26'), |
| 93 | array('.localStartsWithDot@domain.com'), |
| 94 | array('localEndsWithDot.@domain.com'), |
| 95 | array('two..consecutiveDots@domain.com'), |
| 96 | array('domainStartsWithDash@-domain.com'), |
| 97 | array('domainEndsWithDash@domain-.com'), |
| 98 | array('numbersInTLD@domain.c0m'), |
| 99 | array('missingTLD@domain.'), |
| 100 | array('! "#$%(),/;<>[]`|@invalidCharsInLocal.org'), |
| 101 | array('invalidCharsInDomain@! "#$%(),/;<>_[]`|.org'), |
| 102 | array('local@SecondLevelDomainNamesAreInvalidIfTheyAreLongerThan64Charactersss.org'), |
| 103 | array('alice@phpbb.topZlevelZdomainZnamesZcanZbeZupZtoZsixtyZthreeZcharactersZlongZ'), |
| 104 | ); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * @dataProvider positive_match_data |
| 109 | */ |
| 110 | public function test_positive_match($email) |
| 111 | { |
| 112 | $this->assertEquals(1, preg_match($this->regex, $email)); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * @dataProvider negative_match_data |
| 117 | */ |
| 118 | public function test_negative_match($email) |
| 119 | { |
| 120 | $this->assertEquals(0, preg_match($this->regex, $email)); |
| 121 | } |
| 122 | } |
| 123 |