function UserAccountFormPasswordResetTest::testPasswordResetToken

Same name and namespace in other branches
  1. 9 core/modules/user/tests/src/Kernel/UserAccountFormPasswordResetTest.php \Drupal\Tests\user\Kernel\UserAccountFormPasswordResetTest::testPasswordResetToken()
  2. 11.x core/modules/user/tests/src/Kernel/UserAccountFormPasswordResetTest.php \Drupal\Tests\user\Kernel\UserAccountFormPasswordResetTest::testPasswordResetToken()

Tests the reset token used only from query string.

File

core/modules/user/tests/src/Kernel/UserAccountFormPasswordResetTest.php, line 51

Class

UserAccountFormPasswordResetTest
Verifies that the password reset behaves as expected with form elements.

Namespace

Drupal\Tests\user\Kernel

Code

public function testPasswordResetToken() : void {
  /** @var \Symfony\Component\HttpFoundation\Request $request */
  $request = $this->container
    ->get('request_stack')
    ->getCurrentRequest();
  $token = 'VALID_TOKEN';
  $request->getSession()
    ->set('pass_reset_1', $token);
  // Set token in query string.
  $request->query
    ->set('pass-reset-token', $token);
  $form = $this->buildAccountForm('default');
  // User shouldn't see current password field.
  $this->assertFalse($form['account']['current_pass']['#access']);
  $request->query
    ->set('pass-reset-token', NULL);
  $request->attributes
    ->set('pass-reset-token', $token);
  $form = $this->buildAccountForm('default');
  $this->assertTrue($form['account']['current_pass']['#access']);
}

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