summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-08-22 16:16:19 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-08-22 16:16:19 +0000
commitcf5618753251e24b48914329cab158a694005513 (patch)
tree78f2ca889e0d132cbfb67583c401fe3852428e3c /modules
parent4c028a19fbe9d5fc81f21bdce862f6c74a61b7ee (diff)
downloadbrdo-cf5618753251e24b48914329cab158a694005513.tar.gz
brdo-cf5618753251e24b48914329cab158a694005513.tar.bz2
#296322 follow-up. It's extremely helpful when I remember to commit ALL files. :P
Diffstat (limited to 'modules')
-rw-r--r--modules/simpletest/tests/actions_loop_test.info8
-rw-r--r--modules/simpletest/tests/actions_loop_test.install12
-rw-r--r--modules/simpletest/tests/actions_loop_test.module101
3 files changed, 121 insertions, 0 deletions
diff --git a/modules/simpletest/tests/actions_loop_test.info b/modules/simpletest/tests/actions_loop_test.info
new file mode 100644
index 000000000..b842bbf6b
--- /dev/null
+++ b/modules/simpletest/tests/actions_loop_test.info
@@ -0,0 +1,8 @@
+; $Id$
+name = Actions loop test
+description = Support module for action loop testing.
+package = Testing
+version = VERSION
+core = 7.x
+files[] = actions_loop_test.module
+hidden = TRUE
diff --git a/modules/simpletest/tests/actions_loop_test.install b/modules/simpletest/tests/actions_loop_test.install
new file mode 100644
index 000000000..cd6582d52
--- /dev/null
+++ b/modules/simpletest/tests/actions_loop_test.install
@@ -0,0 +1,12 @@
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_install().
+ */
+function actions_loop_test_install() {
+ db_update('system')
+ ->fields(array('weight' => 1))
+ ->condition('name', 'actions_loop_test')
+ ->execute();
+}
diff --git a/modules/simpletest/tests/actions_loop_test.module b/modules/simpletest/tests/actions_loop_test.module
new file mode 100644
index 000000000..58b47fd8b
--- /dev/null
+++ b/modules/simpletest/tests/actions_loop_test.module
@@ -0,0 +1,101 @@
+<?php
+// $Id$
+
+/**
+ * Implement hook_hook_info().
+ */
+function actions_loop_test_hook_info() {
+ return array(
+ 'actions_loop_test' => array(
+ 'watchdog' => array(
+ 'run' => array(
+ 'runs when' => t('When a message is logged'),
+ ),
+ ),
+ ),
+ );
+}
+
+/**
+ * Implement hook_watchdog().
+ */
+function actions_loop_test_watchdog(array $log_entry) {
+ // If the triggering actions are not explicitly enabled, abort.
+ if (empty($_GET['trigger_actions_on_watchdog'])) {
+ return;
+ }
+ // Get all the action ids assigned to the trigger on the watchdog hook's
+ // "run" event.
+ $aids = _trigger_get_hook_aids('watchdog', 'run');
+ // We can pass in any applicable information in $context. There isn't much in
+ // this case, but we'll pass in the hook name and the operation name as the
+ // bare minimum.
+ $context = array(
+ 'hook' => 'watchdog',
+ 'op' => 'run',
+ );
+ // Fire the actions on the associated object ($log_entry) and the context
+ // variable.
+ actions_do(array_keys($aids), $log_entry, $context);
+}
+
+/**
+ * Implement hook_init().
+ */
+function actions_loop_test_init() {
+ if (!empty($_GET['trigger_actions_on_watchdog'])) {
+ watchdog_skip_semaphore('actions_loop_test', 'Triggering action loop');
+ }
+}
+
+/**
+ * Implement hook_action_info().
+ */
+function actions_loop_test_action_info() {
+ return array(
+ 'actions_loop_test_log' => array(
+ 'description' => t('Write a message to the log.'),
+ 'type' => 'system',
+ 'configurable' => FALSE,
+ 'hooks' => array(
+ 'any' => TRUE,
+ )
+ ),
+ );
+}
+
+/**
+ * Write a message to the log.
+ */
+function actions_loop_test_log() {
+ $count = &drupal_static(__FUNCTION__, 0);
+ $count++;
+ watchdog_skip_semaphore('actions_loop_test', "Test log #$count");
+}
+
+/**
+ * Replacement of the watchdog() function that eliminates the use of semaphores
+ * so that we can test the abortion of an action loop.
+ */
+function watchdog_skip_semaphore($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) {
+ global $user, $base_root;
+
+ // Prepare the fields to be logged
+ $log_entry = array(
+ 'type' => $type,
+ 'message' => $message,
+ 'variables' => $variables,
+ 'severity' => $severity,
+ 'link' => $link,
+ 'user' => $user,
+ 'request_uri' => $base_root . request_uri(),
+ 'referer' => $_SERVER['HTTP_REFERER'],
+ 'ip' => ip_address(),
+ 'timestamp' => REQUEST_TIME,
+ );
+
+ // Call the logging hooks to log/process the message
+ foreach (module_implements('watchdog') as $module) {
+ module_invoke($module, 'watchdog', $log_entry);
+ }
+}