Index: includes/batch.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/batch.inc,v
retrieving revision 1.20
diff -u -p -r1.20 batch.inc
--- includes/batch.inc 24 Jun 2008 21:51:02 -0000 1.20
+++ includes/batch.inc 14 Sep 2008 12:23:00 -0000
@@ -22,11 +22,14 @@ function _batch_page() {
// Register database update for end of processing.
register_shutdown_function('_batch_shutdown');
- // Add batch-specific css.
+ // Add batch-specific css and javascript.
foreach ($batch['sets'] as $batch_set) {
foreach ($batch_set['css'] as $css) {
drupal_add_css($css);
}
+ foreach ($batch_set['js'] as $js) {
+ drupal_add_js($js);
+ }
}
$op = isset($_REQUEST['op']) ? $_REQUEST['op'] : '';
@@ -251,8 +254,11 @@ function _batch_process() {
'@total' => $total,
'@current' => floor($current),
'@percentage' => $percentage,
- );
- $message = strtr($progress_message, $values) . '
';
+ );
+ $message = strtr($progress_message, $values);
+ if (!empty($message)) {
+ $message .= '
';
+ }
$message .= $task_message ? $task_message : ' ';
return array($percentage, $message);
Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.282
diff -u -p -r1.282 form.inc
--- includes/form.inc 6 Sep 2008 08:36:19 -0000 1.282
+++ includes/form.inc 14 Sep 2008 12:23:01 -0000
@@ -2421,6 +2421,7 @@ function batch_set($batch_definition) {
'progress_message' => $t('Remaining @remaining of @total.'),
'error_message' => $t('An error has occurred.'),
'css' => array(),
+ 'js' => array(),
);
$batch_set = $init + $batch_definition + $defaults;
Index: misc/batch.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/batch.js,v
retrieving revision 1.4
diff -u -p -r1.4 batch.js
--- misc/batch.js 21 Oct 2007 18:59:01 -0000 1.4
+++ misc/batch.js 14 Sep 2008 12:23:01 -0000
@@ -16,6 +16,9 @@ Drupal.behaviors.batch = function (conte
// Success: redirect to the summary.
var updateCallback = function (progress, status, pb) {
+ for (behavior in Drupal.batchUpdate) {
+ Drupal.batchUpdate[behavior](progress, status, pb);
+ }
if (progress == 100) {
pb.stopMonitoring();
window.location = uri+'&op=finished';
Index: misc/drupal.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/drupal.js,v
retrieving revision 1.45
diff -u -p -r1.45 drupal.js
--- misc/drupal.js 25 Jun 2008 07:45:03 -0000 1.45
+++ misc/drupal.js 14 Sep 2008 12:23:01 -0000
@@ -1,6 +1,6 @@
// $Id: drupal.js,v 1.45 2008/06/25 07:45:03 dries Exp $
-var Drupal = Drupal || { 'settings': {}, 'behaviors': {}, 'themes': {}, 'locale': {} };
+var Drupal = Drupal || { 'settings': {}, 'behaviors': {}, 'themes': {}, 'locale': {}, 'batchUpdate': {} };
/**
* Set the variable that indicates if JavaScript behaviors should be applied
Index: modules/simpletest/drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v
retrieving revision 1.39
diff -u -p -r1.39 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php 14 Sep 2008 06:46:34 -0000 1.39
+++ modules/simpletest/drupal_web_test_case.php 14 Sep 2008 12:23:03 -0000
@@ -76,15 +76,19 @@ class DrupalWebTestCase {
'test_class' => get_class($this),
'status' => $status,
'message' => $message,
- 'message_group' => $group,
+ 'group' => $group,
'function' => $caller['function'],
'line' => $caller['line'],
'file' => $caller['file'],
);
// Store assertion for display after the test has completed.
+ // Change the 'group' attribute to 'message_group' to avoid reserved word
+ // conflict when inserted into database.
+ $assertion['message_group'] = $assertion['group'];
+ unset($assertion['group']);
db_insert('simpletest')->fields($assertion)->execute();
-
+
// Return to testing prefix.
$db_prefix = $current_db_prefix;
return $status;
Index: modules/simpletest/simpletest.css
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.css,v
retrieving revision 1.2
diff -u -p -r1.2 simpletest.css
--- modules/simpletest/simpletest.css 24 Jun 2008 21:51:02 -0000 1.2
+++ modules/simpletest/simpletest.css 14 Sep 2008 12:23:03 -0000
@@ -1,11 +1,9 @@
/* $Id: simpletest.css,v 1.2 2008/06/24 21:51:02 dries Exp $ */
-/* Addon for the simpletest module */
-#simpletest {
-}
/* Test Table */
th.simpletest_run {
width: 50px;
+ padding-right: 0.5em;
}
th.simpletest_test {
width: 160px;
@@ -17,46 +15,55 @@ td.simpletest-select-all {
}
table#simpletest-form-table tr td {
- background-color: white !important;
+ background-color: white;
}
table#simpletest-form-table tr.simpletest-group td {
- background-color: #EDF5FA !important;
+ background-color: #EDF5FA;
}
-div.simpletest-pass {
- color: #33a333;
+table#simpletest-form-table thead .form-item {
+ margin-bottom:0pt;
+ margin-top:0pt;
+ white-space:nowrap;
}
-div.simpletest-fail {
- color: #a30000;
+div.simpletest-image {
+ display: inline;
}
-tr.simpletest-pass.odd {
- background: #b6ffb6;
+div.simpletest-image, label.simpletest-group-label {
+ cursor: pointer;
}
-tr.simpletest-pass.even {
- background: #9bff9b;
+.simpletest-pass {
+ color: #316d31;
}
-tr.simpletest-fail.odd {
- background: #ffc9c9;
+.simpletest-fail {
+ color: #981010;
}
-tr.simpletest-fail.even {
- background: #ffacac;
+.simpletest-exception {
+ color: #bda400;
}
-tr.simpletest-exception.odd {
- background: #f4ea71;
+div.message > div.item-list {
+ font-weight: normal;
}
-tr.simpletest-exception.even {
- background: #f5e742;
+li.simpletest-important {
+ font-weight: bold;
}
-div.simpletest-image {
- display: inline;
+ul.simpletest-results li div.item-list ul {
+ padding-left: 20px;
+}
+
+ul.simpletest-results li span.simpletest-overview {
cursor: pointer;
}
+
+ul.simpletest-results li span.simpletest-overview:hover {
+ text-decoration: underline;
+}
\ No newline at end of file
Index: modules/simpletest/simpletest.js
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.js,v
retrieving revision 1.2
diff -u -p -r1.2 simpletest.js
--- modules/simpletest/simpletest.js 23 Apr 2008 18:50:49 -0000 1.2
+++ modules/simpletest/simpletest.js 14 Sep 2008 12:23:03 -0000
@@ -60,4 +60,69 @@ Drupal.behaviors.simpleTestSelectAll = f
}
$(this).append(checkbox);
});
+ $('input.simpletest-master:checkbox').click(function() {
+ if ($(this).is(':checked')) {
+ $('#simpletest-form-table input:checkbox,input.simpletest-master:checkbox').attr('checked', 'checked');
+ }
+ else {
+ $('#simpletest-form-table input:checkbox,input.simpletest-master:checkbox').removeAttr('checked');
+ }
+ $('#simpletest-form-table input:checkbox:not(.simpletest-master)').change(function() {
+ if ($('#simpletest-form-table input:checkbox:not(:checked):not(.simpletest-master)').length) {
+ $('input.simpletest-master:checkbox').removeAttr('checked');
+ }
+ else if ($('#simpletest-form-table input:checkbox:not(.simpletest-master)').length == $('#simpletest-form-table input:checkbox:checked:not(.simpletest-master)').length) {
+ $('input.simpletest-master:checkbox').attr('checked', 'checked');
+ }
+ });
+ });
+};
+
+/**
+ * Filter the results based on their outcome.
+ */
+Drupal.behaviors.simpleTestFilterForm = function() {
+ var updateResults = function(type, checked) {
+ $('li.simpletest-' + type + ':not(.simpletest-container)')[checked ? 'show' : 'hide']();
+ $('li.simpletest-container:not(:has(li.simpletest-container))').each(function() {
+ var children = $(this).find('li:visible:not(.simpletest-container)').is('.simpletest-pass,.simpletest-fail,.simpletest-exception');
+ $(this)[children ? 'show' : 'hide']();
+ });
+ }
+ $('#edit-outcome-pass').change(function() {
+ updateResults('pass', $(this).is(':checked'));
+ });
+ $('#edit-outcome-fail').change(function() {
+ updateResults('fail', $(this).is(':checked'));
+ });
+ $('#edit-outcome-exception').change(function() {
+ updateResults('exception', $(this).is(':checked'));
+ });
+ updateResults('pass', $('#edit-outcome-pass').is(':checked'));
+ updateResults('fail', $('#edit-outcome-fail').is(':checked'));
+ updateResults('exception', $('#edit-outcome-exception').is(':checked'));
+};
+
+/**
+ * The results should collapse when you click on them, of course.
+ */
+Drupal.behaviors.simpleTestResultsCollapse = function() {
+ $('li > span.simpletest-overview').click(function() {
+ $(this).siblings().children('ul').toggle().toggleClass('simpletest-hidden').parent().parent().toggleClass('collapsed').toggleClass('expanded');
+ });
+ $('li.collapsed > span.simpletest-overview').each(function() {
+ $(this).siblings().children('ul').hide().addClass('simpletest-hidden');
+ });
+};
+
+/**
+ * Batch update function - re-attaches javascript behaviors to the new elements
+ * now injected into the HTML.
+ */
+Drupal.batchUpdate.simpleTestResultsCollapse = function() {
+ $('li > span.simpletest-overview').click(function() {
+ $(this).siblings().children('ul').toggle().toggleClass('simpletest-hidden').parent().parent().toggleClass('collapsed').toggleClass('expanded');
+ }).each(function() {
+ $(this).siblings().children('ul').hide().addClass('simpletest-hidden').parent().parent().removeClass('expanded').addClass('collapsed');
+ });
};
\ No newline at end of file
Index: modules/simpletest/simpletest.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.module,v
retrieving revision 1.12
diff -u -p -r1.12 simpletest.module
--- modules/simpletest/simpletest.module 10 Sep 2008 04:13:01 -0000 1.12
+++ modules/simpletest/simpletest.module 14 Sep 2008 12:23:03 -0000
@@ -26,6 +26,14 @@ function simpletest_menu() {
'page arguments' => array('simpletest_test_form'),
'description' => 'Run tests against Drupal core and your active modules. These tests help assure that your site code is working as designed.',
'access arguments' => array('administer unit tests'),
+ 'type' => MENU_NORMAL_ITEM,
+ );
+ $items['admin/build/testing/results'] = array(
+ 'title' => 'Results',
+ 'page callback' => 'simpletest_display_results',
+ 'description' => 'View the test results.',
+ 'access arguments' => array('administer unit tests'),
+ 'type' => MENU_CALLBACK,
);
return $items;
}
@@ -50,110 +58,34 @@ function simpletest_theme() {
'simpletest_result_summary' => array(
'arguments' => array('form' => NULL)
),
+ 'simpletest_results' => array(
+ 'arguments' => array('results' => NULL, 'assertions' => NULL)
+ ),
);
}
/**
- * Menu callback for both running tests and listing possible tests
+ * Menu callback -- List all tests that can be run.
*/
function simpletest_test_form() {
global $db_prefix, $db_prefix_original;
+
$form = array();
+ $form['run_all'] = array(
+ '#type' => 'checkbox',
+ '#default_value' => 0,
+ '#attributes' => array('class' => 'simpletest-master'),
+ );
+
+ // List out all tests in groups for selection.
$uncategorized_tests = simpletest_get_all_tests();
$tests = simpletest_categorize_tests($uncategorized_tests);
- if (isset($_SESSION['test_id'])) {
- // Select all results using the active test ID used to group them.
- $results = db_query("SELECT * FROM {simpletest} WHERE test_id = %d ORDER BY test_class, message_id", $_SESSION['test_id']);
-
- $summary = array(
- '#theme' => 'simpletest_result_summary',
- '#pass' => 0,
- '#fail' => 0,
- '#exception' => 0,
- '#weight' => -10,
- );
- $form['summary'] = $summary;
- $form['results'] = array();
- $group_summary = array();
- $map = array(
- 'pass' => theme('image', 'misc/watchdog-ok.png'),
- 'fail' => theme('image', 'misc/watchdog-error.png'),
- 'exception' => theme('image', 'misc/watchdog-warning.png'),
- );
- $header = array(t('Message'), t('Group'), t('Filename'), t('Line'), t('Function'), array('colspan' => 2, 'data' => t('Status')));
- while ($result = db_fetch_object($results)) {
- $class = $result->test_class;
- $info = $uncategorized_tests[$class]->getInfo();
- $group = $info['group'];
- if (!isset($group_summary[$group])) {
- $group_summary[$group] = $summary;
- }
- $element = &$form['results'][$group][$class];
- if (!isset($element)) {
- $element['summary'] = $summary;
- }
- $status = $result->status;
- // This reporter can only handle pass, fail and exception.
- if (isset($map[$status])) {
- $element['#title'] = $info['name'];
- $status_index = '#'. $status;
- $form['summary'][$status_index]++;
- $group_summary[$group][$status_index]++;
- $element['summary'][$status_index]++;
- $element['result_table']['#rows'][] = array(
- 'data' => array(
- $result->message,
- $result->message_group,
- basename($result->file),
- $result->line,
- $result->function,
- $map[$status],
- ),
- 'class' => "simpletest-$status",
- );
- }
- unset($element);
- }
- // Clear test results.
- if (variable_get('simpletest_clear_results', TRUE)) {
- db_query('DELETE FROM {simpletest} WHERE test_id = %d', $_SESSION['test_id']);
- db_query('DELETE FROM {simpletest_test_id} WHERE test_id = %d', $_SESSION['test_id']);
- }
- unset($_SESSION['test_id']);
-
- $all_ok = TRUE;
- foreach ($form['results'] as $group => &$elements) {
- $group_ok = TRUE;
- foreach ($elements as $class => &$element) {
- $info = $uncategorized_tests[$class]->getInfo();
- $ok = $element['summary']['#fail'] + $element['summary']['#exception'] == 0;
- $element += array(
- '#type' => 'fieldset',
- '#collapsible' => TRUE,
- '#collapsed' => $ok,
- '#description' => $info['description'],
- );
- $element['result_table']['#markup'] = theme('table', $header, $element['result_table']['#rows']);
- $element['summary']['#ok'] = $ok;
- $group_ok = $group_ok && $ok;
- }
- $elements += array(
- '#type' => 'fieldset',
- '#title' => $group,
- '#collapsible' => TRUE,
- '#collapsed' => $group_ok,
- 'summary' => $group_summary[$group],
- );
- $elements['summary']['#ok'] = $group_ok;
- $all_ok = $group_ok && $all_ok;
- }
- $form['summary']['#ok'] = $all_ok;
- }
foreach ($tests as $group_name => $test_group) {
foreach ($test_group as $test) {
$test_info = $test->getInfo();
$test_class = get_class($test);
+
$form['tests'][$group_name][$test_class] = array(
'#type' => 'checkbox',
'#title' => $test_info['name'],
@@ -163,21 +95,8 @@ function simpletest_test_form() {
}
}
- $form['run'] = array(
- '#type' => 'fieldset',
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- '#title' => t('Run tests'),
- );
- $form['run']['running_options'] = array(
- '#type' => 'radios',
- '#default_value' => 'selected_tests',
- '#options' => array(
- 'all_tests' => t('Run all tests (WARNING, this may take a long time)'),
- 'selected_tests' => t('Run selected tests'),
- ),
- );
- $form['run']['op'] = array(
+ // Action buttons.
+ $form['op'] = array(
'#type' => 'submit',
'#value' => t('Run tests'),
);
@@ -186,7 +105,8 @@ function simpletest_test_form() {
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#title' => t('Clean test environment'),
- '#description' => t('Remove tables with the prefix "simpletest" and temporary directories that are left over from tests that crashed.')
+ '#description' => t('Remove tables with the prefix "simpletest" and temporary directories that are left over from' .
+ 'tests that crashed. This is intended for developers when creating tests.')
);
$form['reset']['op'] = array(
'#type' => 'submit',
@@ -202,13 +122,18 @@ function simpletest_test_form() {
* @ingroup themeable
*/
function theme_simpletest_test_form($form) {
- drupal_add_css(drupal_get_path('module', 'simpletest') .'/simpletest.css', 'module');
- drupal_add_js(drupal_get_path('module', 'simpletest') .'/simpletest.js', 'module');
+ drupal_add_css(drupal_get_path('module', 'simpletest') . '/simpletest.css', 'module');
+ drupal_add_js(drupal_get_path('module', 'simpletest') . '/simpletest.js', 'module');
+
+ // Create header for test selection table.
$header = array(
- array('data' => t('Run'), 'class' => 'simpletest_run checkbox'),
+ array('data' => drupal_render($form['run_all']), 'class' => 'simpletest_run checkbox'),
array('data' => t('Test'), 'class' => 'simpletest_test'),
array('data' => t('Description'), 'class' => 'simpletest_description'),
);
+ unset($form['run_all']);
+
+ // Define the images used to expand/collapse the test groups.
$js = array(
'images' => array(
theme('image', 'misc/menu-collapsed.png', 'Expand', 'Expand'),
@@ -216,61 +141,172 @@ function theme_simpletest_test_form($for
),
);
- // Go through each test group and create a row:
+ // Go through each test group and create a row.
$rows = array();
foreach (element_children($form['tests']) as $key) {
$element = &$form['tests'][$key];
- $test_class = strtolower(trim(preg_replace("/[^\w\d]/", "-", $key)));
$row = array();
+
+ // Make the class name safe for output on the pace by replacing all
+ // non-word/decimal characters with a dash (-).
+ $test_class = strtolower(trim(preg_replace("/[^\w\d]/", "-", $key)));
+
+ // Place-holder for checkboxes to select group of tests.
$row[] = array('id' => $test_class, 'class' => 'simpletest-select-all');
+
+ // Expand/collapse image and group title.
$row[] = array(
- 'data' => '
' . t('Select the tests you would like to run, and click Run tests.') . '
'; + if (empty($rows)) { + $output .= '' . t('No tests to display.') . ''; } - if (count($rows)) { + else { $output .= theme('table', $header, $rows, array('id' => 'simpletest-form-table')); } - // Output the rest of the form, excluded test groups which have been removed: + + // Output the rest of the form, excluded tests which have been removed. $output .= drupal_render($form); return $output; } -function theme_simpletest_result_summary($form, $text = NULL) { - return '' . t('The assertions listed in bold text are those made by the tests themselves, rather than the implicit framework tests.') . '
' . + drupal_get_form('simpletest_filter_form') . + theme('simpletest_results', $results, $assertions) . + drupal_get_form('simpletest_rerun_form', $test_classes); } function _simpletest_format_summary_line($summary) { - return t('@pass, @fail, @exception', array( + return t('@pass, @fail, and @exception', array( '@pass' => format_plural(isset($summary['#pass']) ? $summary['#pass'] : 0, '1 pass', '@count passes'), '@fail' => format_plural(isset($summary['#fail']) ? $summary['#fail'] : 0, '1 fail', '@count fails'), '@exception' => format_plural(isset($summary['#exception']) ? $summary['#exception'] : 0, '1 exception', '@count exceptions'), @@ -281,17 +317,20 @@ function _simpletest_format_summary_line * Run selected tests. */ function simpletest_test_form_submit($form, &$form_state) { - $output = ''; - $batch_mode = !preg_match("/^simpletest\d+$/", $_SERVER['HTTP_USER_AGENT']); - $tests_list = array(); - $run_all_tests = $form_state['values']['running_options'] == 'all_tests'; + // Ensure that all classes are loaded before we create instances to get test information and run. simpletest_get_all_tests(); + + // Get list of tests. + $tests_list = array(); foreach ($form_state['values'] as $class_name => $value) { - if (class_exists($class_name) && ($value === 1 || $run_all_tests)) { + if (class_exists($class_name) && $value === 1) { $tests_list[] = $class_name; } } - if (count($tests_list) > 0 ) { + + // If there are selected tests then run them. + if (!empty($tests_list)) { + $batch_mode = !preg_match("/^simpletest\d+$/", $_SERVER['HTTP_USER_AGENT']); simpletest_run_tests($tests_list, 'drupal', $batch_mode); } else { @@ -315,16 +354,20 @@ function simpletest_run_tests($test_list $test_id = db_insert('simpletest_test_id')->useDefaults(array('test_id'))->execute(); if ($batch_mode) { + $first_test = array_shift($test_list); + $first_instance = new $first_test(); + array_unshift($test_list, $first_test); + $info = $first_instance->getInfo(); $batch = array( 'title' => t('Running SimpleTests'), 'operations' => array( array('_simpletest_batch_operation', array($test_list, $test_id)), ), 'finished' => '_simpletest_batch_finished', - 'redirect' => 'admin/build/testing', - 'progress_message' => t('Processing tests.'), + 'progress_message' => '', 'css' => array(drupal_get_path('module', 'simpletest') .'/simpletest.css'), - 'init_message' => t('SimpleTest is initializing...') . ' ' . format_plural(count($test_list), "one test case will run.", "@count test cases will run."), + 'js' => array(drupal_get_path('module', 'simpletest') .'/simpletest.js'), + 'init_message' => t('Processing test @num of @max - %test.', array('%test' => $info['name'], '@num' => '1', '@max' => count($test_list))), ); batch_set($batch); } @@ -335,6 +378,7 @@ function simpletest_run_tests($test_list $test->run(); } $_SESSION['test_id'] = $test_id; + drupal_goto('admin/build/testing/results'); } } @@ -374,12 +418,11 @@ function _simpletest_batch_operation($te $test_results[$test_class]['#name'] = $info['name']; $items = array(); foreach (element_children($test_results) as $class) { - $items[] = ''; + $output .= t('Overall results: @summary', array('@summary' => _simpletest_format_summary_line($totals))); + $output .= '
'; + $output .= theme('item_list', $items, NULL, 'ul', array('class' => 'simpletest-results')); + return $output; +} + +/** + * Create a filter form used on the results page. + */ +function simpletest_filter_form() { + $form = array(); + $form['outcome'] = array( + '#type' => 'checkboxes', + '#title' => t('Filter by outcome'), + '#options' => array(), + '#attributes' => array('class' => 'container-inline'), + '#default_value' => array(), + ); + $categories = array('pass' => t('Passes'), 'fail' => t('Fails'), 'exception' => t('Exceptions')); + foreach ($categories as $outcome => $readable) { + $form['outcome'][$outcome] = array( + '#type' => 'checkbox', + '#title' => $readable, + '#attributes' => array('class' => 'simpletest-filter'), + '#default_value' => TRUE, + ); + } + return $form; +} + +/** + * Create a form containing the last run test classes so that they can bee run + * again. + */ +function simpletest_rerun_form($form_state, array $classes) { + $form = array(); + $form['#action'] = url('admin/build/testing/results/re-run'); + $form['classes_pass'] = array( + '#type' => 'hidden', + '#default_value' => implode(',', $classes['pass']) + ); + $form['classes_fail'] = array( + '#type' => 'hidden', + '#default_value' => implode(',', $classes['fail']) + ); + $form['actions'] = array( + '#prefix' => '