public function MonitoringCoreKernelTest::testCronLastRunAgeSensorPlugin in Monitoring 8
Tests cron last run age sensor.
See also
\Drupal\monitoring\Plugin\monitoring\SensorPlugin\CronLastRunAgeSensorPlugin
File
- tests/
src/ Kernel/ MonitoringCoreKernelTest.php, line 78
Class
- MonitoringCoreKernelTest
- Kernel tests for the core pieces of monitoring.
Namespace
Drupal\Tests\monitoring\KernelCode
public function testCronLastRunAgeSensorPlugin() {
// Fake cron run 1d+1s ago.
$time_shift = 60 * 60 * 24 + 1;
\Drupal::state()
->set('system.cron_last', \Drupal::time()
->getRequestTime() - $time_shift);
$result = $this
->runSensor('core_cron_last_run_age');
$this
->assertTrue($result
->isWarning());
$this
->assertEquals($time_shift, $result
->getValue());
// Fake cron run from 3d+1s ago.
$time_shift = 60 * 60 * 24 * 3 + 1;
\Drupal::state()
->set('system.cron_last', \Drupal::time()
->getRequestTime() - $time_shift);
$result = $this
->runSensor('core_cron_last_run_age');
$this
->assertTrue($result
->isCritical());
$this
->assertEquals($time_shift, $result
->getValue());
// Run cron and check sensor.
\Drupal::service('cron')
->run();
$result = $this
->runSensor('core_cron_last_run_age');
$this
->assertTrue($result
->isOk());
$this
->assertEquals(0, $result
->getValue());
}