Index: trunk/phase3/tests/phpunit/includes/UserIsValidEmailAddrTest.php |
— | — | @@ -1,79 +0,0 @@ |
2 | | -<?php |
3 | | - |
4 | | -class UserIsValidEmailAddrTest extends MediaWikiTestCase { |
5 | | - |
6 | | - private function checkEmail( $addr, $expected = true, $msg = '') { |
7 | | - if( $msg == '' ) { $msg = "Testing $addr"; } |
8 | | - $this->assertEquals( |
9 | | - $expected, |
10 | | - User::isValidEmailAddr( $addr ), |
11 | | - $msg |
12 | | - ); |
13 | | - } |
14 | | - private function valid( $addr, $msg = '' ) { |
15 | | - $this->checkEmail( $addr, true, $msg ); |
16 | | - } |
17 | | - private function invalid( $addr, $msg = '' ) { |
18 | | - $this->checkEmail( $addr, false, $msg ); |
19 | | - } |
20 | | - |
21 | | - function testEmailWellKnownUserAtHostDotTldAreValid() { |
22 | | - $this->valid( 'user@example.com' ); |
23 | | - $this->valid( 'user@example.museum' ); |
24 | | - } |
25 | | - function testEmailWithUpperCaseCharactersAreValid() { |
26 | | - $this->valid( 'USER@example.com' ); |
27 | | - $this->valid( 'user@EXAMPLE.COM' ); |
28 | | - $this->valid( 'user@Example.com' ); |
29 | | - $this->valid( 'USER@eXAMPLE.com' ); |
30 | | - } |
31 | | - function testEmailWithAPlusInUserName() { |
32 | | - $this->valid( 'user+sub@example.com' ); |
33 | | - $this->valid( 'user+@example.com' ); |
34 | | - } |
35 | | - function testEmailDoesNotNeedATopLevelDomain() { |
36 | | - $this->valid( "user@localhost" ); |
37 | | - $this->valid( "FooBar@localdomain" ); |
38 | | - $this->valid( "nobody@mycompany" ); |
39 | | - } |
40 | | - function testEmailWithWhiteSpacesBeforeOrAfterAreInvalids() { |
41 | | - $this->invalid( " user@host.com" ); |
42 | | - $this->invalid( "user@host.com " ); |
43 | | - $this->invalid( "\tuser@host.com" ); |
44 | | - $this->invalid( "user@host.com\t" ); |
45 | | - } |
46 | | - function testEmailWithWhiteSpacesAreInvalids() { |
47 | | - $this->invalid( "User user@host" ); |
48 | | - $this->invalid( "first last@mycompany" ); |
49 | | - $this->invalid( "firstlast@my company" ); |
50 | | - } |
51 | | - // bug 26948 : comma were matched by an incorrect regexp range |
52 | | - function testEmailWithCommasAreInvalids() { |
53 | | - $this->invalid( "user,foo@example.org" ); |
54 | | - $this->invalid( "userfoo@ex,ample.org" ); |
55 | | - } |
56 | | - function testEmailWithHyphens() { |
57 | | - $this->valid( "user-foo@example.org" ); |
58 | | - $this->valid( "userfoo@ex-ample.org" ); |
59 | | - } |
60 | | - function testEmailDomainCanNotBeginWithDot() { |
61 | | - $this->invalid( "user@." ); |
62 | | - $this->invalid( "user@.localdomain" ); |
63 | | - $this->invalid( "user@localdomain." ); |
64 | | - $this->valid( "user.@localdomain" ); |
65 | | - $this->valid( ".@localdomain" ); |
66 | | - $this->invalid( ".@a............" ); |
67 | | - } |
68 | | - function testEmailWithFunnyCharacters() { |
69 | | - $this->valid( "\$user!ex{this}@123.com" ); |
70 | | - } |
71 | | - function testEmailTopLevelDomainCanBeNumerical() { |
72 | | - $this->valid( "user@example.1234" ); |
73 | | - } |
74 | | - function testEmailWithoutAtSignIsInvalid() { |
75 | | - $this->invalid( 'useràexample.com' ); |
76 | | - } |
77 | | - function testEmailWithOneCharacterDomainIsValid() { |
78 | | - $this->valid( 'user@a' ); |
79 | | - } |
80 | | -} |
Index: trunk/phase3/tests/phpunit/includes/SanitizerValidateEmailTest.php |
— | — | @@ -0,0 +1,79 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class SanitizerValidateEmailTest extends MediaWikiTestCase { |
| 5 | + |
| 6 | + private function checkEmail( $addr, $expected = true, $msg = '') { |
| 7 | + if( $msg == '' ) { $msg = "Testing $addr"; } |
| 8 | + $this->assertEquals( |
| 9 | + $expected, |
| 10 | + Sanitizer::validateEmail( $addr ), |
| 11 | + $msg |
| 12 | + ); |
| 13 | + } |
| 14 | + private function valid( $addr, $msg = '' ) { |
| 15 | + $this->checkEmail( $addr, true, $msg ); |
| 16 | + } |
| 17 | + private function invalid( $addr, $msg = '' ) { |
| 18 | + $this->checkEmail( $addr, false, $msg ); |
| 19 | + } |
| 20 | + |
| 21 | + function testEmailWellKnownUserAtHostDotTldAreValid() { |
| 22 | + $this->valid( 'user@example.com' ); |
| 23 | + $this->valid( 'user@example.museum' ); |
| 24 | + } |
| 25 | + function testEmailWithUpperCaseCharactersAreValid() { |
| 26 | + $this->valid( 'USER@example.com' ); |
| 27 | + $this->valid( 'user@EXAMPLE.COM' ); |
| 28 | + $this->valid( 'user@Example.com' ); |
| 29 | + $this->valid( 'USER@eXAMPLE.com' ); |
| 30 | + } |
| 31 | + function testEmailWithAPlusInUserName() { |
| 32 | + $this->valid( 'user+sub@example.com' ); |
| 33 | + $this->valid( 'user+@example.com' ); |
| 34 | + } |
| 35 | + function testEmailDoesNotNeedATopLevelDomain() { |
| 36 | + $this->valid( "user@localhost" ); |
| 37 | + $this->valid( "FooBar@localdomain" ); |
| 38 | + $this->valid( "nobody@mycompany" ); |
| 39 | + } |
| 40 | + function testEmailWithWhiteSpacesBeforeOrAfterAreInvalids() { |
| 41 | + $this->invalid( " user@host.com" ); |
| 42 | + $this->invalid( "user@host.com " ); |
| 43 | + $this->invalid( "\tuser@host.com" ); |
| 44 | + $this->invalid( "user@host.com\t" ); |
| 45 | + } |
| 46 | + function testEmailWithWhiteSpacesAreInvalids() { |
| 47 | + $this->invalid( "User user@host" ); |
| 48 | + $this->invalid( "first last@mycompany" ); |
| 49 | + $this->invalid( "firstlast@my company" ); |
| 50 | + } |
| 51 | + // bug 26948 : comma were matched by an incorrect regexp range |
| 52 | + function testEmailWithCommasAreInvalids() { |
| 53 | + $this->invalid( "user,foo@example.org" ); |
| 54 | + $this->invalid( "userfoo@ex,ample.org" ); |
| 55 | + } |
| 56 | + function testEmailWithHyphens() { |
| 57 | + $this->valid( "user-foo@example.org" ); |
| 58 | + $this->valid( "userfoo@ex-ample.org" ); |
| 59 | + } |
| 60 | + function testEmailDomainCanNotBeginWithDot() { |
| 61 | + $this->invalid( "user@." ); |
| 62 | + $this->invalid( "user@.localdomain" ); |
| 63 | + $this->invalid( "user@localdomain." ); |
| 64 | + $this->valid( "user.@localdomain" ); |
| 65 | + $this->valid( ".@localdomain" ); |
| 66 | + $this->invalid( ".@a............" ); |
| 67 | + } |
| 68 | + function testEmailWithFunnyCharacters() { |
| 69 | + $this->valid( "\$user!ex{this}@123.com" ); |
| 70 | + } |
| 71 | + function testEmailTopLevelDomainCanBeNumerical() { |
| 72 | + $this->valid( "user@example.1234" ); |
| 73 | + } |
| 74 | + function testEmailWithoutAtSignIsInvalid() { |
| 75 | + $this->invalid( 'useràexample.com' ); |
| 76 | + } |
| 77 | + function testEmailWithOneCharacterDomainIsValid() { |
| 78 | + $this->valid( 'user@a' ); |
| 79 | + } |
| 80 | +} |
Property changes on: trunk/phase3/tests/phpunit/includes/SanitizerValidateEmailTest.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 81 | + native |