Tests for checking the actions system within Backdrop.
<?php /** * @file * Tests for checking the actions system within Backdrop. */ /** * Test actions executing in a potential loop, and make sure they abort properly. */ class ActionLoopTestCase extends BackdropWebTestCase { protected $profile = 'testing'; function setUp() { parent::setUp('dblog', 'actions_loop_test'); } /** * Set up a loop with 3 - 12 recursions, and see if it aborts properly. */ function testActionLoop() { // Delete any existing watchdog messages to clear the plethora of // "Action added" messages from when Backdrop was installed. db_delete('watchdog')->execute(); // To prevent this test from failing when xdebug is enabled, the maximum // recursion level should be kept low enough to prevent the xdebug // infinite recursion protection mechanism from aborting the request. // See http://drupal.org/node/587634. config_set('system.core', 'action_recursion_limit', 7); $this->triggerActions(); } /** * 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. */ protected function triggerActions() { $this->backdropGet('<front>', array('query' => array('trigger_actions_on_watchdog' => 'actions_loop_test_log'))); $expected = array(); $expected[] = 'Triggering action loop'; $recursion_limit = config_get('system.core', 'action_recursion_limit'); for ($i = 1; $i <= $recursion_limit; $i++) { $expected[] = "Test log #$i"; } $expected[] = 'Stack overflow: recursion limit for actions_execute() has been reached. Stack is limited by %limit calls.'; $result = db_query("SELECT message FROM {watchdog} WHERE type = 'actions_loop_test' OR type = 'actions' ORDER BY wid"); 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.')); } }