-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change reaction-rule config to save the event with settings #405
Open
milkovsky
wants to merge
11
commits into
fago:8.x-3.x
Choose a base branch
from
milkovsky:feature/RUL-45
base: 8.x-3.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b57e33d
Change rules config to have multiple events.
milkovsky 7d0d7e2
Tests for multiple events.
milkovsky 87dca7d
PR fixes.
milkovsky cb7f762
Code formatting.
milkovsky 6fecbad
Merge branch '8.x-3.x' of github.com:fago/rules into feature/RUL-45
milkovsky 944aa09
After merge fix.
milkovsky 9ead81e
Initialize events [].
milkovsky 8e0c714
Merge branch '8.x-3.x' into feature/RUL-45
milkovsky d179fcf
Fixed expression set in rules handler test.
milkovsky 0c297b6
Merge branch '8.x-3.x' into feature/RUL-45
milkovsky 5eea48c
Fix testMultipleEvents test.
milkovsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ public function testUserLoginEvent() { | |
$config_entity = $this->storage->create([ | ||
'id' => 'test_rule', | ||
'expression_id' => 'rules_rule', | ||
'event' => 'rules_user_login', | ||
'events' => [['event_name' => 'rules_user_login']], | ||
'configuration' => $rule->getConfiguration(), | ||
]); | ||
$config_entity->save(); | ||
|
@@ -81,7 +81,7 @@ public function testUserLogoutEvent() { | |
$config_entity = $this->storage->create([ | ||
'id' => 'test_rule', | ||
'expression_id' => 'rules_rule', | ||
'event' => 'rules_user_logout', | ||
'events' => [['event_name' => 'rules_user_logout']], | ||
'configuration' => $rule->getConfiguration(), | ||
]); | ||
$config_entity->save(); | ||
|
@@ -108,7 +108,7 @@ public function testCronEvent() { | |
$config_entity = $this->storage->create([ | ||
'id' => 'test_rule', | ||
'expression_id' => 'rules_rule', | ||
'event' => 'rules_system_cron', | ||
'events' => [['event_name' => 'rules_system_cron']], | ||
'configuration' => $rule->getConfiguration(), | ||
]); | ||
$config_entity->save(); | ||
|
@@ -134,7 +134,7 @@ public function testSystemLoggerEvent() { | |
$config_entity = $this->storage->create([ | ||
'id' => 'test_rule', | ||
'expression_id' => 'rules_rule', | ||
'event' => 'rules_system_logger_event', | ||
'events' => [['event_name' => 'rules_system_logger_event']], | ||
'configuration' => $rule->getConfiguration(), | ||
]); | ||
$config_entity->save(); | ||
|
@@ -161,7 +161,7 @@ public function testInitEvent() { | |
$config_entity = $this->storage->create([ | ||
'id' => 'test_rule', | ||
'expression_id' => 'rules_rule', | ||
'event' => KernelEvents::REQUEST, | ||
'events' => [['event_name' => KernelEvents::REQUEST]], | ||
'configuration' => $rule->getConfiguration(), | ||
]); | ||
$config_entity->save(); | ||
|
@@ -185,4 +185,38 @@ public function testInitEvent() { | |
$this->assertRulesLogEntryExists('action called'); | ||
} | ||
|
||
/** | ||
* Test that rules config supports multiple events. | ||
*/ | ||
public function testMultipleEvents() { | ||
$rule = $this->expressionManager->createRule(); | ||
$rule->addCondition('rules_test_true'); | ||
$rule->addAction('rules_test_log'); | ||
|
||
$config_entity = $this->storage->create([ | ||
'id' => 'test_rule', | ||
'expression_id' => 'rules_rule', | ||
]); | ||
$config_entity->set('events', [ | ||
['event_name' => 'rules_user_login'], | ||
['event_name' => 'rules_user_logout'], | ||
]); | ||
$config_entity->set('configuration', $rule->getConfiguration()); | ||
$config_entity->save(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should test using the getter also. |
||
|
||
// The logger instance has changed, refresh it. | ||
$this->logger = $this->container->get('logger.channel.rules'); | ||
|
||
$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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice that this works already! |
||
|
||
// Test that the action in the rule logged something. | ||
$this->assertRulesLogEntryExists('action called'); | ||
$this->assertRulesLogEntryExists('action called', 1); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a code smell if we need to document array keys. I think we should use a simple class instead which has this properties + methods documented. We should prevent nested array weirdness when we can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, but can we do that with CMI? I've only seen it save/load arrays.
As alternative, we could use an order array with
which Alex tried initially. Problem there was that we need to have dots in event names (as symfony events use dots), but CMI does not allow dots in config keys. Thus, we'd have to massage the event names and somehow escape/replace dots. That makes it more complicated, also when querying for events etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can file a follow-up to explore using objects instead of event arrays.