You are here

public function CasPasswordResetTest::testPasswordResetAsAuthenticated in CAS 2.x

Same name and namespace in other branches
  1. 8 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 86

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
    ->assertStatusMessage('user_without_cas@example.com');

  // 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
    ->assertStatusMessage('user_with_cas@example.com');

  // 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
    ->assertStatusMessage('user_without_cas@example.com');
}