function CronQueueTest::testQueueWorkerManagerSafeguard

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Kernel/System/CronQueueTest.php \Drupal\Tests\system\Kernel\System\CronQueueTest::testQueueWorkerManagerSafeguard()
  2. 10 core/modules/system/tests/src/Kernel/System/CronQueueTest.php \Drupal\Tests\system\Kernel\System\CronQueueTest::testQueueWorkerManagerSafeguard()

Test safeguard against invalid annotations in QueueWorkerManager.

File

core/modules/system/tests/src/Kernel/System/CronQueueTest.php, line 304

Class

CronQueueTest
Tests the Cron Queue runner.

Namespace

Drupal\Tests\system\Kernel\System

Code

public function testQueueWorkerManagerSafeguard() : void {
    $queue_worker_manager = $this->container
        ->get('plugin.manager.queue_worker');
    $plugin_id = 'test_plugin_id';
    // Ensure if no cron annotation is provided, none is added.
    $definition = [];
    $queue_worker_manager->processDefinition($definition, $plugin_id);
    $this->assertArrayNotHasKey('cron', $definition);
    // Ensure if an empty cron annotation is provided, the default lease time is
    // added.
    $definition = [
        'cron' => [],
    ];
    $queue_worker_manager->processDefinition($definition, $plugin_id);
    $this->assertArrayHasKey('time', $definition['cron']);
    $this->assertEquals(QueueWorkerManagerInterface::DEFAULT_QUEUE_CRON_TIME, $definition['cron']['time']);
    // Ensure if an invalid lease time (less-than 1 second) is provided, it is
    // overridden with the default lease time.
    $definition = [
        'cron' => [
            'time' => 0,
        ],
    ];
    $queue_worker_manager->processDefinition($definition, $plugin_id);
    $this->assertEquals(QueueWorkerManagerInterface::DEFAULT_QUEUE_CRON_TIME, $definition['cron']['time']);
    $definition = [
        'cron' => [
            'time' => -1,
        ],
    ];
    $queue_worker_manager->processDefinition($definition, $plugin_id);
    $this->assertEquals(QueueWorkerManagerInterface::DEFAULT_QUEUE_CRON_TIME, $definition['cron']['time']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.