You are here

function PrivatemsgGroupsTestCase::testSendMessagetoGroupCron in Privatemsg 7.2

Test batch sending using API and cron.

File

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

Class

PrivatemsgGroupsTestCase
Test cases for the privatemsg_groups module.

Code

function testSendMessagetoGroupCron() {
  variable_set('privatemsg_recipient_small_threshold', 20);
  variable_set('privatemsg_cron_recipient_per_run', 20);

  // Create 26 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,
    ));
  }
  $recipient = clone $this->group1;
  $recipient->recipient = $this->group1->nid;
  $recipient->type = _privatemsg_groups_get_group_recipient_type('node');
  privatemsg_new_thread(array(
    $recipient,
  ), $subject = $this
    ->randomName(10), $body = $this
    ->randomName(50), array(
    'author' => $this->group1_manager,
  ));

  // Run cron.
  privatemsg_cron();

  // Test a few recipients to see if they received the message.
  foreach (array(
    0,
    5,
    17,
  ) as $uid) {
    $this
      ->drupalLogin($users[$uid]);
    $this
      ->drupalGet('messages');
    $this
      ->assertRaw($subject . '</a> <span class="marker">new</span>', t('Message is displayed as new'));
    $this
      ->clickLink($subject);
    $this
      ->assertText($body, t('Thread starter body displayed.'));
  }

  // Make sure that user 20 has not yet received the message.
  $this
    ->drupalLogin($users[20]);
  $this
    ->drupalGet('messages');
  $this
    ->assertNoText($subject, t('Message is not yet displayed for this user'));

  // Run cron again.
  privatemsg_cron();

  // Test that the remaining recipients do now see the message too.
  foreach (array(
    20,
    24,
  ) as $uid) {
    $this
      ->drupalLogin($users[$uid]);
    $this
      ->drupalGet('messages');
    $this
      ->assertRaw($subject . '</a> <span class="marker">new</span>', t('Message is displayed as new'));
    $this
      ->clickLink($subject);
    $this
      ->assertText($body, t('Thread starter body displayed.'));
  }
}