You are here

function PrivatemsgRolesTestCase::testSendMessageToRoleBlocked in Privatemsg 7

Same name and namespace in other branches
  1. 6.2 privatemsg_roles/privatemsg_roles.test \PrivatemsgRolesTestCase::testSendMessageToRoleBlocked()
  2. 7.2 privatemsg_roles/privatemsg_roles.test \PrivatemsgRolesTestCase::testSendMessageToRoleBlocked()

File

privatemsg_roles/privatemsg_roles.test, line 223
This file contains tests for the privatemsg roles module

Class

PrivatemsgRolesTestCase
Test cases for the privatemsg_roles module.

Code

function testSendMessageToRoleBlocked() {
  $admin = $this
    ->drupalCreateUser(array(
    'read privatemsg',
    'write privatemsg',
    'write privatemsg to roles',
  ));
  $user1 = $this
    ->drupalCreateUser(array(
    'read privatemsg',
    'write privatemsg',
  ));
  $user2 = $this
    ->drupalCreateUser();

  // Add role of user 1 to user 2;
  $edit = array(
    'roles' => $user2->roles + $user1->roles,
  );
  user_save($user2, $edit);

  // Block admin as user 2.
  $this
    ->drupalLogin($user2);
  $this
    ->drupalPost('messages/blocked', array(
    'name' => $admin->name,
  ), t('Block user'));
  $this
    ->drupalLogin($admin);

  // Send a message to the role of user 1 and 2.
  $edit = array(
    'recipient' => user_role_load($user1->roles[4])->name . '[role]',
    'subject' => $this
      ->randomName(10),
    'body[value]' => $this
      ->randomName(50),
  );
  $this
    ->drupalPost('messages/new', $edit, t('Send message'));
  $this
    ->assertText(t('A message has been sent to @role (role).', array(
    '@role' => user_role_load($user1->roles[4])->name,
  )));

  // Log in as user1 and check that the message is listed, is marked as new
  // and can be marked as read.
  $this
    ->drupalLogin($user1);
  $this
    ->drupalGet('messages');
  $this
    ->assertRaw($edit['subject'] . '</a> <span class="marker">new</span>', t('Message is displayed as new'));
  $this
    ->clickLink($edit['subject']);
  $this
    ->assertText($edit['body[value]'], t('Thread starter body displayed.'));

  // Make sure that the user doesn't see the role recipient.
  $this
    ->assertNoText(t('@role (role)', array(
    '@role' => user_role_load($user1->roles[4])->name,
  )));

  // Log in as user2 and make sure that he didn't received the messages
  // as he blocks admin.
  $this
    ->drupalLogin($user2);
  $this
    ->drupalGet('messages');
  $this
    ->assertNoText($edit['subject'], t('Message is not displayed'));
}