You are here

function MessageSubscribeQueueTest::testQueueCron in Message Subscribe 7

Test cron-based queue handling. These are very basic checks that ensure the cron worker callback functions as expected. No formal subscription processing is triggered here.

File

./message_subscribe.test, line 503
Test for the Message subscribe module.

Class

MessageSubscribeQueueTest
Test queue integration.

Code

function testQueueCron() {
  $node = $this->node;
  $message = message_create('foo', array());
  $queue = DrupalQueue::get('message_subscribe');

  // Start with a control case.
  message_subscribe_send_message('node', $node, $message, array(), array());
  $this
    ->assertEqual($queue
    ->numberOfItems(), 1, 'Message item 1 added to queue.');
  $this
    ->cronRun();
  $this
    ->assertEqual($queue
    ->numberOfItems(), 0, 'Message item 1 processed by cron.');

  // Now try a case where the message entity is deleted before any related
  // queue items can be processed.
  message_subscribe_send_message('node', $node, $message, array(), array());
  $this
    ->assertEqual($queue
    ->numberOfItems(), 1, 'Message item 2 added to queue.');
  $message
    ->delete();

  // Assert message was deleted.
  $this
    ->assertFalse(message_load($message->mid), 'Message entity deleted.');
  $this
    ->cronRun();
  $this
    ->assertEqual($queue
    ->numberOfItems(), 0, 'Message item 2 processed by cron.');
}