Commit f0f1805e authored by Dries's avatar Dries

- Patch #500280 by boombatower, Dries: provide verbose mode for testing.

parent f9bdd7ae
......@@ -376,6 +376,9 @@ protected function error($message = '', $group = 'Other', array $caller = NULL)
* 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 @@ protected function drupalGet($path, array $options = array(), array $headers = a
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 @@ protected function drupalPost($path, $edit, $submit, array $options = array(), a
// 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 @@ protected function drupalPost($path, $edit, $submit, array $options = array(), a
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 @@ protected function assertMail($name, $value = '', $message = '') {
$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;
}
......@@ -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');
......
......@@ -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',
......
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