MediaWiki  1.23.2
SanitizerValidateEmailTest.php
Go to the documentation of this file.
1 <?php
2 
9 
10  private function checkEmail( $addr, $expected = true, $msg = '' ) {
11  if ( $msg == '' ) {
12  $msg = "Testing $addr";
13  }
14 
15  $this->assertEquals(
16  $expected,
17  Sanitizer::validateEmail( $addr ),
18  $msg
19  );
20  }
21 
22  private function valid( $addr, $msg = '' ) {
23  $this->checkEmail( $addr, true, $msg );
24  }
25 
26  private function invalid( $addr, $msg = '' ) {
27  $this->checkEmail( $addr, false, $msg );
28  }
29 
31  $this->valid( 'user@example.com' );
32  $this->valid( 'user@example.museum' );
33  }
34 
36  $this->valid( 'USER@example.com' );
37  $this->valid( 'user@EXAMPLE.COM' );
38  $this->valid( 'user@Example.com' );
39  $this->valid( 'USER@eXAMPLE.com' );
40  }
41 
42  public function testEmailWithAPlusInUserName() {
43  $this->valid( 'user+sub@example.com' );
44  $this->valid( 'user+@example.com' );
45  }
46 
48  $this->valid( "user@localhost" );
49  $this->valid( "FooBar@localdomain" );
50  $this->valid( "nobody@mycompany" );
51  }
52 
54  $this->invalid( " user@host.com" );
55  $this->invalid( "user@host.com " );
56  $this->invalid( "\tuser@host.com" );
57  $this->invalid( "user@host.com\t" );
58  }
59 
61  $this->invalid( "User user@host" );
62  $this->invalid( "first last@mycompany" );
63  $this->invalid( "firstlast@my company" );
64  }
65 
69  public function testEmailWithCommasAreInvalids() {
70  $this->invalid( "user,foo@example.org" );
71  $this->invalid( "userfoo@ex,ample.org" );
72  }
73 
74  public function testEmailWithHyphens() {
75  $this->valid( "user-foo@example.org" );
76  $this->valid( "userfoo@ex-ample.org" );
77  }
78 
80  $this->invalid( "user@." );
81  $this->invalid( "user@.localdomain" );
82  $this->invalid( "user@localdomain." );
83  $this->valid( "user.@localdomain" );
84  $this->valid( ".@localdomain" );
85  $this->invalid( ".@a............" );
86  }
87 
88  public function testEmailWithFunnyCharacters() {
89  $this->valid( "\$user!ex{this}@123.com" );
90  }
91 
93  $this->valid( "user@example.1234" );
94  }
95 
96  public function testEmailWithoutAtSignIsInvalid() {
97  $this->invalid( 'useràexample.com' );
98  }
99 
101  $this->valid( 'user@a' );
102  }
103 }
SanitizerValidateEmailTest\invalid
invalid( $addr, $msg='')
Definition: SanitizerValidateEmailTest.php:26
SanitizerValidateEmailTest\testEmailTopLevelDomainCanBeNumerical
testEmailTopLevelDomainCanBeNumerical()
Definition: SanitizerValidateEmailTest.php:92
SanitizerValidateEmailTest\checkEmail
checkEmail( $addr, $expected=true, $msg='')
Definition: SanitizerValidateEmailTest.php:10
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
SanitizerValidateEmailTest\testEmailWithWhiteSpacesAreInvalids
testEmailWithWhiteSpacesAreInvalids()
Definition: SanitizerValidateEmailTest.php:60
SanitizerValidateEmailTest\testEmailWithWhiteSpacesBeforeOrAfterAreInvalids
testEmailWithWhiteSpacesBeforeOrAfterAreInvalids()
Definition: SanitizerValidateEmailTest.php:53
SanitizerValidateEmailTest\testEmailWithOneCharacterDomainIsValid
testEmailWithOneCharacterDomainIsValid()
Definition: SanitizerValidateEmailTest.php:100
Sanitizer\validateEmail
static validateEmail( $addr)
Does a string look like an e-mail address?
Definition: Sanitizer.php:1830
SanitizerValidateEmailTest\testEmailWellKnownUserAtHostDotTldAreValid
testEmailWellKnownUserAtHostDotTldAreValid()
Definition: SanitizerValidateEmailTest.php:30
SanitizerValidateEmailTest\testEmailDomainCanNotBeginWithDot
testEmailDomainCanNotBeginWithDot()
Definition: SanitizerValidateEmailTest.php:79
SanitizerValidateEmailTest
@covers Sanitizer::validateEmail @TODO all test methods in this class should be refactored and....
Definition: SanitizerValidateEmailTest.php:8
SanitizerValidateEmailTest\valid
valid( $addr, $msg='')
Definition: SanitizerValidateEmailTest.php:22
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
SanitizerValidateEmailTest\testEmailWithUpperCaseCharactersAreValid
testEmailWithUpperCaseCharactersAreValid()
Definition: SanitizerValidateEmailTest.php:35
SanitizerValidateEmailTest\testEmailWithFunnyCharacters
testEmailWithFunnyCharacters()
Definition: SanitizerValidateEmailTest.php:88
SanitizerValidateEmailTest\testEmailWithHyphens
testEmailWithHyphens()
Definition: SanitizerValidateEmailTest.php:74
SanitizerValidateEmailTest\testEmailWithAPlusInUserName
testEmailWithAPlusInUserName()
Definition: SanitizerValidateEmailTest.php:42
SanitizerValidateEmailTest\testEmailWithoutAtSignIsInvalid
testEmailWithoutAtSignIsInvalid()
Definition: SanitizerValidateEmailTest.php:96
SanitizerValidateEmailTest\testEmailWithCommasAreInvalids
testEmailWithCommasAreInvalids()
bug 26948 : comma were matched by an incorrect regexp range
Definition: SanitizerValidateEmailTest.php:69
SanitizerValidateEmailTest\testEmailDoesNotNeedATopLevelDomain
testEmailDoesNotNeedATopLevelDomain()
Definition: SanitizerValidateEmailTest.php:47