1 user.test | UserValidationTestCase::testUsernames() |
File
- core/
modules/ user/ tests/ user.test, line 394 - Tests for user.module.
Class
Code
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'),
// Invalid domains are allowed in usernames.
'foo@-example.com' => array('Valid username', 'assertNull'),
// cspell:disable
'þòøÇߪř€' => array('Valid username', 'assertNull'),
// Runes.
'ᚠᛇᚻ᛫ᛒᛦᚦ' => array('Valid UTF8 username', 'assertNull'),
// cspell:enable
// '+' symbol is allowed.
'foo+bar' => array('Valid username', 'assertNull'),
' foo' => array('Invalid username that starts with a space', 'assertNotNull'),
'foo ' => array('Invalid username that ends with a space', 'assertNotNull'),
'foo bar' => array('Invalid username that contains 2 spaces \' \'', 'assertNotNull'),
'' => array('Invalid empty username', 'assertNotNull'),
'foo/' => array('Invalid username containing invalid chars', 'assertNotNull'),
// NULL.
'foo' . chr(0) . 'bar' => array('Invalid username containing chr(0)', 'assertNotNull'),
// CR.
'foo' . chr(13) . 'bar' => array('Invalid username containing chr(13)', 'assertNotNull'),
str_repeat('x', USERNAME_MAX_LENGTH + 1) => array('Invalid 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 . ')');
}
}