function RulesTriggerTestCase::testRecursionPrevention

Same name in other branches
  1. 8.x-3.x d7-tests/rules_test_trigger_case.test \RulesTriggerTestCase::testRecursionPrevention()

Tests preventing recursive rule invocations.

Creates a rule that reacts on node-update then generates a node update that would trigger it itself.

File

tests/rules.test, line 1253

Class

RulesTriggerTestCase
Test triggering rules.

Code

public 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());
}