You are here

public function PasswordPolicyTest::testPasswordPolicies in Thunder 6.1.x

Same name and namespace in other branches
  1. 8.5 tests/src/Functional/Integration/PasswordPolicyTest.php \Drupal\Tests\thunder\Functional\Integration\PasswordPolicyTest::testPasswordPolicies()
  2. 8.2 tests/src/Functional/Integration/PasswordPolicyTest.php \Drupal\Tests\thunder\Functional\Integration\PasswordPolicyTest::testPasswordPolicies()
  3. 8.3 tests/src/Functional/Integration/PasswordPolicyTest.php \Drupal\Tests\thunder\Functional\Integration\PasswordPolicyTest::testPasswordPolicies()
  4. 8.4 tests/src/Functional/Integration/PasswordPolicyTest.php \Drupal\Tests\thunder\Functional\Integration\PasswordPolicyTest::testPasswordPolicies()
  5. 6.2.x tests/src/Functional/Integration/PasswordPolicyTest.php \Drupal\Tests\thunder\Functional\Integration\PasswordPolicyTest::testPasswordPolicies()
  6. 6.0.x tests/src/Functional/Integration/PasswordPolicyTest.php \Drupal\Tests\thunder\Functional\Integration\PasswordPolicyTest::testPasswordPolicies()

Tests redirect from old URL to new one.

File

tests/src/Functional/Integration/PasswordPolicyTest.php, line 24

Class

PasswordPolicyTest
Tests password policy integration.

Namespace

Drupal\Tests\thunder\Functional\Integration

Code

public function testPasswordPolicies() {
  $editor = $this
    ->logWithRole('editor');
  $current_password = $editor->passRaw;
  $valid_password = 'This is 1 valid password!';
  $another_valid_password = 'This is 1 valid password 2!';
  $invalid_passwords = [
    'This is no valid password!' => 'Password must contain at least 4 types of characters from the following character types: lowercase letters, uppercase letters, digits, special characters.',
    'This is not 1 valid password' => 'Password must contain at least 4 types of characters from the following character types: lowercase letters, uppercase letters, digits, special characters.',
    'this is not 1 valid password!' => 'Password must contain at least 4 types of characters from the following character types: lowercase letters, uppercase letters, digits, special characters.',
    'short' => 'Password length must be at least 8 characters.',
  ];
  $edit['current_pass'] = $current_password;
  $edit['pass[pass2]'] = $valid_password;
  $edit['pass[pass1]'] = $valid_password;
  $this
    ->drupalGet("user/" . $editor
    ->id() . "/edit");
  $this
    ->submitForm($edit, $this
    ->t('Save'));
  $this
    ->assertSession()
    ->responseContains('The changes have been saved.');

  // Testing reusing of password.
  $edit['current_pass'] = $valid_password;
  $edit['pass[pass2]'] = $another_valid_password;
  $edit['pass[pass1]'] = $another_valid_password;
  $this
    ->drupalGet("user/" . $editor
    ->id() . "/edit");
  $this
    ->submitForm($edit, $this
    ->t('Save'));
  $this
    ->assertSession()
    ->responseContains('The changes have been saved.');
  $edit['current_pass'] = $another_valid_password;
  $edit['pass[pass2]'] = $valid_password;
  $edit['pass[pass1]'] = $valid_password;
  $this
    ->drupalGet("user/" . $editor
    ->id() . "/edit");
  $this
    ->submitForm($edit, $this
    ->t('Save'));
  $this
    ->assertSession()
    ->responseNotContains('The changes have been saved.');

  // Testing invalid character type combinations and length restriction.
  foreach ($invalid_passwords as $password => $response) {
    $edit['pass[pass2]'] = $password;
    $edit['pass[pass1]'] = $password;
    $this
      ->drupalGet("user/" . $editor
      ->id() . "/edit");
    $this
      ->submitForm($edit, $this
      ->t('Save'));
    $this
      ->assertSession()
      ->responseContains($response);
  }
}