diff options
author | Dries Buytaert <dries@buytaert.net> | 2008-06-26 19:47:02 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2008-06-26 19:47:02 +0000 |
commit | 2877c1027a05ab516439f4917cfc25c84b2bef10 (patch) | |
tree | 983785bdfd8545bfc31c70ed147a82eb2dd59cc2 | |
parent | d7c32183e562eb8d1719da03869a0a1eb30227e8 (diff) | |
download | brdo-2877c1027a05ab516439f4917cfc25c84b2bef10.tar.gz brdo-2877c1027a05ab516439f4917cfc25c84b2bef10.tar.bz2 |
- Patch #266488 by Damien Tournoud, nbz, Heine, MadHarold, et al: clean-up user_validate_name(), allow astrophes, removed some cruft and made the tests more compact.
-rw-r--r-- | modules/user/user.test | 75 |
1 files changed, 36 insertions, 39 deletions
diff --git a/modules/user/user.test b/modules/user/user.test index 2272a17d7..784735fa8 100644 --- a/modules/user/user.test +++ b/modules/user/user.test @@ -116,47 +116,44 @@ class UserValidationTestCase extends DrupalWebTestCase { } // Username validation. - function testMinLengthName() { - $name = ''; - $result = user_validate_name($name); - $this->assertNotNull($result, 'Excessively short username'); - } - - function testValidCharsName() { - $name = 'ab/'; - $result = user_validate_name($name); - $this->assertNotNull($result, 'Invalid chars in username'); - } - - function testMaxLengthName() { - $name = str_repeat('a', 61); - $result = user_validate_name($name); - $this->assertNotNull($result, 'Excessively long username'); - } - - function testValidName() { - $name = 'abc'; - $result = user_validate_name($name); - $this->assertNull($result, 'Valid username'); - } - - // Mail validation. - function testMinLengthMail() { - $name = ''; - $result = user_validate_mail($name); - $this->assertNotNull($result, 'Empty mail'); - } - - function testInValidMail() { - $name = 'abc'; - $result = user_validate_mail($name); - $this->assertNotNull($result, 'Invalid mail'); + function testUsernames() { + $test_cases = array( // '<username>' => array('<description>', 'assert<testName>'), + 'foo' => array('Valid username', 'assertNull'), + 'FOO' => array('Valid username', 'assertNull'), + 'Foo O\'Bar' => array('Valid username', 'assertNull'), + 'foo@bar' => array('Valid username', 'assertNull'), + 'foo@example.com' => array('Valid username', 'assertNull'), + 'foo@-example.com' => array('Valid username', 'assertNull'), // invalid domains are allowed in usernames + 'þòøÇߪř€' => array('Valid username', 'assertNull'), + 'ᚠᛇᚻ᛫ᛒᛦᚦ' => array('Valid UTF8 username', 'assertNull'), // runes + ' foo' => array('Username that starts with a space', 'assertNotNull'), + 'foo ' => array('Username that ends with a space', 'assertNotNull'), + 'foo bar' => array('Username that contains 2 spaces \' \'', 'assertNotNull'), + '' => array('Empty username', 'assertNotNull'), + 'foo/' => array('Invalid chars in username', 'assertNotNull'), + 'foo' . chr(0) . 'bar' => array('chr(0) in username', 'assertNotNull'), // NULL + 'foo' . chr(13) . 'bar' => array('chr(13) in username', 'assertNotNull'), // CR + str_repeat('x', USERNAME_MAX_LENGTH + 1) => array('Excessively long username', 'assertNotNull'), + ); + foreach ($test_cases as $name => $test_case) { + list($description, $test) = $test_case; + $result = user_validate_name($name); + $this->$test($result, $description . ' ('. $name . '). %s'); + } } - function testValidMail() { - $name = 'absdsdsdc@dsdsde.com'; - $result = user_validate_mail($name); - $this->assertNull($result, 'Valid mail'); + // Mail validation. More extensive tests can be found at common.test + function testMailAddresses() { + $test_cases = array( // '<username>' => array('<description>', 'assert<testName>'), + '' => array('Empty mail address', 'assertNotNull'), + 'foo' => array('Invalid mail address', 'assertNotNull'), + 'foo@example.com' => array('Valid mail address', 'assertNull'), + ); + foreach ($test_cases as $name => $test_case) { + list($description, $test) = $test_case; + $result = user_validate_mail($name); + $this->$test($result, $description . ' (' . $name . '). %s'); + } } } |