public function PasswordPolicyExpirationTestCase::testWarningEmails in Password Policy 7
Tests expiration warning e-mails.
File
- tests/
password_policy_expiration.test, line 357 - Tests for Password policy module expiration functionality.
Class
- PasswordPolicyExpirationTestCase
- Tests of password expiration.
Code
public function testWarningEmails() {
$expiration_days = 180;
$rid = DRUPAL_AUTHENTICATED_RID;
$warning = '14,7';
$this
->setExpirationPolicy($expiration_days, $rid, $warning);
// Disable admin (UID=1) expiration to prevent multiple expiration emails.
$this
->disableAdminExpiration();
// Start at 180 days before expiration.
// By "day" in the rest of this method, a 24-hour period of time is meant,
// not a calendar day.
$this
->cronRun();
$this
->assertNoMail('No e-mails sent initially.');
// Advance to one second past 90 days before expiration.
$one_day = 24 * 60 * 60;
_password_policy_advance_test_clock(90 * $one_day + 1);
$this
->cronRun();
$this
->assertNoMail('No e-mails sent before first expiration warning day.');
// Advance to one second past 14 days before expiration.
_password_policy_advance_test_clock(76 * $one_day);
$this
->cronRun();
$warning_subject = t('Password expiration warning for !username at !site', array(
'!username' => $this->policyMaker->name,
'!site' => variable_get('site_name', 'Drupal'),
));
$this
->assertMail('subject', $warning_subject, 'First expiration warning e-mail sent.');
$this
->clearMails();
// Advance to one second past 10 days before expiration.
_password_policy_advance_test_clock(4 * $one_day);
$this
->cronRun();
$this
->assertNoMail('No e-mails sent between first and second expiration warning days.');
// Advance to one second past 7 days before expiration.
_password_policy_advance_test_clock(3 * $one_day);
$this
->cronRun();
$warning_subject = t('Password expiration warning for !username at !site', array(
'!username' => $this->policyMaker->name,
'!site' => variable_get('site_name', 'Drupal'),
));
$this
->assertMail('subject', $warning_subject, 'Second expiration warning e-mail sent.');
$this
->clearMails();
// Advance to one second past 6 days before expiration.
_password_policy_advance_test_clock(1 * $one_day);
$this
->cronRun();
$this
->assertNoMail('No e-mails sent after expiration warnings and before expiration.');
// Advance to one second past day before expiration.
_password_policy_advance_test_clock(6 * $one_day);
$this
->cronRun();
$this
->assertNoMail('No e-mails sent after expiration warnings and less than one day before expiration.');
// Advance to one second past 3 days after expiration.
_password_policy_advance_test_clock(3 * $one_day);
$this
->cronRun();
$this
->assertNoMail('No e-mails sent after expiration.');
}