You are here

public function HookCronTest::testRecentExecution in Entity Share Cron 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/HookCronTest.php \Drupal\Tests\entity_share_cron\Kernel\HookCronTest::testRecentExecution()

Tests if no channels are enqueuend when the interval has not elapsed.

File

tests/src/Kernel/HookCronTest.php, line 161

Class

HookCronTest
Tests the hook_cron() implementation.

Namespace

Drupal\Tests\entity_share_cron\Kernel

Code

public function testRecentExecution() {

  // Adjusts configuration as though a recent synchronization happened.
  $last_run = time();
  $this->config
    ->set('cron_interval', 9999999)
    ->set('cron_last_run', $last_run);

  // Configure some remotes and channels.
  $this->config
    ->set('remotes', [
    'remote1' => [
      'enabled' => TRUE,
      'channels' => [
        'channel1' => [
          'enabled' => TRUE,
          'url' => 'url1',
        ],
      ],
    ],
  ]);

  // Saves changes to configuration.
  $this->config
    ->save();

  // Invokes the hook.
  \entity_share_cron_cron();

  // Checks if the queue is empty.
  $this
    ->assertEquals(0, $this->queue
    ->numberOfItems());
  $this
    ->assertEquals($last_run, $this->config
    ->get('cron_last_run'));
}