From f0f1805e34320587eaa09bb661d31f4cdfa45007 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Wed, 8 Jul 2009 07:23:23 +0000 Subject: - Patch #500280 by boombatower, Dries: provide verbose mode for testing. --- modules/simpletest/drupal_web_test_case.php | 66 +++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'modules/simpletest/drupal_web_test_case.php') diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php index e78c4ce50..7723b03ca 100644 --- a/modules/simpletest/drupal_web_test_case.php +++ b/modules/simpletest/drupal_web_test_case.php @@ -376,6 +376,9 @@ abstract class DrupalTestCase { * Run all tests in this class. */ public function run() { + // Initialize verbose debugging. + simpletest_verbose(NULL, file_directory_path()); + // HTTP auth settings (:) for the simpletest browser // when sending requests to the test site. $username = variable_get('simpletest_username', NULL); @@ -1346,6 +1349,9 @@ class DrupalWebTestCase extends DrupalTestCase { if (($new = $this->checkForMetaRefresh())) { $out = $new; } + $this->verbose('GET request to: ' . $path . + '
Ending URL: ' . $this->getUrl() . + '
' . $out); return $out; } @@ -1404,6 +1410,7 @@ class DrupalWebTestCase extends DrupalTestCase { // We post only if we managed to handle every field in edit and the // submit button matches. if (!$edit && $submit_matches) { + $post_array = $post; if ($upload) { // TODO: cURL handles file uploads for us, but the implementation // is broken. This is a less than elegant workaround. Alternatives @@ -1432,6 +1439,10 @@ class DrupalWebTestCase extends DrupalTestCase { if (($new = $this->checkForMetaRefresh())) { $out = $new; } + $this->verbose('POST request to: ' . $path . + '
Ending URL: ' . $this->getUrl() . + '
Fields: ' . highlight_string('' . $out); return $out; } } @@ -2401,6 +2412,22 @@ class DrupalWebTestCase extends DrupalTestCase { $email = end($captured_emails); return $this->assertTrue($email && isset($email[$name]) && $email[$name] == $value, $message, t('E-mail')); } + + /** + * Log verbose message in a text file. + * + * The a link to the vebose message will be placed in the test results via + * as a passing assertion with the text '[verbose message]'. + * + * @param $message + * The verbose message to be stored. + * @see simpletest_verbose() + */ + protected function verbose($message) { + if ($id = simpletest_verbose($message)) { + $this->pass(l(t('Verbose message'), url($this->originalFileDirectory . '/simpletest/verbose.html', array('fragment' => $id))), 'Debug'); + } + } } /** @@ -2418,3 +2445,42 @@ function drupal_mail_wrapper($message) { return TRUE; } + +/** + * Log verbose message in a text file. + * + * If verbose mode is enabled then page requests will be dumped to a file and + * presented on the test result screen. The messages will be placed in a file + * located in the simpletest directory in the original file system. + * + * @param $message + * The verbose message to be stored. + * @param $original_file_directory + * The original file directory, before it was changed for testing purposes. + * @return + * The ID of the message to be placed in related assertion messages. + * @see DrupalTestCase->originalFileDirectory + * @see DrupalWebTestCase->verbose() + */ +function simpletest_verbose($message, $original_file_directory = NULL) { + static $file_directory = NULL, $id = 0; + + if (variable_get('simpletest_verbose', FALSE) || TRUE) { + return FALSE; + } + + if ($message && $file_directory) { + $message = '
ID #' . $id . '
' . $message; + file_put_contents($file_directory . '/simpletest/verbose.html', $message, FILE_APPEND); + return $id++; + } + + if ($original_file_directory) { + $file_directory = $original_file_directory; + + // Clear out the previous log. + $message = t('Starting verbose log at @time.', array('@time' => format_date(time()))) . "\n"; + file_put_contents($file_directory . '/simpletest/verbose.html', $message); + } + return FALSE; +} -- cgit v1.2.3