function UserLoginTest::testPasswordLengthLogin

Same name and namespace in other branches
  1. 10 core/modules/user/tests/src/Functional/UserLoginTest.php \Drupal\Tests\user\Functional\UserLoginTest::testPasswordLengthLogin()
  2. 9 core/modules/user/tests/src/Functional/UserLoginTest.php \Drupal\Tests\user\Functional\UserLoginTest::testPasswordLengthLogin()
  3. main 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 197

Class

UserLoginTest
Ensure that login works as expected.

Namespace

Drupal\Tests\user\Functional

Code

public function testPasswordLengthLogin() : void {
  // Create a new user and authenticate.
  $account = $this->drupalCreateUser([]);
  $current_password = $account->passRaw;
  // Add Created field to the user profile display so that there is something
  // to check page contents against.
  EntityViewDisplay::collectRenderDisplay($account, 'default')->setComponent('created', [
    'type' => 'timestamp',
  ])
    ->save();
  $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('Created');
  $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('Created');
}

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