summaryrefslogtreecommitdiff
path: root/modules/simpletest
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2008-10-15 16:05:51 +0000
committerDries Buytaert <dries@buytaert.net>2008-10-15 16:05:51 +0000
commit967d8f67ac957924b9cb6855cb650f8f67d58cdc (patch)
tree55fce20e7794e58e8623ba7b00b927759e8c98de /modules/simpletest
parente85187d948fc997edc7c8332b6e0cc62d28b9008 (diff)
downloadbrdo-967d8f67ac957924b9cb6855cb650f8f67d58cdc.tar.gz
brdo-967d8f67ac957924b9cb6855cb650f8f67d58cdc.tar.bz2
- Patch #304924 by Damien Tournoud: extend error handler to manage exceptions. I have one exception and one fail.
Diffstat (limited to 'modules/simpletest')
-rw-r--r--modules/simpletest/drupal_web_test_case.php3
-rw-r--r--modules/simpletest/tests/common.test49
-rw-r--r--modules/simpletest/tests/system_test.info1
-rw-r--r--modules/simpletest/tests/system_test.module48
4 files changed, 98 insertions, 3 deletions
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index eba232b86..988f1592c 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -322,8 +322,7 @@ class DrupalWebTestCase {
* @see set_error_handler
*/
function errorHandler($severity, $message, $file = NULL, $line = NULL) {
- $severity = $severity & error_reporting();
- if ($severity) {
+ if ($severity & error_reporting()) {
$error_map = array(
E_STRICT => 'Run-time notice',
E_WARNING => 'Warning',
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index 43e7b0216..0d7ad985c 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -251,3 +251,52 @@ class DrupalSetContentTestCase extends DrupalWebTestCase {
}
}
}
+
+/**
+ * Tests Drupal error and exception handlers.
+ */
+class DrupalErrorHandlerUnitTest extends DrupalWebTestCase {
+ function getInfo() {
+ return array(
+ 'name' => t('Drupal error handlers'),
+ 'description' => t("Performs tests on the Drupal error and exception handler."),
+ 'group' => t('System'),
+ );
+ }
+
+ function setUp() {
+ parent::setUp('system_test');
+ }
+
+ /**
+ * Test the error handler.
+ */
+ function testErrorHandler() {
+ $this->drupalGet('system-test/generate-warnings');
+
+ $this->assertErrorMessage('Notice', 'system_test.module', 'system_test_generate_warnings() ', 'Undefined variable');
+ $this->assertErrorMessage('Warning', 'system_test.module', 'system_test_generate_warnings() ', 'Division by zero');
+ $this->assertErrorMessage('User notice', 'system_test.module', 'system_test_generate_warnings() ', 'Drupal is awesome');
+ }
+
+ /**
+ * Test the exception handler.
+ */
+ function testExceptionHandler() {
+ $this->drupalGet('system-test/trigger-exception');
+ $this->assertErrorMessage('Exception', 'system_test.module', 'system_test_trigger_exception()', 'Drupal is awesome');
+
+ $this->drupalGet('system-test/trigger-pdo-exception');
+ $this->assertErrorMessage('PDOException', 'system_test.module', 'system_test_trigger_pdo_exception()', 'Base table or view not found');
+ }
+
+ /**
+ * Helper function: assert that the logged message is correct.
+ */
+ function assertErrorMessage($type, $file, $function, $message) {
+ $this->assertText($type, t("Found '%type' in error page.", array('%type' => $type)));
+ $this->assertText($file, t("Found '%file' in error page.", array('%file' => $file)));
+ $this->assertText($function, t("Found '%function' in error page.", array('%function' => $function)));
+ $this->assertText($message, t("Found '%message' in error page.", array('%message' => $message)));
+ }
+}
diff --git a/modules/simpletest/tests/system_test.info b/modules/simpletest/tests/system_test.info
index f70a1a79f..1910e87ae 100644
--- a/modules/simpletest/tests/system_test.info
+++ b/modules/simpletest/tests/system_test.info
@@ -5,4 +5,3 @@ package = Testing
version = VERSION
core = 7.x
files[] = system_test.module
-hidden = TRUE
diff --git a/modules/simpletest/tests/system_test.module b/modules/simpletest/tests/system_test.module
index 188facc96..bd3eff6c5 100644
--- a/modules/simpletest/tests/system_test.module
+++ b/modules/simpletest/tests/system_test.module
@@ -48,6 +48,27 @@ function system_test_menu() {
'type' => MENU_CALLBACK,
);
+ $items['system-test/generate-warnings'] = array(
+ 'title' => 'Generate warnings',
+ 'page callback' => 'system_test_generate_warnings',
+ 'access callback' => TRUE,
+ 'type' => MENU_CALLBACK,
+ );
+
+ $items['system-test/trigger-exception'] = array(
+ 'title' => 'Trigger an exception',
+ 'page callback' => 'system_test_trigger_exception',
+ 'access callback' => TRUE,
+ 'type' => MENU_CALLBACK,
+ );
+
+ $items['system-test/trigger-pdo-exception'] = array(
+ 'title' => 'Trigger a PDO exception',
+ 'page callback' => 'system_test_trigger_pdo_exception',
+ 'access callback' => TRUE,
+ 'type' => MENU_CALLBACK,
+ );
+
return $items;
}
@@ -120,3 +141,30 @@ function system_test_modules_uninstalled($modules) {
drupal_set_message(t('hook_modules_uninstalled fired for aggregator'));
}
}
+
+/**
+ * Menu callback; generate warnings to test the error handler.
+ */
+function system_test_generate_warnings() {
+ // This will generate a notice.
+ $monkey_love = $bananas;
+ // This will generate a warning.
+ $awesomely_big = 1/0;
+ // This will generate a user error.
+ trigger_error("Drupal is awesome", E_USER_NOTICE);
+ return "";
+}
+
+/**
+ * Menu callback; trigger an exception to test the exception handler.
+ */
+function system_test_trigger_exception() {
+ throw new Exception("Drupal is awesome");
+}
+
+/**
+ * Menu callback; trigger an exception to test the exception handler.
+ */
+function system_test_trigger_pdo_exception() {
+ db_query("SELECT * FROM bananas_are_awesome");
+}