You are here

public function CronQueueTest::testQueueWorkerManagerSafeguard in Drupal 10

Test safeguard against invalid annotations in QueueWorkerManager.

File

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

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']);
}