You are here

function PrivatemsgEMailNotifyTestCase::testNeverConfiguration in Privatemsg 7.2

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

Test that no mails are sent when

File

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

Class

PrivatemsgEMailNotifyTestCase
@file Test file for pm_email_notify.module

Code

function testNeverConfiguration() {

  // Disable notifications by default.
  $this
    ->drupalLogin($this->admin);
  $edit = array(
    'privatemsg_setting_email_notify_level' => PM_EMAIL_NOTIFY_LEVEL_DISABLED,
  );
  $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'));
  $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'));
  $this
    ->getNewMails(0);

  // Verify that only the user with the necessary permission enable email
  // notifications.
  $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_ALL,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $this
    ->drupalLogin($this->recipient2);
  $this
    ->drupalGet('user/' . $this->recipient2->uid . '/edit');

  // Verify correct defaults.
  $this
    ->assertNoFieldById('edit-pm-email-notify-level', NULL, t('User is not allowed change email notification setting.'));
  $this
    ->assertNoText(t('Private messages'), t('Private messages fieldset is not displayed when there are no fields within it.'));

  // Send a message to all users, only recipient should receive an email.
  $this
    ->drupalLogin($this->author);
  $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(
    $this->recipient,
  );
  $this
    ->verifyMails($recipients, $this->author, $message);
}