You are here

function PrivatemsgEMailNotifyTestCase::testUnreadConfiguration in Privatemsg 7.2

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

Test Always configuration.

File

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

Class

PrivatemsgEMailNotifyTestCase
@file Test file for pm_email_notify.module

Code

function testUnreadConfiguration() {

  // Configure to only send notifications for new messages.
  $this
    ->drupalLogin($this->admin);
  $edit = array(
    'privatemsg_setting_email_notify_level' => PM_EMAIL_NOTIFY_LEVEL_UNREAD_ONCE,
  );
  $this
    ->drupalPost('admin/config/messaging/privatemsg', $edit, t('Save configuration'));
  $this
    ->drupalLogin($this->author);

  // Send a new message.
  $message = array(
    'recipient' => $this->recipient->name . ', ' . $this->recipient2->name,
    'subject' => $this
      ->randomName(),
    'body[value]' => $this
      ->randomName(20),
  );
  $this
    ->drupalPost('messages/new', $message, t('Send message'));
  $message['thread_id'] = $this
    ->getCurrentThreadId();
  $this
    ->verifyMails(array(
    $this->recipient,
    $this->recipient2,
  ), $this->author, $message);

  // Reply to the existing message.
  $reply = array(
    'body[value]' => $this
      ->randomName(20),
  );
  $this
    ->drupalPost(NULL, $reply, t('Send message'));
  $message['body[value]'] = $reply['body[value]'];
  $this
    ->getNewMails(0);

  // Visit the thread with the first recipient.
  $this
    ->drupalLogin($this->recipient);
  $this
    ->drupalGet('messages');
  $this
    ->clickLink($message['subject']);

  // Back to author, send another message.
  $this
    ->drupalLogin($this->author);
  $this
    ->drupalGet('messages/view/' . $message['thread_id']);
  $reply = array(
    'body[value]' => $this
      ->randomName(20),
  );
  $this
    ->drupalPost(NULL, $reply, t('Send message'));
  $message['body[value]'] = $reply['body[value]'];
  $this
    ->verifyMails(array(
    $this->recipient,
  ), $this->author, $message);

  // Another reply, again, no notifications.
  $reply = array(
    'body[value]' => $this
      ->randomName(20),
  );
  $this
    ->drupalPost(NULL, $reply, t('Send message'));
  $message['body[value]'] = $reply['body[value]'];
  $this
    ->getNewMails(0);

  // Send a message to all users.
  $message = array(
    'recipient' => 'authenticated user',
    'subject' => $this
      ->randomName(),
    'body[value]' => $this
      ->randomName(20),
  );
  $this
    ->drupalPost('messages/new', $message, t('Send message'));
  $message['thread_id'] = $this
    ->getCurrentThreadId();
  $recipients = array(
    user_load(1),
    $this->author,
    $this->recipient,
    $this->recipient2,
    $this->admin,
  );
  $this
    ->verifyMails($recipients, $this->author, $message);
}