You are here

function PrivatemsgGroupsTestCase::testSendMessagetoGroupBatch in Privatemsg 7.2

Test batch sending from GUI.

File

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

Class

PrivatemsgGroupsTestCase
Test cases for the privatemsg_groups module.

Code

function testSendMessagetoGroupBatch() {
  variable_set('privatemsg_recipient_small_threshold', 20);

  // Create 25 users (more than are allowed to be process directly).
  $users = array();
  for ($i = 0; $i < 25; $i++) {
    $users[$i] = $this
      ->drupalCreateUser(array(
      'read privatemsg',
      'write privatemsg',
    ));

    // Add user to group1.
    og_group('node', $this->group1->nid, array(
      'entity' => $users[$i]->uid,
    ));
  }
  $this
    ->drupalLogin($this->group1_manager);

  // Send a message to the group shared by all users.
  $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,
  )));

  // Test a few recipients to see if they all received the message.
  foreach ($users as $user) {
    $this
      ->drupalLogin($user);
    $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.'));
  }
}