rdbms: Rename "memCache" to "memStash" in LBFactory
[mediawiki.git] / tests / phpunit / includes / SanitizerValidateEmailTest.php
blob2448513345655553603555264e99c71002a654f7
1 <?php
3 /**
4 * @covers Sanitizer::validateEmail
5 * @todo all test methods in this class should be refactored and...
6 * use a single test method and a single data provider...
7 */
8 class SanitizerValidateEmailTest extends PHPUnit_Framework_TestCase {
10 private function checkEmail( $addr, $expected = true, $msg = '' ) {
11 if ( $msg == '' ) {
12 $msg = "Testing $addr";
15 $this->assertEquals(
16 $expected,
17 Sanitizer::validateEmail( $addr ),
18 $msg
22 private function valid( $addr, $msg = '' ) {
23 $this->checkEmail( $addr, true, $msg );
26 private function invalid( $addr, $msg = '' ) {
27 $this->checkEmail( $addr, false, $msg );
30 public function testEmailWellKnownUserAtHostDotTldAreValid() {
31 $this->valid( 'user@example.com' );
32 $this->valid( 'user@example.museum' );
35 public function testEmailWithUpperCaseCharactersAreValid() {
36 $this->valid( 'USER@example.com' );
37 $this->valid( 'user@EXAMPLE.COM' );
38 $this->valid( 'user@Example.com' );
39 $this->valid( 'USER@eXAMPLE.com' );
42 public function testEmailWithAPlusInUserName() {
43 $this->valid( 'user+sub@example.com' );
44 $this->valid( 'user+@example.com' );
47 public function testEmailDoesNotNeedATopLevelDomain() {
48 $this->valid( "user@localhost" );
49 $this->valid( "FooBar@localdomain" );
50 $this->valid( "nobody@mycompany" );
53 public function testEmailWithWhiteSpacesBeforeOrAfterAreInvalids() {
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" );
60 public function testEmailWithWhiteSpacesAreInvalids() {
61 $this->invalid( "User user@host" );
62 $this->invalid( "first last@mycompany" );
63 $this->invalid( "firstlast@my company" );
66 /**
67 * T28948 : comma were matched by an incorrect regexp range
69 public function testEmailWithCommasAreInvalids() {
70 $this->invalid( "user,foo@example.org" );
71 $this->invalid( "userfoo@ex,ample.org" );
74 public function testEmailWithHyphens() {
75 $this->valid( "user-foo@example.org" );
76 $this->valid( "userfoo@ex-ample.org" );
79 public function testEmailDomainCanNotBeginWithDot() {
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............" );
88 public function testEmailWithFunnyCharacters() {
89 $this->valid( "\$user!ex{this}@123.com" );
92 public function testEmailTopLevelDomainCanBeNumerical() {
93 $this->valid( "user@example.1234" );
96 public function testEmailWithoutAtSignIsInvalid() {
97 $this->invalid( 'useràexample.com' );
100 public function testEmailWithOneCharacterDomainIsValid() {
101 $this->valid( 'user@a' );