You are here

public function PasswordPolicyForcePasswordChangeTestCase::testRoleChange in Password Policy 6

Same name and namespace in other branches
  1. 7 tests/password_policy.test \PasswordPolicyForcePasswordChangeTestCase::testRoleChange()

File

tests/password_policy.test, line 364
Unit tests for Password policy module.

Class

PasswordPolicyForcePasswordChangeTestCase

Code

public function testRoleChange() {
  $admin = $this
    ->drupalCreateUser(array(
    'administer users',
    'force password change',
  ));
  $user1 = $this
    ->drupalCreateUser();
  $user2 = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($admin);
  $edit = array(
    'password_policy_force_change_roles[2]' => 2,
  );
  $this
    ->drupalPost('admin/settings/password_policy/password_change', $edit, t('Submit'));
  $this
    ->assertText(t('Users in the following roles will be required to immediately change their password: authenticated user'), t('Authenticated users role selected.'));
  $this
    ->assertTrue($admin->uid != 1, t("Admin uid not 1: {$admin->uid}"));
  $this
    ->assertRaw(t('Your password has expired. You must change your password to proceed on the site.'), t('Admin (not uid 1) correctly forced to change password.'));

  // test db flags for individual users
  $entry_1 = db_result(db_query('SELECT uid FROM {password_policy_force_change} WHERE uid=%d', $user1->uid));
  $this
    ->assertTrue($entry_1 == $user1->uid, t("Entry created in password_policy_force_change for user {$user1->uid}."));
  $flag_1 = db_result(db_query('SELECT force_change FROM {password_policy_force_change} WHERE uid=%d', $user1->uid));
  $this
    ->assertTrue($flag_1 == 1, t("User {$user1->uid} flagged: {$flag_1}."));
  $this
    ->drupalLogout();

  //test individual users
  $this
    ->drupalLogin($user1);
  $this
    ->drupalGet('node');
  $this
    ->assertRaw(t('Your password has expired. You must change your password to proceed on the site.'), t('First test user forced to change password.'));
  $this
    ->drupalLogout();

  //test 2nd user
  $this
    ->drupalLogin($user2);
  $this
    ->assertRaw(t('Your password has expired. You must change your password to proceed on the site.'), t('Second test user forced to change password.'));
  $this
    ->drupalLogout();
}