function MessageSubscribeQueueTest::testQueue in Message Subscribe 7
Test base queue processing logic.
File
- ./
message_subscribe.test, line 449 - Test for the Message subscribe module.
Class
- MessageSubscribeQueueTest
- Test queue integration.
Code
function testQueue() {
$node = $this->node;
$message = message_create('foo', array());
$subscribe_options = array();
$subscribe_options['save message'] = FALSE;
try {
$message = message_subscribe_send_message('node', $node, $message, array(), $subscribe_options);
$this
->fail('Can add a non-saved message to the queue.');
} catch (Exception $e) {
$this
->pass('Cannot add a non-saved message to the queue.');
}
// Assert message was saved and added to queue.
$uids = array_fill(1, 10, array());
$subscribe_options = array(
'uids' => $uids,
'skip context' => TRUE,
'range' => 3,
);
$queue = DrupalQueue::get('message_subscribe');
$this
->assertEqual($queue
->numberOfItems(), 0, 'Queue is empty');
message_subscribe_send_message('node', $node, $message, array(), $subscribe_options);
$this
->assertTrue($message->mid, 'Message was saved');
$this
->assertEqual($queue
->numberOfItems(), 1, 'Message added to queue.');
// Assert queue-item is processed and updated. We mock subscription
// of users to the message. It will not be sent, as the default
// notifier is disabled.
$item = $queue
->claimItem();
$item_id = $item->item_id;
// Add the queue information, and the user IDs to process.
$subscribe_options['queue'] = array(
'uids' => $uids,
'item' => $item,
'end time' => FALSE,
);
message_subscribe_send_message('node', $node, $message, array(), $subscribe_options);
// Reclaim the new item, and assert the "last UID" was updated.
$item = $queue
->claimItem();
$this
->assertNotEqual($item_id, $item->item_id, 'Queue item was updated.');
$this
->assertEqual($item->data['subscribe_options']['last uid'], 3, 'Last processed user ID was updated.');
}