summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-07-08 07:23:23 +0000
committerDries Buytaert <dries@buytaert.net>2009-07-08 07:23:23 +0000
commitf0f1805e34320587eaa09bb661d31f4cdfa45007 (patch)
tree34f1f0b1bac5c01b8dfed0437c1fd28779a4440b
parentf9bdd7ae9e049bdb9cabda964f968081a45acafc (diff)
downloadbrdo-f0f1805e34320587eaa09bb661d31f4cdfa45007.tar.gz
brdo-f0f1805e34320587eaa09bb661d31f4cdfa45007.tar.bz2
- Patch #500280 by boombatower, Dries: provide verbose mode for testing.
-rw-r--r--modules/simpletest/drupal_web_test_case.php66
-rw-r--r--modules/simpletest/simpletest.install1
-rw-r--r--modules/simpletest/simpletest.pages.inc10
3 files changed, 75 insertions, 2 deletions
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 (<username>:<password>) 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 .
+ '<hr />Ending URL: ' . $this->getUrl() .
+ '<hr />' . $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 .
+ '<hr />Ending URL: ' . $this->getUrl() .
+ '<hr />Fields: ' . highlight_string('<?php ' . var_export($post_array, TRUE), TRUE) .
+ '<hr />' . $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 = '<hr /><a id="' . $id . '" href="#' . $id . '">ID #' . $id . '</a><hr />' . $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;
+}
diff --git a/modules/simpletest/simpletest.install b/modules/simpletest/simpletest.install
index 1a79a7979..6f21ae54a 100644
--- a/modules/simpletest/simpletest.install
+++ b/modules/simpletest/simpletest.install
@@ -109,6 +109,7 @@ function simpletest_uninstall() {
variable_del('simpletest_httpauth_username');
variable_del('simpletest_httpauth_pass');
variable_del('simpletest_devel');
+ variable_del('simpletest_verbose');
// Uninstall schema.
drupal_uninstall_schema('simpletest');
diff --git a/modules/simpletest/simpletest.pages.inc b/modules/simpletest/simpletest.pages.inc
index 44a02d037..31ff67c7c 100644
--- a/modules/simpletest/simpletest.pages.inc
+++ b/modules/simpletest/simpletest.pages.inc
@@ -417,10 +417,16 @@ function simpletest_settings_form(&$form_state) {
);
$form['general']['simpletest_clear_results'] = array(
'#type' => 'checkbox',
- '#title' => t('Clear results'),
- '#description' => t('Clear the test results after each complete test suite run. By default SimpleTest will clear the results after they have been viewed on the results page, but in some cases it may be useful to leave the results in the database. The results can then be viewed at <em>admin/development/testing/[test_id]</em>. The test ID can be found in the database, simpletest table, or kept track of when viewing the results the first time. Additionally, some modules may provide more analaysis or features that require this setting to be disabled.'),
+ '#title' => t('Clear results after each complete test suite run'),
+ '#description' => t('By default SimpleTest will clear the results after they have been viewed on the results page, but in some cases it may be useful to leave the results in the database. The results can then be viewed at <em>admin/development/testing/[test_id]</em>. The test ID can be found in the database, simpletest table, or kept track of when viewing the results the first time. Additionally, some modules may provide more analaysis or features that require this setting to be disabled.'),
'#default_value' => variable_get('simpletest_clear_results', TRUE),
);
+ $form['general']['simpletest_verbose'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Provide verbose information when running tests'),
+ '#description' => t('The verbose data will be printed along with the standard assertions. Useful for debugging.'),
+ '#default_value' => variable_get('simpletest_verbose', TRUE),
+ );
$form['httpauth'] = array(
'#type' => 'fieldset',