You are here

function PrivatemsgTestCase::testReadAllPermission in Privatemsg 6

Same name and namespace in other branches
  1. 6.2 privatemsg.test \PrivatemsgTestCase::testReadAllPermission()
  2. 7.2 privatemsg.test \PrivatemsgTestCase::testReadAllPermission()
  3. 7 privatemsg.test \PrivatemsgTestCase::testReadAllPermission()

Test correct handling of read all permissions.

File

./privatemsg.test, line 361
Test file for privatemsg.module

Class

PrivatemsgTestCase
@file Test file for privatemsg.module

Code

function testReadAllPermission() {
  $author = $this
    ->drupalCreateUser(array(
    'write privatemsg',
    'read privatemsg',
  ));
  $recipient = $this
    ->drupalCreateUser(array(
    'write privatemsg',
    'read privatemsg',
  ));
  $admin = $this
    ->drupalCreateUser(array(
    'write privatemsg',
    'read privatemsg',
    'read all private messages',
  ));

  // Create new message.
  $edit = array(
    'recipient' => $recipient->name,
    'subject' => $this
      ->randomName(20),
    'body' => $this
      ->randomName(100),
  );
  $this
    ->drupalLogin($author);
  $this
    ->drupalPost('messages/new', $edit, t('Send message'));
  $this
    ->assertText(t('A message has been sent to @recipients.', array(
    '@recipients' => $recipient->name,
  )), t('Message sent confirmation displayed'));
  $this
    ->drupalLogin($admin);
  $this
    ->drupalGet('messages/view/1');
  $this
    ->assertText(t('This conversation is being viewed with escalated priviledges and may not be the same as shown to normal users.'), t('Notice about read all mode displayed.'));

  // Send a first response.
  $admin_edit = array(
    'body' => $this
      ->randomName(100),
  );
  $this
    ->drupalPost('messages/view/1', $admin_edit, t('Send message'));

  // Make sure that the notice is not displayed anymore.
  $this
    ->assertNoText(t('This conversation is being viewed with escalated priviledges and may not be the same as shown to normal users.'), t('Notice about read all mode not displayed.'));

  // Make sure that both the existing message body and the new one are displayed.
  $this
    ->assertText($edit['body'], t('First message body displayed.'));
  $this
    ->assertText($admin_edit['body'], t('New message body displayed.'));
  $admin_recipient_count = db_result(db_query("SELECT COUNT(*) FROM {pm_index} WHERE uid = %d AND thread_id = %d", $admin->uid, 1));
  $this
    ->assertEqual($admin_recipient_count, 2, t('Admin is listed as recipient for every message once.'));

  // Send a second response.
  $admin_edit2 = array(
    'body' => $this
      ->randomName(100),
  );
  $this
    ->drupalPost('messages/view/1', $admin_edit2, t('Send message'));

  // Make sure that both the existing message body and the new one are displayed.
  $this
    ->assertText($edit['body'], t('First message body displayed.'));
  $this
    ->assertText($admin_edit['body'], t('Second response body displayed.'));
  $this
    ->assertText($admin_edit2['body'], t('Third message body displayed.'));
  $admin_recipient_count = db_result(db_query("SELECT COUNT(*) FROM {pm_index} WHERE uid = %d AND thread_id = %d", $admin->uid, 1));
  $this
    ->assertEqual($admin_recipient_count, 3, t('Admin is listed as recipient for every message once.'));
}