You are here

function PrivatemsgEMailNotifyTestCase::testAlwaysConfiguration in Privatemsg 6.2

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

Test Always configuration.

File

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

Class

PrivatemsgEMailNotifyTestCase
@file Test file for pm_email_notify.module

Code

function testAlwaysConfiguration() {
  $this
    ->drupalLogin($this->author);

  // Send a new message.
  $message = array(
    'recipient' => $this->recipient->name . ', ' . $this->recipient2->name,
    'subject' => $this
      ->randomName(),
    'body' => $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' => $this
      ->randomName(20),
  );
  $this
    ->drupalPost(NULL, $reply, t('Send message'));
  $message['body'] = $reply['body'];
  $this
    ->verifyMails(array(
    $this->recipient,
    $this->recipient2,
  ), $this->author, $message);

  // Send a message to all users.
  $message = array(
    'recipient' => 'authenticated user',
    'subject' => $this
      ->randomName(),
    'body' => $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);

  // Verify that the user with the necessary permission chan choose the exact
  // notification level while the other can only opt out.
  $this
    ->drupalLogin($this->recipient);
  $this
    ->drupalGet('user/' . $this->recipient->uid . '/edit');

  // Verify correct defaults.
  $this
    ->assertFieldByName('pm_email_notify_level', PM_EMAIL_NOTIFY_LEVEL_ALL, t('Notification level setting has the correct default value'));
  $edit = array(
    'pm_email_notify_level' => PM_EMAIL_NOTIFY_LEVEL_DISABLED,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // Send another message, only recipient two should get a notification.
  $this
    ->drupalLogin($this->author);

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

  // Opt out of notifications with the other user.
  $this
    ->drupalLogin($this->recipient2);
  $this
    ->drupalGet('user/' . $this->recipient2->uid . '/edit');

  // Verify correct defaults.
  $this
    ->assertFieldChecked('edit-pm-email-notify-level', PM_EMAIL_NOTIFY_LEVEL_DEFAULT, t('Notification level is set to default.'));
  $edit = array(
    'pm_email_notify_level' => FALSE,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // Send another message, only recipient two should get a notification.
  $this
    ->drupalLogin($this->author);

  // Send a new message.
  $message = array(
    'recipient' => $this->recipient->name . ', ' . $this->recipient2->name,
    'subject' => $this
      ->randomName(),
    'body' => $this
      ->randomName(20),
  );
  $this
    ->drupalPost('messages/new', $message, t('Send message'));
  $this
    ->getNewMails(0);
}