diff options
author | Chad Horohoe <demon@users.mediawiki.org> | 2010-12-14 16:26:35 +0000 |
---|---|---|
committer | Chad Horohoe <demon@users.mediawiki.org> | 2010-12-14 16:26:35 +0000 |
commit | 23f69f10ed07c7fbe7d752882a88d55351ce2e3d (patch) | |
tree | 43054aea852645def63951fcbf45eb2cf2551adb /tests/phpunit/includes/UserIsValidEmailAddrTest.php | |
parent | 5903e492a5c60f65182d6339f63693aa2dca92f0 (diff) | |
download | mediawikicore-23f69f10ed07c7fbe7d752882a88d55351ce2e3d.tar.gz mediawikicore-23f69f10ed07c7fbe7d752882a88d55351ce2e3d.zip |
Per wikitech-l discussion: Move tests from maintenance/tests/ to tests/. They're not strictly maintenance scripts, and some people want to do a selective checkout that doesn't include the tests. There's still debate on whether we should include these in the release downloads, but we had a pretty firm consensus to move this.
Notes
Notes:
http://mediawiki.org/wiki/Special:Code/MediaWiki/78383
Diffstat (limited to 'tests/phpunit/includes/UserIsValidEmailAddrTest.php')
-rw-r--r-- | tests/phpunit/includes/UserIsValidEmailAddrTest.php | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/phpunit/includes/UserIsValidEmailAddrTest.php b/tests/phpunit/includes/UserIsValidEmailAddrTest.php new file mode 100644 index 000000000000..c1f34193ed91 --- /dev/null +++ b/tests/phpunit/includes/UserIsValidEmailAddrTest.php @@ -0,0 +1,64 @@ +<?php + +class UserIsValidEmailAddrTest extends PHPUnit_Framework_TestCase { + + private function checkEmail( $addr, $expected = true, $msg = '') { + $this->assertEquals( + $expected, + User::isValidEmailAddr( $addr ), + $msg + ); + } + private function valid( $addr, $msg = '' ) { + $this->checkEmail( $addr, true, $msg ); + } + private function invalid( $addr, $msg = '' ) { + $this->checkEmail( $addr, false, $msg ); + } + + function testEmailWellKnownUserAtHostDotTldAreValid() { + $this->valid( 'user@example.com' ); + $this->valid( 'user@example.museum' ); + } + function testEmailWithUpperCaseCharactersAreValid() { + $this->valid( 'USER@example.com' ); + $this->valid( 'user@EXAMPLE.COM' ); + $this->valid( 'user@Example.com' ); + $this->valid( 'USER@eXAMPLE.com' ); + } + function testEmailWithAPlusInUserName() { + $this->valid( 'user+sub@example.com' ); + $this->valid( 'user+@example.com' ); + } + function testEmailWithWhiteSpacesBeforeOrAfterAreInvalids() { + $this->invalid( " user@host" ); + $this->invalid( "user@host " ); + $this->invalid( "\tuser@host" ); + $this->invalid( "user@host\t" ); + } + function testEmailWithWhiteSpacesAreInvalids() { + $this->invalid( "User user@host" ); + $this->invalid( "first last@mycompany" ); + $this->invalid( "firstlast@my company" ); + } + function testEmailDomainCanNotBeginWithDot() { + $this->invalid( "user@." ); + $this->invalid( "user@.localdomain" ); + $this->invalid( "user@localdomain." ); + $this->invalid( "user.@localdomain" ); + $this->invalid( ".@localdomain" ); + $this->invalid( ".@a............" ); + } + function testEmailWithFunnyCharacters() { + $this->valid( "\$user!ex{this}@123.com" ); + } + function testEmailTopLevelDomainCanBeNumerical() { + $this->valid( "user@example.1234" ); + } + function testEmailWithoutAtSignIsInvalid() { + $this->invalid( 'userà example.com' ); + } + function testEmailWithOneCharacterDomainIsInvalid() { + $this->invalid( 'user@a' ); + } +} |