function UserNameValidatorTest::invalidUserNameProvider

Same name in other branches
  1. 11.x core/modules/user/tests/src/Kernel/UserNameValidatorTest.php \Drupal\Tests\user\Kernel\UserNameValidatorTest::invalidUserNameProvider()

Provides invalid user names.

File

core/modules/user/tests/src/Kernel/UserNameValidatorTest.php, line 79

Class

UserNameValidatorTest
Verify that user validity checks behave as designed.

Namespace

Drupal\Tests\user\Kernel

Code

public static function invalidUserNameProvider() : array {
    return [
        'starts with space' => [
            ' foo',
            'The username cannot begin with a space.',
        ],
        'ends with space' => [
            'foo ',
            'The username cannot end with a space.',
        ],
        'contains 2 spaces' => [
            'foo  bar',
            'The username cannot contain multiple spaces in a row.',
        ],
        'empty string' => [
            '',
            'You must enter a username.',
        ],
        'invalid chars' => [
            'foo/',
            'The username contains an illegal character.',
        ],
        // NULL.
'contains chr(0)' => [
            'foo' . chr(0) . 'bar',
            'The username contains an illegal character.',
        ],
        // CR.
'contains chr(13)' => [
            'foo' . chr(13) . 'bar',
            'The username contains an illegal character.',
        ],
        'excessively long' => [
            str_repeat('x', UserInterface::USERNAME_MAX_LENGTH + 1),
            'The username xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx is too long: it must be 60 characters or less.',
        ],
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.