MediaWiki  1.30.0
SanitizerValidateEmailTest.php
Go to the documentation of this file.
1 <?php
2 
8 class SanitizerValidateEmailTest extends PHPUnit_Framework_TestCase {
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
SanitizerValidateEmailTest\testEmailWithWhiteSpacesAreInvalids
testEmailWithWhiteSpacesAreInvalids()
Definition: SanitizerValidateEmailTest.php:60
SanitizerValidateEmailTest\testEmailWithWhiteSpacesBeforeOrAfterAreInvalids
testEmailWithWhiteSpacesBeforeOrAfterAreInvalids()
Definition: SanitizerValidateEmailTest.php:53
SanitizerValidateEmailTest\testEmailWithOneCharacterDomainIsValid
testEmailWithOneCharacterDomainIsValid()
Definition: SanitizerValidateEmailTest.php:100
SanitizerValidateEmailTest\testEmailWellKnownUserAtHostDotTldAreValid
testEmailWellKnownUserAtHostDotTldAreValid()
Definition: SanitizerValidateEmailTest.php:30
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
SanitizerValidateEmailTest\testEmailDomainCanNotBeginWithDot
testEmailDomainCanNotBeginWithDot()
Definition: SanitizerValidateEmailTest.php:79
SanitizerValidateEmailTest
Sanitizer::validateEmail.
Definition: SanitizerValidateEmailTest.php:8
SanitizerValidateEmailTest\valid
valid( $addr, $msg='')
Definition: SanitizerValidateEmailTest.php:22
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()
T28948 : comma were matched by an incorrect regexp range.
Definition: SanitizerValidateEmailTest.php:69
SanitizerValidateEmailTest\testEmailDoesNotNeedATopLevelDomain
testEmailDoesNotNeedATopLevelDomain()
Definition: SanitizerValidateEmailTest.php:47