// Try to reset the password for an invalid account.
$this->drupalGet('user/password');
$edit=array('name'=>$this->randomName(32));
$this->drupalPost(NULL,$edit,t('E-mail new password'));
$this->assertText(t('Sorry, @name is not recognized as a username or an e-mail address.',array('@name'=>$edit['name'])),'Validation error message shown when trying to request password for invalid account.');
$this->assertEqual(count($this->drupalGetMails(array('id'=>'user_password_reset'))),0,t('No e-mail was sent when requesting a password for an invalid account.'));
// Reset the password by username via the password reset page.
$edit['name']=$this->account->name;
$this->drupalPost(NULL,$edit,t('E-mail new password'));
// Verify that the user was sent an e-mail.
$this->assertMail('to',$this->account->mail,t('Password e-mail sent to user.'));
$subject=t('Replacement login information for @username at @site',array('@username'=>$this->account->name,'@site'=>variable_get('site_name','Drupal')));
$this->assertMail('subject',$subject,'Password reset e-mail subject is correct.');
$resetURL=$this->getResetURL();
$this->drupalGet($resetURL);
// Check the one-time login page.
$this->assertText($this->account->name,'One-time login page contains the correct username.');
$this->assertText(t('This login can be used only once.'),'Found warning about one-time login.');
// Check successful login.
$this->drupalPost(NULL,NULL,t('Log in'));
$this->assertLink(t('Log out'));
$this->assertTitle(t('@name | @site',array('@name'=>$this->account->name,'@site'=>variable_get('site_name','Drupal'))),'Logged in using password reset link.');
// Log out, and try to log in again using the same one-time link.
$this->drupalLogout();
$this->drupalGet($resetURL);
$this->assertText(t('You have tried to use a one-time login link that has either been used or is no longer valid. Please request a new one using the form below.'),'One-time link is no longer valid.');
// Request a new password again, this time using the e-mail address.
$this->drupalGet('user/password');
// Count email messages before to compare with after.
$this->drupalPost(NULL,$edit,t('E-mail new password'));
$this->assertTrue(count($this->drupalGetMails(array('id'=>'user_password_reset')))===$before+1,'E-mail sent when requesting password reset using e-mail address.');
// To attempt an expired password reset, create a password reset link as if
// its request time was 60 seconds older than the allowed limit of timeout.
// Create a password reset link as if the request time was 60 seconds older than the allowed limit.
$this->assertText(t('You have tried to use a one-time login link that has expired. Please request a new one using the form below.'),'Expired password reset request rejected.');
}
/**
* Retrieves password reset e-mail and extracts the login link.