You are here

function PrivatemsgGroupsTestCase::testSendMessageToGroup in Privatemsg 7.2

Test sending message to group using GUI.

File

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

Class

PrivatemsgGroupsTestCase
Test cases for the privatemsg_groups module.

Code

function testSendMessageToGroup() {
  $user2 = $this
    ->drupalCreateUser(array(
    'read privatemsg',
    'write privatemsg',
    'view organic groups recipients',
  ));
  og_group('node', $this->group1->nid, array(
    'entity' => $user2->uid,
  ));
  $group_name = $this->group1->title;
  $this
    ->drupalLogin($this->group1_manager);

  // Verify autocomplete feature.
  $json = $this
    ->drupalGet('messages/autocomplete/' . drupal_substr($group_name, 0, 2));
  $autocomplete = (array) json_decode($json);
  $this
    ->assertEqual($autocomplete[$group_name . ', '], $group_name);

  // Access the form through a url that pre-fills the recipient field.
  $this
    ->drupalGet('messages/new/' . _privatemsg_groups_get_group_recipient_type('node') . '_' . $this->group1->nid);

  // Send a message to group1.
  $edit = array(
    'subject' => $this
      ->randomName(10),
    'body[value]' => $this
      ->randomName(50),
  );
  $this
    ->drupalPost(NULL, $edit, t('Send message'));
  $this
    ->assertText(t('A message has been sent to @group (group).', array(
    '@group' => $group_name,
  )));

  // 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 does not see the group.
  $this
    ->assertNoText(t('@group (group)', array(
    '@group' => $group_name,
  )));

  // Reply to the message, only admin should see this.
  $reply1 = array(
    'body[value]' => $this
      ->randomName(50),
  );
  $this
    ->drupalPost(NULL, $reply1, t('Send message'));
  $this
    ->drupalGet('messages');
  $this
    ->assertNoRaw($edit['subject'] . '</a> <span class="marker">new</span>', t('Message is displayed as read'));

  // Login as admin again and check if he sees the response.
  $this
    ->drupalLogin($this->group1_manager);
  $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($reply1['body[value]'], t('Reply1 is displayed'));

  // Reply to the message, all recipients should see this.
  $reply2 = array(
    'body[value]' => $this
      ->randomName(50),
  );
  $this
    ->drupalPost(NULL, $reply2, t('Send message'));

  // Log in as user2 and check that he only sees the messages from admin.
  $this
    ->drupalLogin($user2);
  $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(t('@group (group)', array(
    '@group' => $group_name,
  )));
  $this
    ->assertText($edit['body[value]'], t('Thread starter body is displayed'));
  $this
    ->assertNoText($reply1['body[value]'], t('Reply1 is not displayed'));
  $this
    ->assertText($reply2['body[value]'], t('Reply2 is displayed'));
}