Commit 57d35b7f authored by Dries's avatar Dries
Browse files

- Patch #243532 by Damien Tournoud et al: catch notices, warnings and fatal...

- Patch #243532 by Damien Tournoud et al: catch notices, warnings and fatal errors during testing.  Woop, woop.
parent dc1af5e2
......@@ -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');
......
......@@ -801,6 +801,7 @@ protected function curlConnect() {
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];
......@@ -832,6 +833,26 @@ protected function curlExec($curl_options) {
return $this->drupalGetContent();
}
/**
* 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.
*/
......
......@@ -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 "";
}
}
/**
......
......@@ -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");
}
......@@ -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);
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment