public function RulesTriggerTestCase::testVariableHandler in Rules 7.2
Same name and namespace in other branches
- 8.3 d7-tests/rules_test_trigger_case.test \RulesTriggerTestCase::testVariableHandler()
Tests a rule using a handler to load a variable.
File
- tests/
rules.test, line 1192 - Rules tests.
Class
- RulesTriggerTestCase
- Test triggering rules.
Code
public 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());
}