You are here

function PrivatemsgRolesTestCase::testSendMessagetoRoleBatch in Privatemsg 7

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

File

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

Class

PrivatemsgRolesTestCase
Test cases for the privatemsg_roles module.

Code

function testSendMessagetoRoleBatch() {
  $admin = $this
    ->drupalCreateUser(array(
    'read privatemsg',
    'write privatemsg',
    'write privatemsg to roles',
  ));
  $user1 = $this
    ->drupalCreateUser(array(
    'read privatemsg',
    'write privatemsg',
  ));
  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();

    // Add role of user 1 to user 2;
    $edit = array(
      'roles' => $users[$i]->roles + $user1->roles,
    );
    user_save($users[$i], $edit);
  }
  $this
    ->drupalLogin($admin);

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

  // Test a few recipients to see if they all recieved 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.'));
  }
}