Per wikitech-l discussion: Move tests from maintenance/tests/ to tests/. They're...
[lhc/web/wiklou.git] / tests / phpunit / includes / UserIsValidEmailAddrTest.php
1 <?php
2
3 class UserIsValidEmailAddrTest extends PHPUnit_Framework_TestCase {
4
5 private function checkEmail( $addr, $expected = true, $msg = '') {
6 $this->assertEquals(
7 $expected,
8 User::isValidEmailAddr( $addr ),
9 $msg
10 );
11 }
12 private function valid( $addr, $msg = '' ) {
13 $this->checkEmail( $addr, true, $msg );
14 }
15 private function invalid( $addr, $msg = '' ) {
16 $this->checkEmail( $addr, false, $msg );
17 }
18
19 function testEmailWellKnownUserAtHostDotTldAreValid() {
20 $this->valid( 'user@example.com' );
21 $this->valid( 'user@example.museum' );
22 }
23 function testEmailWithUpperCaseCharactersAreValid() {
24 $this->valid( 'USER@example.com' );
25 $this->valid( 'user@EXAMPLE.COM' );
26 $this->valid( 'user@Example.com' );
27 $this->valid( 'USER@eXAMPLE.com' );
28 }
29 function testEmailWithAPlusInUserName() {
30 $this->valid( 'user+sub@example.com' );
31 $this->valid( 'user+@example.com' );
32 }
33 function testEmailWithWhiteSpacesBeforeOrAfterAreInvalids() {
34 $this->invalid( " user@host" );
35 $this->invalid( "user@host " );
36 $this->invalid( "\tuser@host" );
37 $this->invalid( "user@host\t" );
38 }
39 function testEmailWithWhiteSpacesAreInvalids() {
40 $this->invalid( "User user@host" );
41 $this->invalid( "first last@mycompany" );
42 $this->invalid( "firstlast@my company" );
43 }
44 function testEmailDomainCanNotBeginWithDot() {
45 $this->invalid( "user@." );
46 $this->invalid( "user@.localdomain" );
47 $this->invalid( "user@localdomain." );
48 $this->invalid( "user.@localdomain" );
49 $this->invalid( ".@localdomain" );
50 $this->invalid( ".@a............" );
51 }
52 function testEmailWithFunnyCharacters() {
53 $this->valid( "\$user!ex{this}@123.com" );
54 }
55 function testEmailTopLevelDomainCanBeNumerical() {
56 $this->valid( "user@example.1234" );
57 }
58 function testEmailWithoutAtSignIsInvalid() {
59 $this->invalid( 'useràexample.com' );
60 }
61 function testEmailWithOneCharacterDomainIsInvalid() {
62 $this->invalid( 'user@a' );
63 }
64 }