summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorwebchick <webchick@24967.no-reply.drupal.org>2011-08-30 01:07:28 -0700
committerwebchick <webchick@24967.no-reply.drupal.org>2011-08-30 01:07:28 -0700
commit3379da9d7008c327115f49c47c2436e1e8ee73cd (patch)
tree6bd7f1bf97bcdad554848aceee25c4e35fb1cd3e /modules
parentd4c02d841c69cb8e83d9a69d9d2d105ed3a1f1d7 (diff)
downloadbrdo-3379da9d7008c327115f49c47c2436e1e8ee73cd.tar.gz
brdo-3379da9d7008c327115f49c47c2436e1e8ee73cd.tar.bz2
Issue #978944 by Aron Novak, chx, ksenzee: Fixed Handle exceptions thrown in cron.
Diffstat (limited to 'modules')
-rw-r--r--modules/simpletest/tests/common_test.module13
-rw-r--r--modules/simpletest/tests/common_test_cron_helper.info6
-rw-r--r--modules/simpletest/tests/common_test_cron_helper.module17
-rw-r--r--modules/system/system.test17
4 files changed, 53 insertions, 0 deletions
diff --git a/modules/simpletest/tests/common_test.module b/modules/simpletest/tests/common_test.module
index 9b6178804..c400eaed1 100644
--- a/modules/simpletest/tests/common_test.module
+++ b/modules/simpletest/tests/common_test.module
@@ -225,3 +225,16 @@ function common_test_js_and_css_querystring() {
drupal_add_css('/' . drupal_get_path('module', 'node') . '/node-fake.css?arg1=value1&arg2=value2');
return '';
}
+
+/**
+ * Implements hook_cron().
+ *
+ * System module should handle if a module does not catch an exception and keep
+ * cron going.
+ *
+ * @see common_test_cron_helper()
+ *
+ */
+function common_test_cron() {
+ throw new Exception(t('Uncaught exception'));
+}
diff --git a/modules/simpletest/tests/common_test_cron_helper.info b/modules/simpletest/tests/common_test_cron_helper.info
new file mode 100644
index 000000000..ce1a6326f
--- /dev/null
+++ b/modules/simpletest/tests/common_test_cron_helper.info
@@ -0,0 +1,6 @@
+name = "Common Test Cron Helper"
+description = "Helper module for CronRunTestCase::testCronExceptions()."
+package = Testing
+version = VERSION
+core = 7.x
+hidden = TRUE
diff --git a/modules/simpletest/tests/common_test_cron_helper.module b/modules/simpletest/tests/common_test_cron_helper.module
new file mode 100644
index 000000000..94a2b2c43
--- /dev/null
+++ b/modules/simpletest/tests/common_test_cron_helper.module
@@ -0,0 +1,17 @@
+<?php
+/**
+ * @file
+ * Helper module for the testCronExceptions in addition to common_test module.
+ */
+
+/**
+ * Implements hook_cron().
+ *
+ * common_test_cron() throws an exception, but the execution should reach this
+ * function as well.
+ *
+ * @see common_test_cron()
+ */
+function common_test_cron_helper_cron() {
+ variable_set('common_test_cron', 'success');
+}
diff --git a/modules/system/system.test b/modules/system/system.test
index f273bc7d2..d482afa22 100644
--- a/modules/system/system.test
+++ b/modules/system/system.test
@@ -695,6 +695,10 @@ class CronRunTestCase extends DrupalWebTestCase {
);
}
+ function setUp() {
+ parent::setUp(array('common_test', 'common_test_cron_helper'));
+ }
+
/**
* Test cron runs.
*/
@@ -799,6 +803,19 @@ class CronRunTestCase extends DrupalWebTestCase {
$this->assertTrue(file_exists($perm_old->uri), t('Old permanent file was correctly ignored.'));
$this->assertTrue(file_exists($perm_new->uri), t('New permanent file was correctly ignored.'));
}
+
+ /**
+ * Make sure exceptions thrown on hook_cron() don't affect other modules.
+ */
+ function testCronExceptions() {
+ variable_del('common_test_cron');
+ // The common_test module throws an exception. If it isn't caught, the tests
+ // won't finish successfully.
+ // The common_test_cron_helper module sets the 'common_test_cron' variable.
+ $this->cronRun();
+ $result = variable_get('common_test_cron');
+ $this->assertEqual($result, 'success', t('Cron correctly handles exceptions thrown during hook_cron() invocations.'));
+ }
}
class AdminMetaTagTestCase extends DrupalWebTestCase {