public function QueueTest::testQueueCron in Message Subscribe 8
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
- tests/
src/ Kernel/ QueueTest.php, line 123
Class
- QueueTest
- Test queue integration.
Namespace
Drupal\Tests\message_subscribe\KernelCode
public function testQueueCron() {
$node = $this->node;
$message = Message::create([
'template' => 'foo',
]);
$queue = \Drupal::queue('message_subscribe');
// Start with a control case.
$this->messageSubscribers
->sendMessage($node, $message, [], []);
$this
->assertEquals($queue
->numberOfItems(), 1, 'Message item 1 added to queue.');
$this->container
->get('cron')
->run();
$this
->assertEquals($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.
$this->messageSubscribers
->sendMessage($node, $message, [], []);
$this
->assertEquals($queue
->numberOfItems(), 1, 'Message item 2 added to queue.');
$message
->delete();
// Assert message was deleted.
$this
->assertNull($message
->load($message
->id()), 'Message entity deleted.');
$this->container
->get('cron')
->run();
$this
->assertEquals($queue
->numberOfItems(), 0, 'Message item 2 processed by cron.');
}