public function SimpleLdapUserPasswordResetTestCase::testPasswordChange in Simple LDAP 7
Same name and namespace in other branches
- 7.2 simple_ldap_user/simple_ldap_user.test \SimpleLdapUserPasswordResetTestCase::testPasswordChange()
Tests that a user can change thier password.
File
- simple_ldap_user/
simple_ldap_user.test, line 1023 - Tests for Simple LDAP User module.
Class
Code
public function testPasswordChange() {
// Load configuration variables.
$attribute_name = simple_ldap_user_variable_get('simple_ldap_user_attribute_name');
// Initialize a user account object.
$account = new stdClass();
$account->name = $this->ldapUser[0]->{$attribute_name}[0];
$account->pass_raw = $this->userPassword[0];
// Log in user. This should create/sync an LDAP user (tested elsewhere).
$this
->drupalLogin($account);
// Get the drupal user.
$drupal_user = user_load_by_name($this->ldapUser[0]->{$attribute_name}[0]);
// Create the form variable array.
$edit = array();
$edit['current_pass'] = $this->userPassword[0];
$edit['pass[pass1]'] = $this
->randomName();
$edit['pass[pass2]'] = $edit['pass[pass1]'];
// Submit user edit form.
$this
->drupalPost('user/' . $drupal_user->uid . '/edit', $edit, 'Save');
// Verify that the old password no longer works.
$this
->drupalNoLogin($account);
// Verify that the new password works.
$account->pass_raw = $edit['pass[pass1]'];
$this
->drupalLogin($account);
// Reset the password.
$edit['current_pass'] = $edit['pass[pass1]'];
$edit['pass[pass1]'] = $this->userPassword[0];
$edit['pass[pass2]'] = $edit['pass[pass1]'];
// Submit user edit form.
$this
->drupalPost('user/' . $drupal_user->uid . '/edit', $edit, 'Save');
// Verify that it was changed back.
$account->pass_raw = $edit['pass[pass1]'];
$this
->drupalLogin($account);
}