You are here

public function UserPasswordResetTest::testUserPasswordResetWithAdditionalAjaxForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/user/tests/src/FunctionalJavascript/UserPasswordResetTest.php \Drupal\Tests\user\FunctionalJavascript\UserPasswordResetTest::testUserPasswordResetWithAdditionalAjaxForm()

Tests password reset functionality with an AJAX form.

Make sure the ajax request from uploading a user picture does not invalidate the reset token.

File

core/modules/user/tests/src/FunctionalJavascript/UserPasswordResetTest.php, line 81

Class

UserPasswordResetTest
Ensure that password reset methods work as expected.

Namespace

Drupal\Tests\user\FunctionalJavascript

Code

public function testUserPasswordResetWithAdditionalAjaxForm() {
  $this
    ->drupalGet(Url::fromRoute('user.reset.form', [
    'uid' => $this->account
      ->id(),
  ]));

  // Try to reset the password for an invalid account.
  $this
    ->drupalGet('user/password');

  // Reset the password by username via the password reset page.
  $edit['name'] = $this->account
    ->getAccountName();
  $this
    ->drupalPostForm(NULL, $edit, t('Submit'));
  $resetURL = $this
    ->getResetURL();
  $this
    ->drupalGet($resetURL);

  // Login
  $this
    ->drupalPostForm(NULL, NULL, t('Log in'));

  // Generate file.
  $image_file = current($this
    ->drupalGetTestFiles('image'));
  $image_path = \Drupal::service('file_system')
    ->realpath($image_file->uri);

  // Upload file.
  $this
    ->getSession()
    ->getPage()
    ->attachFileToField('Picture', $image_path);
  $this
    ->assertSession()
    ->waitForButton('Remove');

  // Change the forgotten password.
  $password = user_password();
  $edit = [
    'pass[pass1]' => $password,
    'pass[pass2]' => $password,
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));

  // Verify that the password reset session has been destroyed.
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));

  // Password needed to make profile changes.
  $this
    ->assertSession()
    ->pageTextContains("Your current password is missing or incorrect; it's required to change the Password.");
}