public function PasswordPolicyExpirationTestCase::testWarningEmailsTokens in Password Policy 7
Tests tokens replacement in warning e-mails.
Importantly, this tests the Password Policy tokens.
File
- tests/
password_policy_expiration.test, line 451 - Tests for Password policy module expiration functionality.
Class
- PasswordPolicyExpirationTestCase
- Tests of password expiration.
Code
public function testWarningEmailsTokens() {
$expiration_days = 30;
$rid = DRUPAL_AUTHENTICATED_RID;
$warning = '14';
$this
->setExpirationPolicy($expiration_days, $rid, $warning);
// Disable admin (UID=1) expiration to prevent multiple expiration emails.
$this
->disableAdminExpiration();
// Trigger expiration warning e-mail.
// (Advance to one second past 14 days before expiration and run cron.)
$one_day = 24 * 60 * 60;
_password_policy_advance_test_clock(16 * $one_day + 1);
$this
->cronRun();
// Assert correct subject.
$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, "Tokens replaced in subject correctly.");
// Assert correct body.
$edit_url = _password_policy_get_preferred_password_edit_url_for_user($this->policyMaker);
global $language;
$langcode = isset($language) ? $language->language : NULL;
$warning_body = t("!username,\n\nYour password at !site will expire in less than !days_left day(s).\n\nPlease go to !edit_url to change your password.", array(
'!username' => $this->policyMaker->name,
'!site' => variable_get('site_name', 'Drupal'),
'!days_left' => '14',
'!edit_url' => $edit_url,
), array(
'langcode' => $langcode,
));
// assertMail() does not seem to work for the body because the mail
// functions insert some whitespace into the body. assertMailString() seems
// to work, though.
$this
->assertMailString('body', $warning_body, 1);
}