function UserLoginTest::doPasswordLengthLogin

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

Helper to test log in with a maximum length password.

Parameters

\Drupal\user\UserInterface $account: An object containing the user account.

string $current_password: The current password associated with the user.

int $length: The length of the password.

Return value

string The new password associated with the user.

1 call to UserLoginTest::doPasswordLengthLogin()
UserLoginTest::testPasswordLengthLogin in core/modules/user/tests/src/Functional/UserLoginTest.php
Tests log in with a maximum length and a too long password.

File

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

Class

UserLoginTest
Ensure that login works as expected.

Namespace

Drupal\Tests\user\Functional

Code

public function doPasswordLengthLogin(UserInterface $account, string $current_password, int $length) {
    $new_password = \Drupal::service('password_generator')->generate($length);
    $uid = $account->id();
    $edit = [
        'current_pass' => $current_password,
        'mail' => $account->getEmail(),
        'pass[pass1]' => $new_password,
        'pass[pass2]' => $new_password,
    ];
    // Change the password.
    $this->drupalGet("user/{$uid}/edit");
    $this->submitForm($edit, 'Save');
    $this->assertSession()
        ->pageTextContains('The changes have been saved.');
    $this->drupalLogout();
    // Login with new password.
    $this->drupalGet('user/login');
    $edit = [
        'name' => $account->getAccountName(),
        'pass' => $new_password,
    ];
    $this->submitForm($edit, 'Log in');
    return $new_password;
}

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