public function HookCronTest::testEnqueueChannels in Entity Share Cron 8.2
Same name and namespace in other branches
- 8 tests/src/Kernel/HookCronTest.php \Drupal\Tests\entity_share_cron\Kernel\HookCronTest::testEnqueueChannels()
Tests if channels are enqueued.
File
- tests/
src/ Kernel/ HookCronTest.php, line 51
Class
- HookCronTest
- Tests the hook_cron() implementation.
Namespace
Drupal\Tests\entity_share_cron\KernelCode
public function testEnqueueChannels() {
// Adjusts configuration to force a synchronization.
$this->config
->set('cron_interval', 1);
$this->state
->set('entity_share_cron.cron_last_run', -999999);
// Configuree some remotes and channels.
$this->config
->set('remotes', [
'remote1' => [
'enabled' => FALSE,
'channels' => [
'channel1' => [
'enabled' => FALSE,
'url' => 'url1',
],
],
],
'remote2' => [
'enabled' => TRUE,
'channels' => [
'channel2' => [
'enabled' => TRUE,
'url' => 'url2',
],
'channel3' => [
'enabled' => FALSE,
'url' => 'url3',
],
'channel4' => [
'enabled' => TRUE,
'url' => 'url4',
],
],
],
'remote3' => [
'enabled' => FALSE,
],
'remote4' => [
'enabled' => TRUE,
'channels' => [
'channel5' => [
'enabled' => TRUE,
'url' => 'url5',
],
],
],
]);
// Saves changes to configuration.
$this->config
->save();
// Invokes the hook.
\entity_share_cron_cron();
// Makes assertions.
$this
->assertEquals(3, $this->queue
->numberOfItems());
$item = $this->queue
->claimItem();
$this
->assertEquals('remote2', $item->data['remote_id']);
$this
->assertEquals('channel2', $item->data['channel_id']);
$this
->assertEquals('url2', $item->data['channel_info']['url']);
$item = $this->queue
->claimItem();
$this
->assertEquals('remote2', $item->data['remote_id']);
$this
->assertEquals('channel4', $item->data['channel_id']);
$this
->assertEquals('url4', $item->data['channel_info']['url']);
$item = $this->queue
->claimItem();
$this
->assertEquals('remote4', $item->data['remote_id']);
$this
->assertEquals('channel5', $item->data['channel_id']);
$this
->assertEquals('url5', $item->data['channel_info']['url']);
$last_run = $this->state
->get('entity_share_cron.cron_last_run') ? $this->state
->get('entity_share_cron.cron_last_run') : -99999;
$this
->assertGreaterThan(-99999, $last_run);
$this
->assertLessThanOrEqual(time(), $last_run);
}