function UserLoginTest::testPasswordLengthLogin

Same name in other branches
  1. 10 core/modules/user/tests/src/Functional/UserLoginTest.php \Drupal\Tests\user\Functional\UserLoginTest::testPasswordLengthLogin()
  2. 11.x core/modules/user/tests/src/Functional/UserLoginTest.php \Drupal\Tests\user\Functional\UserLoginTest::testPasswordLengthLogin()

Tests log in with a maximum length and a too long password.

File

core/modules/user/tests/src/Functional/UserLoginTest.php, line 178

Class

UserLoginTest
Ensure that login works as expected.

Namespace

Drupal\Tests\user\Functional

Code

public function testPasswordLengthLogin() {
    // Create a new user and authenticate.
    $account = $this->drupalCreateUser([]);
    $current_password = $account->passRaw;
    $this->drupalLogin($account);
    // Use the length specified in
    // \Drupal\Core\Render\Element\Password::getInfo().
    $length = 128;
    $current_password = $this->doPasswordLengthLogin($account, $current_password, $length);
    $this->assertSession()
        ->pageTextNotContains('Password cannot be longer than');
    $this->assertSession()
        ->pageTextContains('Member for');
    $this->doPasswordLengthLogin($account, $current_password, $length + 1);
    $this->assertSession()
        ->pageTextContains('Password cannot be longer than ' . $length . ' characters but is currently ' . ($length + 1) . ' characters long.');
    $this->assertSession()
        ->pageTextNotContains('Member for');
}

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