function RulesTriggerTestCase::testVariableHandler in Rules 8.3
Same name and namespace in other branches
- 7.2 tests/rules.test \RulesTriggerTestCase::testVariableHandler()
Test a rule using a handler to load a variable.
File
- d7-tests/
rules_test_trigger_case.test, line 90 - Rules 7.x tests.
Class
- RulesTriggerTestCase
- Test triggering rules.
Code
function testVariableHandler() {
$node = $this
->drupalCreateNode(array(
'type' => 'page',
'sticky' => 0,
'status' => 0,
));
$rule = $this
->createTestRule(FALSE, 'node_update');
$rule
->action('rules_node_publish_action_save', array(
'node:select' => 'node_unchanged',
));
// Test without recursion prevention to make sure recursive invocations
// work right too. This rule won't ran in an infinite loop anyway.
$rule->recursion = TRUE;
$rule->label = 'rule 1';
$rule
->integrityCheck()
->save();
$node->status = 0;
$node->sticky = 1;
node_save($node);
RulesLog::logger()
->checkLog();
entity_get_controller('node')
->resetCache();
$node = node_load($node->nid);
$this
->assertFalse($node->sticky, 'Parameter has been loaded and saved.');
$this
->assertTrue($node->status, 'Action has been executed.');
// Ensure the rule was evaluated a second time
$text = RulesLog::logger()
->render();
$msg = RulesTestCase::t('Evaluating conditions of rule %rule 1', array(
'rule 1',
));
$pos = strpos($text, $msg);
$pos = $pos !== FALSE ? strpos($text, $msg, $pos) : FALSE;
$this
->assertTrue($pos !== FALSE, "Recursion prevented.");
//debug(RulesLog::logger()->render());
}