I'm working on providing Rules support for the Relation module #1137552: Rules support. Most of the code is just providing entity metadata and thus letting entity api do most of the work with creating new entities. But setting the endpoints requires a bit of custom code, and because of that, I'd like to have to Relation specific tests for the Rules support.
However, whatever I do with a Rule within a test, I can't get it working.
This fairly simple code was as easy as I could make it:
$rule = rules_import('{ "rules_full_test_rule" : {
"LABEL" : "Full test rule",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules" ],
"ON" : [ "node_view" ],
"DO" : [
{ "entity_create" : {
"USING" : {
"type" : "node",
"param_type" : "page",
"param_title" : "Node 1",
"param_author" : [ "site:current-user" ]
},
"PROVIDE" : { "entity_created" : { "node_1" : "Node 1" } }
}
}
]
}
}', $error);
if (!empty($error)) {
$this->verbose('rules_import returned: ' . $error);
}
else {
$this->verbose('Rule imported succesfully');
}
$creation_rule->execute();It fails with:
RulesException: Argument <em class="placeholder">node</em> is missing. in RulesPlugin->setUpState() (line 469 of /var/www/drupal-7.2/sites/all/modules/rules/includes/rules.core.inc).
It's probably something simple that I need to manually initialize or so in the test, but from looking at the tests that are in Rules itself, I can't figure out what I'm missing.
Comments
Comment #1
fagoIt looks like you try to manually execute a reaction rule? Usually, you don't do that but trigger them via rules_invoke_event(). If you want manual execution, you should create a component 'rule'.
Still, for manually executing/triggering a single reaction-rule, you need to pass the parameter as needed for the associated events. $rule->parameterInfo() tells you what is required, but in case of the 'node_view' event you'll need to pass a $node as argument. As the exception tells you. ;)
Comment #3
mitchell commentedUpdated component.