function EventIntegrationTest::testMultipleEvents
Test that rules config supports multiple events.
File
-
tests/
src/ Kernel/ EventIntegrationTest.php, line 231
Class
- EventIntegrationTest
- Test for the Symfony event mapping to Rules events.
Namespace
Drupal\Tests\rules\KernelCode
public function testMultipleEvents() {
$rule = $this->expressionManager
->createRule();
$rule->addCondition('rules_test_true');
$rule->addAction('rules_test_debug_log');
$config_entity = $this->storage
->create([
'id' => 'test_rule',
]);
$config_entity->set('events', [
[
'event_name' => 'rules_user_login',
],
[
'event_name' => 'rules_user_logout',
],
]);
$config_entity->set('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);
$account = User::create([
'name' => 'test_user',
]);
// Invoke the hook manually which should trigger the rules_user_login event.
rules_user_login($account);
// Invoke the hook manually which should trigger the rules_user_logout
// event.
rules_user_logout($account);
// Test that the action in the rule logged something.
$this->assertRulesDebugLogEntryExists('action called');
$this->assertRulesDebugLogEntryExists('action called', 1);
}