You are here

function PrivatemsgEMailNotifyTestCase::verifyMail in Privatemsg 6.2

Same name and namespace in other branches
  1. 7.2 pm_email_notify/pm_email_notify.test \PrivatemsgEMailNotifyTestCase::verifyMail()

Verify a notification mail.

Parameters

$mail: Mail array as returned by DrupalWebTestCase::drupalGetMails().

$recipient: Recipient user object.

$author: Author user object.

$message: Message array, containing the keys thread_id, body and subject.

$expectedFrom: The mail address expected to be the notification origin (optional).

1 call to PrivatemsgEMailNotifyTestCase::verifyMail()
PrivatemsgEMailNotifyTestCase::verifyMails in pm_email_notify/pm_email_notify.test
Verify multiple notification mails

File

pm_email_notify/pm_email_notify.test, line 514
Test file for pm_email_notify.module

Class

PrivatemsgEMailNotifyTestCase
@file Test file for pm_email_notify.module

Code

function verifyMail($mail, $recipient, $author, $message, $expectedFrom = NULL) {
  $this
    ->assertEqual($mail['id'], 'pm_email_notify_notice', t('Correct notification id.'));
  $this
    ->assertEqual($mail['to'], $recipient->mail, t('Correct recipient e-mail address.'));
  $params = array(
    '!author_uid' => $author->uid,
    '!author' => privatemsg_recipient_format($author, array(
      'plain' => TRUE,
    )),
    '!pm_subject' => trim(drupal_html_to_text(check_plain($message['subject']))),
    '!pm_body' => trim(drupal_html_to_text(check_markup($message['body'], NULL, FALSE))),
    '!thread' => $message['thread_id'],
    '!user_uid' => $recipient->uid,
    '!message' => url(privatemsg_get_dynamic_url_prefix($recipient->uid) . '/view/' . $message['thread_id'], array(
      'absolute' => TRUE,
    )),
    '!settings' => url('user/' . $recipient->uid . '/edit', array(
      'absolute' => TRUE,
    )),
    '!site' => variable_get('site_name', 'Drupal'),
    '!username' => privatemsg_recipient_format($recipient, array(
      'plain' => TRUE,
    )),
  );
  $subject = strtr(_pm_email_notify_text('subject'), $params);
  $body = drupal_wrap_mail(strtr(_pm_email_notify_text('body'), $params));
  $this
    ->assertEqual($mail['subject'], $subject, t('Correct subject'));
  $this
    ->assertEqual($mail['body'], $body, t('Correct body'));

  // Optionally verify the message's from address.
  if (isset($expectedFrom)) {
    $this
      ->assertEqual($mail['from'], $expectedFrom, sprintf('Mail sender was %s, expected sender was %s', $mail['from'], $expectedFrom));
  }
}