public function PasswordPolicyForcePasswordChangeTestCase::testAllowedPathsAlter in Password Policy 7
Tests altering allowed paths from another module.
File
- tests/
password_policy.test, line 721 - Functional tests for Password policy module.
Class
- PasswordPolicyForcePasswordChangeTestCase
- Tests of forcing password changes.
Code
public function testAllowedPathsAlter() {
$admin = $this
->drupalCreateUser(array(
'force password change',
'administer password policies',
'administer users',
));
$user = $this
->drupalCreateUser();
// Force user to change their password.
$this
->drupalLogin($admin);
$edit = array(
'force_password_change' => TRUE,
);
$this
->drupalPost("user/{$user->uid}/edit", $edit, t('Save'));
$this
->drupalLogout();
// Verify user is forced to change password.
$this
->drupalLogin($user);
$this
->assertFieldByName('current_pass', NULL, 'User redirected correctly.');
$this
->assertRaw(t('Your password has expired. You must change your password to proceed on the site.'), 'User presented with error instructing them to change their password.');
// Try to visit disallowed paths.
$this
->drupalGet('node');
$this
->assertFieldByName('mail', NULL, 'User redirected back to user-edit page.');
$this
->assertRaw(t('Your password has expired. You must change your password to proceed on the site.'), 'User forced to change password.');
$this
->drupalGet('node/add/page');
$this
->assertFieldByName('mail', NULL, 'User redirected back to user-edit page.');
$this
->assertRaw(t('Your password has expired. You must change your password to proceed on the site.'), 'User forced to change password.');
$this
->drupalLogout();
// Add allowed path using
// hook_password_policy_force_change_allowed_path_alter().
variable_set('password_policy_test_force_change_allowed_paths_alter', TRUE);
// Try to visit paths that are now allowed.
// Note that "Access denied" is expected for node/add/page.
$this
->drupalLogin($user);
$this
->drupalGet('node');
$this
->assertNoFieldByName('mail', NULL, 'User not redirected back to user-edit page.');
$this
->drupalGet('node/add/page');
$this
->assertNoFieldByName('mail', NULL, 'User not redirected back to user-edit page.');
// Try to visit a path that is still disallowed.
$this
->drupalGet("user/{$user->uid}/view");
$this
->assertFieldByName('mail', NULL, 'User redirected back to user-edit page.');
$this
->assertRaw(t('Your password has expired. You must change your password to proceed on the site.'), 'User forced to change password.');
$this
->drupalLogout();
}