3 class SanitizerValidateEmailTest
extends MediaWikiTestCase
{
5 private function checkEmail( $addr, $expected = true, $msg = '' ) {
7 $msg = "Testing $addr";
12 Sanitizer
::validateEmail( $addr ),
17 private function valid( $addr, $msg = '' ) {
18 $this->checkEmail( $addr, true, $msg );
21 private function invalid( $addr, $msg = '' ) {
22 $this->checkEmail( $addr, false, $msg );
25 function testEmailWellKnownUserAtHostDotTldAreValid() {
26 $this->valid( 'user@example.com' );
27 $this->valid( 'user@example.museum' );
30 function testEmailWithUpperCaseCharactersAreValid() {
31 $this->valid( 'USER@example.com' );
32 $this->valid( 'user@EXAMPLE.COM' );
33 $this->valid( 'user@Example.com' );
34 $this->valid( 'USER@eXAMPLE.com' );
37 function testEmailWithAPlusInUserName() {
38 $this->valid( 'user+sub@example.com' );
39 $this->valid( 'user+@example.com' );
42 function testEmailDoesNotNeedATopLevelDomain() {
43 $this->valid( "user@localhost" );
44 $this->valid( "FooBar@localdomain" );
45 $this->valid( "nobody@mycompany" );
48 function testEmailWithWhiteSpacesBeforeOrAfterAreInvalids() {
49 $this->invalid( " user@host.com" );
50 $this->invalid( "user@host.com " );
51 $this->invalid( "\tuser@host.com" );
52 $this->invalid( "user@host.com\t" );
55 function testEmailWithWhiteSpacesAreInvalids() {
56 $this->invalid( "User user@host" );
57 $this->invalid( "first last@mycompany" );
58 $this->invalid( "firstlast@my company" );
61 // bug 26948 : comma were matched by an incorrect regexp range
62 function testEmailWithCommasAreInvalids() {
63 $this->invalid( "user,foo@example.org" );
64 $this->invalid( "userfoo@ex,ample.org" );
67 function testEmailWithHyphens() {
68 $this->valid( "user-foo@example.org" );
69 $this->valid( "userfoo@ex-ample.org" );
72 function testEmailDomainCanNotBeginWithDot() {
73 $this->invalid( "user@." );
74 $this->invalid( "user@.localdomain" );
75 $this->invalid( "user@localdomain." );
76 $this->valid( "user.@localdomain" );
77 $this->valid( ".@localdomain" );
78 $this->invalid( ".@a............" );
81 function testEmailWithFunnyCharacters() {
82 $this->valid( "\$user!ex{this}@123.com" );
85 function testEmailTopLevelDomainCanBeNumerical() {
86 $this->valid( "user@example.1234" );
89 function testEmailWithoutAtSignIsInvalid() {
90 $this->invalid( 'userà example.com' );
93 function testEmailWithOneCharacterDomainIsValid() {
94 $this->valid( 'user@a' );