summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-08-22 15:35:36 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-08-22 15:35:36 +0000
commitbfb487627efcfff7a091aee85a7696dde5477188 (patch)
treed83080e7c93aa92abc683c694ae5e68dc99ca636 /modules/simpletest/tests
parenta3215984932bc74ebd3514544fa11a0a536360bc (diff)
downloadbrdo-bfb487627efcfff7a091aee85a7696dde5477188.tar.gz
brdo-bfb487627efcfff7a091aee85a7696dde5477188.tar.bz2
#296322 by cwgordon7 andSenpai: Fix horribly broken trigger module and add tests so we don't do it anymore.
Diffstat (limited to 'modules/simpletest/tests')
-rw-r--r--modules/simpletest/tests/actions.test64
1 files changed, 63 insertions, 1 deletions
diff --git a/modules/simpletest/tests/actions.test b/modules/simpletest/tests/actions.test
index 6619c24d3..5d1c52d56 100644
--- a/modules/simpletest/tests/actions.test
+++ b/modules/simpletest/tests/actions.test
@@ -6,7 +6,7 @@ class ActionsConfigurationTestCase extends DrupalWebTestCase {
return array(
'name' => 'Actions configuration',
'description' => 'Tests complex actions configuration by adding, editing, and deleting a complex action.',
- 'group' => 'System',
+ 'group' => 'Actions',
);
}
@@ -61,3 +61,65 @@ class ActionsConfigurationTestCase extends DrupalWebTestCase {
$this->assertFalse($exists, t('Make sure the action is gone from the database after being deleted.'));
}
}
+
+/**
+ * Test actions executing in a potential loop, and make sure they abort properly.
+ */
+class ActionLoopTestCase extends DrupalWebTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => 'Actions executing in a potentially infinite loop',
+ 'description' => 'Tests actions executing in a loop, and makes sure they abort properly.',
+ 'group' => 'Actions',
+ );
+ }
+
+ function setUp() {
+ parent::setUp('dblog', 'trigger', 'actions_loop_test');
+ }
+
+ /**
+ * Set up a loop with 10-50 recursions, and see if it aborts properly.
+ */
+ function testActionLoop() {
+ $user = $this->drupalCreateUser(array('administer actions'));
+ $this->drupalLogin($user);
+
+ $hash = md5('actions_loop_test_log');
+ $edit = array('aid' => $hash);
+ $this->drupalPost('admin/structure/trigger/actions_loop_test', $edit, t('Assign'));
+
+ // Delete any existing watchdog messages to clear the plethora of
+ // "Action added" messages from when Drupal was installed.
+ db_delete('watchdog')->execute();
+ $this->triggerActions();
+
+ // Clear the log again for another test, this time with a random maximum.
+ db_delete('watchdog')->execute();
+ variable_set('actions_max_stack', mt_rand(10, 50));
+ $this->triggerActions();
+ }
+
+ /**
+ * 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.
+ */
+ 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;
+ while ($row = db_fetch_object($result)) {
+
+ $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.'));
+ }
+}