Index: modules/simpletest/drupal_web_test_case.php =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v retrieving revision 1.125 diff -u -r1.125 drupal_web_test_case.php --- modules/simpletest/drupal_web_test_case.php 11 Jul 2009 06:14:48 -0000 1.125 +++ modules/simpletest/drupal_web_test_case.php 14 Jul 2009 01:27:25 -0000 @@ -388,6 +388,7 @@ } set_error_handler(array($this, 'errorHandler')); + drupal_register_debug_function('simpletest_drupal_debug'); $methods = array(); // Iterate through all the methods in this class. foreach (get_class_methods(get_class($this)) as $method) { @@ -2490,3 +2491,17 @@ } return FALSE; } + +function simpletest_drupal_debug($data, $label = NULL) { + // Print $data contents to string. + $string = print_r($data, TRUE) . "\n"; + if ($label) { + $string = $label . ': ' . $string; + } + + $file = file_directory_path() . '/drupal_debug.log'; + if (file_put_contents($file, $string, FILE_APPEND) === FALSE) { + drupal_set_message(t('The temporary debug log cound not be written.'), 'error'); + return FALSE; + } +} Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.933 diff -u -r1.933 common.inc --- includes/common.inc 13 Jul 2009 21:09:53 -0000 1.933 +++ includes/common.inc 14 Jul 2009 01:27:25 -0000 @@ -4794,3 +4794,41 @@ } variable_set('css_js_query_string', $new_character . substr($string_history, 0, 19)); } + +function drupal_register_debug_function($function = NULL) { + $debug_function = &drupal_static(__FUNCTION__, '_drupal_debug'); + + if ($function) { + $debug_function = $function; + } + + return $debug_function; +} + +function dd($data, $label = NULL) { + drupal_debug($data, $label); +} + +function drupal_debug($data, $label = NULL) { + $function = drupal_register_debug_function(); + $function($data, $label); +} + +function _drupal_debug($data, $label = NULL) { + // Print $data contents to string. + $string = print_r($data, TRUE) . "\n"; + if ($label) { + $string = $label . ': ' . $string; + } + + if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/^simpletest\d+$/", $_SERVER['HTTP_USER_AGENT'])) { + $file = file_directory_path() . '/drupal_debug.log'; + } + else { + $file = file_directory_temp() . '/drupal_debug.log'; + } + if (file_put_contents($file, $string, FILE_APPEND) === FALSE) { + drupal_set_message(t('The temporary debug log cound not be written.'), 'error'); + return FALSE; + } +}