function UserPasswordResetTest::testUserResetPasswordTextboxFilled

Same name in other branches
  1. 9 core/modules/user/tests/src/Functional/UserPasswordResetTest.php \Drupal\Tests\user\Functional\UserPasswordResetTest::testUserResetPasswordTextboxFilled()

Prefill the text box on incorrect login via link to password reset page.

File

core/modules/user/tests/src/Functional/UserPasswordResetTest.php, line 274

Class

UserPasswordResetTest
Ensure that password reset methods work as expected.

Namespace

Drupal\Tests\user\Functional

Code

public function testUserResetPasswordTextboxFilled() {
    $this->drupalGet('user/login');
    $edit = [
        'name' => $this->randomMachineName(),
        'pass' => $this->randomMachineName(),
    ];
    $this->drupalPostForm('user/login', $edit, t('Log in'));
    $this->assertRaw(t('Unrecognized username or password. <a href=":password">Forgot your password?</a>', [
        ':password' => Url::fromRoute('user.pass', [], [
            'query' => [
                'name' => $edit['name'],
            ],
        ])->toString(),
    ]));
    unset($edit['pass']);
    $this->drupalGet('user/password', [
        'query' => [
            'name' => $edit['name'],
        ],
    ]);
    $this->assertFieldByName('name', $edit['name'], 'User name found.');
    // Ensure the name field value is not cached.
    $this->drupalGet('user/password');
    $this->assertNoFieldByName('name', $edit['name'], 'User name not found.');
}

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