You are here

public function RulesTriggerTestCase::testRecursionPrevention in Rules 7.2

Same name and namespace in other branches
  1. 8.3 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 1252
Rules tests.

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