function EventIntegrationTest::testCronEvent
Test that the cron hook triggers the Rules event listener.
File
-
tests/
src/ Kernel/ EventIntegrationTest.php, line 106
Class
- EventIntegrationTest
- Test for the Symfony event mapping to Rules events.
Namespace
Drupal\Tests\rules\KernelCode
public function testCronEvent() {
$rule = $this->expressionManager
->createRule();
$rule->addCondition('rules_test_true');
$rule->addAction('rules_test_debug_log');
$config_entity = $this->storage
->create([
'id' => 'test_rule',
'events' => [
[
'event_name' => 'rules_system_cron',
],
],
'expression' => $rule->getConfiguration(),
]);
$config_entity->save();
// The logger instance has changed, refresh it.
$this->logger = $this->container
->get('logger.channel.rules_debug');
$this->logger
->addLogger($this->debugLog);
// Run cron.
$this->container
->get('cron')
->run();
// Test that the action in the rule logged something.
$this->assertRulesDebugLogEntryExists('action called');
}