You are here

public function CasPasswordResetTest::testPasswordResetAsAuthenticated in CAS 8

Same name and namespace in other branches
  1. 2.x tests/src/Functional/CasPasswordResetTest.php \Drupal\Tests\cas\Functional\CasPasswordResetTest::testPasswordResetAsAuthenticated()

Tests password reset form as authenticated user.

File

tests/src/Functional/CasPasswordResetTest.php, line 87

Class

CasPasswordResetTest
Tests the user's ability to reset their password.

Namespace

Drupal\Tests\cas\Functional

Code

public function testPasswordResetAsAuthenticated() {

  // Test with the 'user_accounts.restrict_password_management' setting off.
  $this->settings
    ->set('user_accounts.restrict_password_management', FALSE)
    ->set('user_accounts.prevent_normal_login', FALSE)
    ->save();

  // Check that a non-CAS user is able to reset their password.
  $this
    ->drupalLogin($this->nonCasUser);
  $this
    ->drupalPostForm('/user/password', [], 'Submit');
  $this
    ->assertSession()
    ->addressEquals($this->nonCasUser
    ->toUrl());
  $this
    ->assertSession()
    ->pageTextContains('Further instructions have been sent to your email address.');

  // Check that a CAS user is able to reset their password.
  $this
    ->drupalLogin($this->casUser);
  $this
    ->drupalPostForm('/user/password', [], 'Submit');
  $this
    ->assertSession()
    ->addressEquals($this->casUser
    ->toUrl());
  $this
    ->assertSession()
    ->pageTextContains('Further instructions have been sent to your email address.');

  // Test with the 'user_accounts.restrict_password_management' setting on.
  $this->settings
    ->set('user_accounts.restrict_password_management', TRUE)
    ->save();

  // Check that a CAS user's access to the /user/password route is denied.
  $this
    ->drupalGet('/user/password');
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // Check that a non-CAS user is able to reset their password.
  $this
    ->drupalLogin($this->nonCasUser);
  $this
    ->drupalPostForm('/user/password', [], 'Submit');
  $this
    ->assertSession()
    ->addressEquals($this->nonCasUser
    ->toUrl());
  $this
    ->assertSession()
    ->pageTextContains('Further instructions have been sent to your email address.');
}