* upgrade patches for oracle 1.17->1.19
[mediawiki.git] / tests / phpunit / includes / UserIsValidEmailAddrTest.php
blob99bf718ee37b4dd6d2ff1f2fabac0b7d8f6990bd
1 <?php
3 class UserIsValidEmailAddrTest extends MediaWikiTestCase {
5 private function checkEmail( $addr, $expected = true, $msg = '') {
6 if( $msg == '' ) { $msg = "Testing $addr"; }
7 $this->assertEquals(
8 $expected,
9 User::isValidEmailAddr( $addr ),
10 $msg
13 private function valid( $addr, $msg = '' ) {
14 $this->checkEmail( $addr, true, $msg );
16 private function invalid( $addr, $msg = '' ) {
17 $this->checkEmail( $addr, false, $msg );
20 function testEmailWellKnownUserAtHostDotTldAreValid() {
21 $this->valid( 'user@example.com' );
22 $this->valid( 'user@example.museum' );
24 function testEmailWithUpperCaseCharactersAreValid() {
25 $this->valid( 'USER@example.com' );
26 $this->valid( 'user@EXAMPLE.COM' );
27 $this->valid( 'user@Example.com' );
28 $this->valid( 'USER@eXAMPLE.com' );
30 function testEmailWithAPlusInUserName() {
31 $this->valid( 'user+sub@example.com' );
32 $this->valid( 'user+@example.com' );
34 function testEmailDoesNotNeedATopLevelDomain() {
35 $this->valid( "user@localhost" );
36 $this->valid( "FooBar@localdomain" );
37 $this->valid( "nobody@mycompany" );
39 function testEmailWithWhiteSpacesBeforeOrAfterAreInvalids() {
40 $this->invalid( " user@host.com" );
41 $this->invalid( "user@host.com " );
42 $this->invalid( "\tuser@host.com" );
43 $this->invalid( "user@host.com\t" );
45 function testEmailWithWhiteSpacesAreInvalids() {
46 $this->invalid( "User user@host" );
47 $this->invalid( "first last@mycompany" );
48 $this->invalid( "firstlast@my company" );
50 // bug 26948 : comma were matched by an incorrect regexp range
51 function testEmailWithCommasAreInvalids() {
52 $this->invalid( "user,foo@example.org" );
53 $this->invalid( "userfoo@ex,ample.org" );
55 function testEmailWithHyphens() {
56 $this->valid( "user-foo@example.org" );
57 $this->valid( "userfoo@ex-ample.org" );
59 function testEmailDomainCanNotBeginWithDot() {
60 $this->invalid( "user@." );
61 $this->invalid( "user@.localdomain" );
62 $this->invalid( "user@localdomain." );
63 $this->valid( "user.@localdomain" );
64 $this->valid( ".@localdomain" );
65 $this->invalid( ".@a............" );
67 function testEmailWithFunnyCharacters() {
68 $this->valid( "\$user!ex{this}@123.com" );
70 function testEmailTopLevelDomainCanBeNumerical() {
71 $this->valid( "user@example.1234" );
73 function testEmailWithoutAtSignIsInvalid() {
74 $this->invalid( 'useràexample.com' );
76 function testEmailWithOneCharacterDomainIsValid() {
77 $this->valid( 'user@a' );