You are here

protected function ActionLoopTestCase::triggerActions in SimpleTest 7

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

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

File

tests/actions.test, line 108

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 * FROM {watchdog} WHERE type = 'actions_loop_test' OR type = 'actions' ORDER BY timestamp");
  $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.'));
}