Skip to content
Snippets Groups Projects
Commit 2877c102 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #266488 by Damien Tournoud, nbz, Heine, MadHarold, et al: clean-up...

- 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.
parent d7c32183
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -116,47 +116,44 @@ class UserValidationTestCase extends DrupalWebTestCase { ...@@ -116,47 +116,44 @@ class UserValidationTestCase extends DrupalWebTestCase {
} }
// Username validation. // Username validation.
function testMinLengthName() { function testUsernames() {
$name = ''; $test_cases = array( // '<username>' => array('<description>', 'assert<testName>'),
$result = user_validate_name($name); 'foo' => array('Valid username', 'assertNull'),
$this->assertNotNull($result, 'Excessively short username'); 'FOO' => array('Valid username', 'assertNull'),
} 'Foo O\'Bar' => array('Valid username', 'assertNull'),
'foo@bar' => array('Valid username', 'assertNull'),
function testValidCharsName() { 'foo@example.com' => array('Valid username', 'assertNull'),
$name = 'ab/'; 'foo@-example.com' => array('Valid username', 'assertNull'), // invalid domains are allowed in usernames
$result = user_validate_name($name); 'þòøÇߪř€' => array('Valid username', 'assertNull'),
$this->assertNotNull($result, 'Invalid chars in username'); 'ᚠᛇᚻ᛫ᛒᛦᚦ' => array('Valid UTF8 username', 'assertNull'), // runes
} ' foo' => array('Username that starts with a space', 'assertNotNull'),
'foo ' => array('Username that ends with a space', 'assertNotNull'),
function testMaxLengthName() { 'foo bar' => array('Username that contains 2 spaces \'&nbsp;&nbsp;\'', 'assertNotNull'),
$name = str_repeat('a', 61); '' => array('Empty username', 'assertNotNull'),
$result = user_validate_name($name); 'foo/' => array('Invalid chars in username', 'assertNotNull'),
$this->assertNotNull($result, 'Excessively long username'); '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'),
function testValidName() { );
$name = 'abc'; foreach ($test_cases as $name => $test_case) {
$result = user_validate_name($name); list($description, $test) = $test_case;
$this->assertNull($result, 'Valid username'); $result = user_validate_name($name);
} $this->$test($result, $description . ' ('. $name . '). %s');
}
// 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 testValidMail() { // Mail validation. More extensive tests can be found at common.test
$name = 'absdsdsdc@dsdsde.com'; function testMailAddresses() {
$result = user_validate_mail($name); $test_cases = array( // '<username>' => array('<description>', 'assert<testName>'),
$this->assertNull($result, 'Valid mail'); '' => 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');
}
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment