protected function LoopTest::triggerActions

Loops watchdog messages up to actions_max_stack times.

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

1 call to LoopTest::triggerActions()
LoopTest::testActionLoop in drupal/core/modules/action/lib/Drupal/action/Tests/LoopTest.php
Sets up a loop with 3 - 12 recursions, and sees if it aborts properly.

File

drupal/core/modules/action/lib/Drupal/action/Tests/LoopTest.php, line 64
Definition of Drupal\action\Tests\LoopTest.

Class

LoopTest
Tests aborting of actions executing in a potential loop.

Namespace

Drupal\action\Tests

Code

protected function triggerActions() {
  $this
    ->drupalGet('<front>', array(
    'query' => array(
      'trigger_action_on_watchdog' => $this->aid,
    ),
  ));
  $expected = array();
  $expected[] = 'Triggering action loop';
  $recursion_limit = config('action.settings')
    ->get('recursion_limit');
  for ($i = 1; $i <= $recursion_limit; $i++) {
    $expected[] = "Test log #{$i}";
  }
  $expected[] = 'Stack overflow: recursion limit for actions_do() has been reached. Stack is limited by %limit calls.';
  $result = db_query("SELECT message FROM {watchdog} WHERE type = 'action_loop_test' OR type = 'action' ORDER BY wid");
  $loop_started = FALSE;
  foreach ($result as $row) {
    $expected_message = array_shift($expected);
    $this
      ->assertEqual($row->message, $expected_message, format_string('Expected message %expected, got %message.', array(
      '%expected' => $expected_message,
      '%message' => $row->message,
    )));
  }
  $this
    ->assertTrue(empty($expected), 'All expected messages found.');
}