MonitoringCronErrorPluginTest.php in Monitoring 8
File
tests/src/Kernel/MonitoringCronErrorPluginTest.php
View source
<?php
namespace Drupal\Tests\monitoring\Kernel;
use Drupal\ultimate_cron\Entity\CronJob;
class MonitoringCronErrorPluginTest extends MonitoringUnitTestBase {
public static $modules = array(
'node',
'ultimate_cron',
'ultimate_cron_logger_test',
);
public function setup() {
parent::setUp();
$this
->installSchema('ultimate_cron', [
'ultimate_cron_log',
'ultimate_cron_lock',
]);
\Drupal::service('ultimate_cron.discovery')
->discoverCronJobs();
$job = CronJob::load('system_cron');
$job
->disable();
$job
->save();
}
public function testUltimateCronErrorsSensorPlugin() {
$result = $this
->runSensor('ultimate_cron_errors');
$this
->assertEquals(0, $result
->getValue());
\Drupal::state()
->set('ultimate_cron_logger_test_cron_action', 'exception');
\Drupal::service('cron')
->run();
$result = $this
->runSensor('ultimate_cron_errors');
$this
->assertEquals(1, $result
->getValue());
$verbose_output = $result
->getVerboseOutput()['log_entries']['#rows'][0];
$this
->assertTrue($result
->isOk());
$this
->assertEquals('Default cron handler (Ultimate Cron Logger Test)', $verbose_output['name']);
$this
->assertStringContainsString('Test cron exception', $verbose_output['message']);
}
}