You are here

function PrivatemsgEMailNotifyTestCase::verifyMail in Privatemsg 7.2

Same name and namespace in other branches
  1. 6.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 516
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.'));
  if (is_array($message) && isset($message['thread_id'])) {
    $mid = db_query('SELECT MAX(mid) FROM {pm_index} WHERE thread_id = :thread_id', array(
      ':thread_id' => $message['thread_id'],
    ))
      ->fetchField();
    $message = privatemsg_message_load($mid);
  }
  $data = array(
    'privatemsg_message' => $message,
    'privatemsg_recipient' => $recipient,
  );
  $options = array(
    'language' => user_preferred_language($recipient),
    // Don't sanitize output since this is used in an email, not a browser.
    'sanitize' => FALSE,
    // Custom token to avoid custom token handling.
    'privatemsg-display-invalid' => FALSE,
  );
  $subject = trim(token_replace(pm_email_notify_text('subject', $options['language']), $data, $options));
  $body = drupal_wrap_mail(drupal_html_to_text(trim(token_replace(pm_email_notify_text('body', $options['language']), $data, $options))));
  $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, format_string('Mail sender was %sender, expected sender was %expected', array(
      '%sender' => $mail['from'],
      '%expected' => $expectedFrom,
    )));
  }
}