diff options
author | Dries Buytaert <dries@buytaert.net> | 2008-11-05 17:06:18 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2008-11-05 17:06:18 +0000 |
commit | 57d35b7fb18619cb68e405f586471ea0ac1453fe (patch) | |
tree | 8aa00621a010ca8f522185543b5a43c648b9bffa | |
parent | dc1af5e2909258358348a17b17a3f87850396e32 (diff) | |
download | brdo-57d35b7fb18619cb68e405f586471ea0ac1453fe.tar.gz brdo-57d35b7fb18619cb68e405f586471ea0ac1453fe.tar.bz2 |
- Patch #243532 by Damien Tournoud et al: catch notices, warnings and fatal errors during testing. Woop, woop.
-rw-r--r-- | includes/common.inc | 18 | ||||
-rw-r--r-- | modules/simpletest/drupal_web_test_case.php | 21 | ||||
-rw-r--r-- | modules/simpletest/tests/session_test.module | 7 | ||||
-rw-r--r-- | modules/simpletest/tests/system_test.module | 3 | ||||
-rw-r--r-- | modules/trigger/trigger.module | 4 |
5 files changed, 49 insertions, 4 deletions
diff --git a/includes/common.inc b/includes/common.inc index df2b8e1d2..34b40fbac 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -615,6 +615,7 @@ function _drupal_error_handler($error_level, $message, $filename, $line, $contex E_RECOVERABLE_ERROR => 'Recoverable fatal error' ); $backtrace = debug_backtrace(); + // We treat recoverable errors as fatal. _drupal_log_error(isset($types[$error_level]) ? $types[$error_level] : 'Unknown error', $message, $backtrace, $error_level == E_RECOVERABLE_ERROR); } @@ -673,10 +674,25 @@ function _drupal_log_error($type, $message, $backtrace, $fatal) { // Do it early because drupal_set_message() triggers an init_theme(). if ($fatal && (drupal_get_bootstrap_phase() != DRUPAL_BOOTSTRAP_FULL)) { unset($GLOBALS['theme']); - define('MAINTENANCE_MODE', 'error'); + if (!defined('MAINTENANCE_MODE')) { + define('MAINTENANCE_MODE', 'error'); + } drupal_maintenance_theme(); } + // When running inside the testing framework, we relay the errors + // to the tested site by the way of HTTP headers. + if (preg_match("/^simpletest\d+/", $GLOBALS['db_prefix']) && !headers_sent() && !defined('SIMPLETEST_DONT_COLLECT_ERRORS')) { + static $number = 0; + $assertion = array( + $message, + $type, + $caller + ); + header('X-Drupal-Assertion-' . $number . ': ' . rawurlencode(serialize($assertion))); + $number++; + } + // Force display of error messages in update.php. if (variable_get('error_level', 1) == 1 || (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update')) { drupal_set_message(t('@type: %message in %function (line %line of %file).', array('@type' => $type, '%message' => $message, '%function' => $caller['function'], '%line' => $caller['line'], '%file' => $caller['file'])), 'error'); diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php index 43795312b..3d8c6d522 100644 --- a/modules/simpletest/drupal_web_test_case.php +++ b/modules/simpletest/drupal_web_test_case.php @@ -801,6 +801,7 @@ class DrupalWebTestCase { CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_SSL_VERIFYPEER => FALSE, // Required to make the tests run on https:// CURLOPT_SSL_VERIFYHOST => FALSE, // Required to make the tests run on https:// + CURLOPT_HEADERFUNCTION => array(&$this, 'curlHeaderCallback'), ); if (preg_match('/simpletest\d+/', $db_prefix, $matches)) { $curl_options[CURLOPT_USERAGENT] = $matches[0]; @@ -833,6 +834,26 @@ class DrupalWebTestCase { } /** + * Reads headers and registers errors received from the tested site. + * + * @see _drupal_log_error(). + * + * @param $ch the cURL handler. + * @param $header a header. + */ + protected function curlHeaderCallback($ch, $header) { + // Errors are being sent via X-Drupal-Assertion-* headers, + // generated by _drupal_log_error() in the exact form required + // by DrupalWebTestCase::error(). + if (preg_match('/^X-Drupal-Assertion-[0-9]+: (.*)$/', $header, $matches)) { + // Call DrupalWebTestCase::error() with the parameters from the header. + call_user_func_array(array(&$this, 'error'), unserialize(urldecode($matches[1]))); + } + // This is required by cURL. + return strlen($header); + } + + /** * Close the cURL handler and unset the handler. */ protected function curlClose() { diff --git a/modules/simpletest/tests/session_test.module b/modules/simpletest/tests/session_test.module index 42c47a08c..b183ec38c 100644 --- a/modules/simpletest/tests/session_test.module +++ b/modules/simpletest/tests/session_test.module @@ -33,7 +33,12 @@ function session_test_menu() { * Page callback, prints the stored session value to the screen. */ function _session_test_get() { - return t('The current value of the stored session variable is: %val', array('%val' => $_SESSION['session_test_value'])); + if (!empty($_SESSION['session_test_value'])) { + return t('The current value of the stored session variable is: %val', array('%val' => $_SESSION['session_test_value'])); + } + else { + return ""; + } } /** diff --git a/modules/simpletest/tests/system_test.module b/modules/simpletest/tests/system_test.module index bd3eff6c5..2134359d2 100644 --- a/modules/simpletest/tests/system_test.module +++ b/modules/simpletest/tests/system_test.module @@ -146,6 +146,7 @@ function system_test_modules_uninstalled($modules) { * Menu callback; generate warnings to test the error handler. */ function system_test_generate_warnings() { + define('SIMPLETEST_DONT_COLLECT_ERRORS', TRUE); // This will generate a notice. $monkey_love = $bananas; // This will generate a warning. @@ -159,6 +160,7 @@ function system_test_generate_warnings() { * Menu callback; trigger an exception to test the exception handler. */ function system_test_trigger_exception() { + define('SIMPLETEST_DONT_COLLECT_ERRORS', TRUE); throw new Exception("Drupal is awesome"); } @@ -166,5 +168,6 @@ function system_test_trigger_exception() { * Menu callback; trigger an exception to test the exception handler. */ function system_test_trigger_pdo_exception() { + define('SIMPLETEST_DONT_COLLECT_ERRORS', TRUE); db_query("SELECT * FROM bananas_are_awesome"); } diff --git a/modules/trigger/trigger.module b/modules/trigger/trigger.module index bc127a8b4..b00cd358e 100644 --- a/modules/trigger/trigger.module +++ b/modules/trigger/trigger.module @@ -393,8 +393,8 @@ function trigger_user_login(&$edit, &$account, $category) { /** * Implementation of hook_user_logout(). */ -function trigger_user_logout(&$edit, &$account, $category) { - _trigger_user('logout', $edit, $account, $category); +function trigger_user_logout(&$edit, &$account) { + _trigger_user('logout', $edit, $account); } /** |