You are here

public function HookCronTest::testNoRemotesEnabled 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::testNoRemotesEnabled()

Tests when no remotes are enabled.

File

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

Class

HookCronTest
Tests the hook_cron() implementation.

Namespace

Drupal\Tests\entity_share_cron\Kernel

Code

public function testNoRemotesEnabled() {

  // Adjusts configuration to force a synchronization.
  $this->config
    ->set('cron_interval', 1)
    ->set('cron_last_run', -99999);

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

  // 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());
  $last_run = $this->config
    ->get('cron_last_run');
  $this
    ->assertGreaterThan(-99999, $last_run);
  $this
    ->assertLessThanOrEqual(time(), $last_run);
}