You are here

function PrivatemsgEMailNotifyTestCase::testOnlyUserConfiguration in Privatemsg 7.2

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

Test Always configuration.

File

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

Class

PrivatemsgEMailNotifyTestCase
@file Test file for pm_email_notify.module

Code

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

  // 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);

  // Enable only user.
  $this
    ->drupalLogin($this->admin);
  $edit = array(
    'privatemsg_setting_email_notify_only_user' => TRUE,
  );
  $this
    ->drupalPost('admin/config/messaging/privatemsg', $edit, t('Save configuration'));
  $this
    ->drupalLogin($this->author);

  // No notifications should be sent now.
  $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 can change
  // the default setting.
  $this
    ->drupalLogin($this->recipient);
  $this
    ->drupalGet('user/' . $this->recipient->uid . '/edit');

  // Verify correct defaults.
  $this
    ->assertFieldChecked('edit-pm-email-only-user', t('Only user option has the correct default value'));

  //$this->assertFieldByName('pm_email_notify_level', PM_EMAIL_NOTIFY_LEVEL_ALL, t('Notification level setting has the correct default value'));
  $edit = array(
    'pm_email_only_user' => FALSE,
  );
  $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-only-user', NULL, t('User is not allowed to customize noly user option.'));

  //$this->assertNoText(t('Private messages'), t('Private messages fieldset is not displayed when there are no fields within it.'));
  $this
    ->drupalLogin($this->author);

  // Send another message to all users, only $this->recipient should receive
  // a notification.
  $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);
}