function UserPasswordResetTest::testUserResetPasswordTextboxNotFilled

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

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

File

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

Class

UserPasswordResetTest
Ensure that password reset methods work as expected.

Namespace

Drupal\Tests\user\Functional

Code

public function testUserResetPasswordTextboxNotFilled() : void {
    $this->drupalGet('user/login');
    $edit = [
        'name' => $this->randomMachineName(),
        'pass' => $this->randomMachineName(),
    ];
    $this->drupalGet('user/login');
    $this->submitForm($edit, 'Log in');
    $this->assertSession()
        ->pageTextContains("Unrecognized username or password. Forgot your password?");
    $this->assertSession()
        ->linkExists("Forgot your password?");
    // Verify we don't pass the username as a query parameter.
    $this->assertSession()
        ->linkByHrefNotExists(Url::fromRoute('user.pass', [], [
        'query' => [
            'name' => $edit['name'],
        ],
    ])->toString());
    $this->assertSession()
        ->linkByHrefExists(Url::fromRoute('user.pass')->toString());
    unset($edit['pass']);
    // Verify the field is empty by default.
    $this->drupalGet('user/password');
    $this->assertSession()
        ->fieldValueEquals('name', '');
    // Ensure the name field value is not cached.
    $this->drupalGet('user/password', [
        'query' => [
            'name' => $edit['name'],
        ],
    ]);
    $this->assertSession()
        ->fieldValueEquals('name', $edit['name']);
    $this->drupalGet('user/password');
    $this->assertSession()
        ->fieldValueNotEquals('name', $edit['name']);
}

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