You are here

public function RedirectTest::testRedirectAfterOneTimeLoginAndSettingPassword in Login Destination 8.2

Same name and namespace in other branches
  1. 8 tests/src/Functional/RedirectTest.php \Drupal\Tests\login_destination\Functional\RedirectTest::testRedirectAfterOneTimeLoginAndSettingPassword()

Tests redirecting after one-time login and setting password.

File

tests/src/Functional/RedirectTest.php, line 195

Class

RedirectTest
Tests redirects.

Namespace

Drupal\Tests\login_destination\Functional

Code

public function testRedirectAfterOneTimeLoginAndSettingPassword() {
  $this
    ->createLoginDestinationToNode1([
    LoginDestination::TRIGGER_ONE_TIME_LOGIN,
  ]);

  // Generate password reset URL.
  $url = user_pass_reset_url($this->account);

  // And use the one-time login link.
  $this
    ->drupalPostForm($url, NULL, 'Log in');
  $this
    ->assertSession()
    ->pageTextContains('You have just used your one-time login link. It is no longer necessary to use this link to log in. Please change your password.');
  $this
    ->assertSession()
    ->titleEquals(strtr('@name | @site', [
    '@name' => $this->account
      ->getAccountName(),
    '@site' => $this
      ->config('system.site')
      ->get('name'),
  ]));

  // Set a new password.
  $password = user_password();
  $edit = [
    'pass[pass1]' => $password,
    'pass[pass2]' => $password,
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save');
  $this
    ->assertSession()
    ->pageTextContains('The changes have been saved.');

  // Assert that the redirect has happened now.
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->addressEquals('/node/1');
}