1 user.test | protected UserLoginTestCase::resetUserPassword(User $user) |
Resets the user password and logs the user in.
Parameters
User $user: The account to reset the password for.
Return value
string: New password.
File
- core/
modules/ user/ tests/ user.test, line 656 - Tests for user.module.
Class
- UserLoginTestCase
- Functional tests for user logins, including rate limiting of login attempts.
Code
protected function resetUserPassword(User $user) {
$this->backdropGet('user/password');
$edit['name'] = $user->name;
$this->backdropPost(NULL, $edit, 'Reset password');
$emails = $this->backdropGetMails();
$email = end($emails);
$urls = array();
preg_match('#.+user/reset/.+#', $email['body'], $urls);
$resetURL = $urls[0];
$this->backdropGet($resetURL);
$pass = user_password();
$pass_edit = array(
'pass[pass1]' => $pass,
'pass[pass2]' => $pass,
);
$this->backdropPost(NULL, $pass_edit, t('Save password & log in'));
return $pass;
}