public function EventIntegrationTest::testUserLoginEvent in Rules 8.3
Test that the user login hook triggers the Rules event listener.
File
- tests/
src/ Kernel/ EventIntegrationTest.php, line 50
Class
- EventIntegrationTest
- Test for the Symfony event mapping to Rules events.
Namespace
Drupal\Tests\rules\KernelCode
public function testUserLoginEvent() {
$rule = $this->expressionManager
->createRule();
$rule
->addCondition('rules_test_true');
$rule
->addAction('rules_test_debug_log', ContextConfig::create()
->map('message', 'account.name.0.value'));
$config_entity = $this->storage
->create([
'id' => 'test_rule',
'events' => [
[
'event_name' => 'rules_user_login',
],
],
'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 rule.
rules_user_login($account);
// Test that the action in the rule logged something.
$this
->assertRulesDebugLogEntryExists('test_user');
}