function RulesTriggerTestCase::testRecursionPrevention

Same name in other branches
  1. 7.x-2.x tests/rules.test \RulesTriggerTestCase::testRecursionPrevention()

Tests preventing recursive rule invocations by creating a rule that reacts on node-update and generates a node update that would trigger it itself.

File

d7-tests/rules_test_trigger_case.test, line 140

Class

RulesTriggerTestCase
Test triggering rules.

Code

function testRecursionPrevention() {
    $rule = $this->createTestRule(FALSE, 'node_update');
    $rule->action('rules_node_make_sticky_action');
    $rule->integrityCheck()
        ->save();
    // Now trigger the rule.
    $node = $this->drupalCreateNode(array(
        'type' => 'page',
        'sticky' => 0,
        'status' => 0,
    ));
    node_save($node);
    $text = RulesTestCase::t('Not evaluating reaction rule %label to prevent recursion.', array(
        'label' => $rule->name,
    ));
    
    //debug(RulesLog::logger()->render());
    $this->assertTrue(strpos(RulesLog::logger()->render(), $text) !== FALSE, "Recursion prevented.");
    
    //debug(RulesLog::logger()->render());
}