public function PasswordPolicyUITestCase::testExpire in Password Policy 7.2
Test expire functionality.
File
- ./
password_policy.test, line 752 - Unit tests for Password policy module.
Class
- PasswordPolicyUITestCase
- Test case to verify accuracy of each available policy condition.
Code
public function testExpire() {
// Use password_policy_test module form_alter to prevent extraneous policy
// text on user edit page. @todo figure out another way to do this.
variable_set('password_policy_test_no_description', TRUE);
$user = $this
->drupalCreateUser();
$this
->drupalLogin($user);
// Set up expire policy.
$this
->createExpirePolicy();
// Sleep to force simpletest to exceed 1 second expire.
sleep(2);
$this
->drupalGet('filter/tips');
$this
->assertText('Your password has expired. Please change it now.');
$this
->assertFieldByName('pass[pass1]', '', 'Password entry field appears.');
// Change password.
$password1 = $this
->randomName() . '9';
$edit = array();
$edit['current_pass'] = $user->pass_raw;
$edit['pass[pass1]'] = $password1;
$edit['pass[pass2]'] = $password1;
$this
->drupalPost("user/{$user->uid}/edit", $edit, t('Save'));
$this
->assertText('The changes have been saved.');
$user->pass_raw = $password1;
$this
->drupalLogout();
// Artificially lengthen expiration to give administrator time to disable.
$info = ctools_export_crud_load('password_policy', 'expire');
$config = unserialize($info->config);
$config['expire']['expire_limit'] = '30 minutes';
$info->config = serialize($config);
ctools_export_crud_save('password_policy', $info);
// Disable expire.
$admin = $this
->drupalCreateUser(array(
'administer password policy',
));
$this
->drupalLogin($admin);
$path = 'admin/config/people/password_policy/list/expire/edit';
$edit = array(
'expire_enabled' => FALSE,
);
$this
->drupalPost($path, $edit, t('Save'));
$this
->drupalLogout();
// Reset expiration to one second.
ctools_export_load_object_reset('password_policy');
$info = ctools_export_crud_load('password_policy', 'expire');
$config = unserialize($info->config);
$config['expire']['expire_limit'] = '1 second';
$info->config = serialize($config);
ctools_export_crud_save('password_policy', $info);
// Confirm expire disabled.
sleep(2);
$this
->drupalLogin($user);
$this
->drupalGet('filter/tips');
$this
->assertNoText('Your password has expired. Please change it now.');
}