You are here

public function CasPasswordResetTest::testPasswordResetAsAnonymous in CAS 8

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

Tests password reset form as anonymous.

File

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

Class

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

Namespace

Drupal\Tests\cas\Functional

Code

public function testPasswordResetAsAnonymous() {

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

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

  // Check that a non-CAS user is able to reset their password.
  $this
    ->drupalPostForm('/user/password', [
    'name' => 'user_without_cas',
  ], 'Submit');
  $this
    ->assertSession()
    ->addressEquals('user/login');
  $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 is not able to reset their password.
  $this
    ->drupalPostForm('/user/password', [
    'name' => 'user_with_cas',
  ], 'Submit');
  $this
    ->assertSession()
    ->addressEquals('user/password');
  $this
    ->assertSession()
    ->pageTextContains('The requested account is associated with CAS and its password cannot be managed from this website.');

  // Test a customized error message for the same user.
  $this->settings
    ->set('error_handling.message_restrict_password_management', 'You cannot manage your password. Back to <a href="[site:url]">homepage</a>.')
    ->save();
  $this
    ->getSession()
    ->reload();
  $this
    ->assertSession()
    ->pageTextContains('You cannot manage your password. Back to homepage.');
  $this
    ->assertSession()
    ->linkExists('homepage');

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