You are here

protected function ActionLoopTestCase::triggerActions in Drupal 7

Create an infinite loop by causing a watchdog message to be set, which causes the actions to be triggered again, up to actions_max_stack times.

1 call to ActionLoopTestCase::triggerActions()
ActionLoopTestCase::testActionLoop in modules/simpletest/tests/actions.test
Set up a loop with 3 - 12 recursions, and see if it aborts properly.

File

modules/simpletest/tests/actions.test, line 109

Class

ActionLoopTestCase
Test actions executing in a potential loop, and make sure they abort properly.

Code

protected function triggerActions() {
  $this
    ->drupalGet('<front>', array(
    'query' => array(
      'trigger_actions_on_watchdog' => TRUE,
    ),
  ));
  $expected = array();
  $expected[] = 'Triggering action loop';
  for ($i = 1; $i <= variable_get('actions_max_stack', 35); $i++) {
    $expected[] = "Test log #{$i}";
  }
  $expected[] = 'Stack overflow: too many calls to actions_do(). Aborting to prevent infinite recursion.';
  $result = db_query("SELECT message FROM {watchdog} WHERE type = 'actions_loop_test' OR type = 'actions' ORDER BY wid");
  $loop_started = FALSE;
  foreach ($result as $row) {
    $expected_message = array_shift($expected);
    $this
      ->assertEqual($row->message, $expected_message, t('Expected message %expected, got %message.', array(
      '%expected' => $expected_message,
      '%message' => $row->message,
    )));
  }
  $this
    ->assertTrue(empty($expected), t('All expected messages found.'));
}