You are here

function PrivatemsgGroupsTestCase::testSendMessageToGroupBlocked in Privatemsg 7.2

Test sending message to group when some members blocked the sender.

File

privatemsg_groups/privatemsg_groups.test, line 281
This file contains tests for the privatemsg groups module

Class

PrivatemsgGroupsTestCase
Test cases for the privatemsg_groups module.

Code

function testSendMessageToGroupBlocked() {
  $user2 = $this
    ->drupalCreateUser(array(
    'read privatemsg',
    'write privatemsg',
  ));

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

  // Send a message to the group of user 1 and 2.
  $edit = array(
    'recipient' => $this->group1->title . '[group]',
    '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 @group (group).', array(
    '@group' => $this->group1->title,
  )));

  // Log in as user1 and check that the message is listed, is marked as new
  // and can be marked as read.
  $this
    ->drupalLogin($this->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 group recipient.
  $this
    ->assertNoText(t('@group (group)', array(
    '@group' => $this->group1->title,
  )));

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