You are here

public function TestNotifyBatch::testBatchSizeThree in Notify 7

File

./notify.test, line 516
Automated tests for notify.

Class

TestNotifyBatch

Code

public function testBatchSizeThree() {

  // Set up notify environment.
  variable_set('notify_attempts', 5);
  variable_set('notify_include_updates', 0);
  variable_set('notify_reg_default', 1);
  variable_set('notify_period', 86400);
  variable_set('notify_send_hour', 9);
  variable_set('notify_batchsize', 3);
  $now = REQUEST_TIME;
  variable_set('notify_send_start', 0);

  // We haven't started
  $tt = $now - 86400;
  variable_set('notify_send_last', $tt);

  // Last was yesterday.
  variable_set('notify_cron_next', 0);

  // Cron reset
  $this
    ->createContent(3);
  $this
    ->cronRun();

  //  3
  // Create a race condition, new post during cron.
  sleep(5);
  $this
    ->createContent(1);
  $this
    ->cronRun();

  //  6
  $this
    ->cronRun();

  //  9
  $this
    ->cronRun();

  // 12
  $this
    ->cronRun();

  // 15
  $this
    ->cronRun();

  // 18
  $this
    ->cronRun();

  // 20
  $this
    ->cronRun();

  // 20
  $this
    ->cronRun();

  // 20
  $mails = $this
    ->drupalGetMails();
  $howmany = count($mails);
  $this
    ->assertEqual($howmany, 20, 'Twenty emails are sent.');
  variable_set('notify_period', 0);
  $this
    ->cronRun();

  // 20
  $mails = $this
    ->drupalGetMails();

  /*
  if ($mails) {
    debug($mails[0], '$mail[0]');
    debug($mails[19], '$mail[19]');
    debug($mails[20], '$mail[20]');
  }
  */
  $howmany = count($mails);
  $this
    ->assertEqual($howmany, 23, 'Twentythree emails are sent.');
}