You are here

public function AdminSettingsTest::testSkipQueueOnCron in Sparkpost email 8.2

Test that queue is not processed on cron, if indicated by settings.

File

tests/src/Functional/AdminSettingsTest.php, line 89

Class

AdminSettingsTest
Test basic functionality.

Namespace

Drupal\Tests\sparkpost\Functional

Code

public function testSkipQueueOnCron() {
  \Drupal::configFactory()
    ->getEditable('sparkpost.settings')
    ->set('skip_cron', FALSE)
    ->set('async', TRUE)
    ->save();

  /** @var \Drupal\Core\Queue\QueueInterface $queue */
  $queue = \Drupal::queue('sparkpost_send');

  // Create a dummy item.
  $queue
    ->createItem($this
    ->createDummyMessage());
  self::assertEquals($queue
    ->numberOfItems(), 1);

  // Run cron.

  /** @var \Drupal\Core\Cron $cron */
  $cron = \Drupal::service('cron');
  $cron
    ->run();

  // Should have processed the item.
  self::assertEquals($queue
    ->numberOfItems(), 0);
  \Drupal::configFactory()
    ->getEditable('sparkpost.settings')
    ->set('skip_cron', TRUE)
    ->save();

  // We also need to clear the cache.
  \Drupal::service('plugin.cache_clearer')
    ->clearCachedDefinitions();
  $queue
    ->createItem($this
    ->createDummyMessage());
  self::assertEquals($queue
    ->numberOfItems(), 1);

  // Run cron.
  $cron
    ->run();

  // Should not have processed the item.
  self::assertEquals($queue
    ->numberOfItems(), 1);
}