function EventIntegrationTest::testUserLogoutEvent
Test that the user logout hook triggers the Rules event listener.
File
-
tests/
src/ Kernel/ EventIntegrationTest.php, line 79
Class
- EventIntegrationTest
- Test for the Symfony event mapping to Rules events.
Namespace
Drupal\Tests\rules\KernelCode
public function testUserLogoutEvent() {
$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_user_logout',
],
],
'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 = $this->container
->get('current_user');
// Invoke the hook manually which should trigger the rule.
rules_user_logout($account);
// Test that the action in the rule logged something.
$this->assertRulesDebugLogEntryExists('action called');
}