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 25 Jun 2008 02:59:32 -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'] : ''; Index: includes/form.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/form.inc,v retrieving revision 1.275 diff -u -p -r1.275 form.inc --- includes/form.inc 25 Jun 2008 09:57:07 -0000 1.275 +++ includes/form.inc 4 Jul 2008 06:12:46 -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 4 Jul 2008 05:35:13 -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: modules/simpletest/drupal_web_test_case.php =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v retrieving revision 1.24 diff -u -p -r1.24 drupal_web_test_case.php --- modules/simpletest/drupal_web_test_case.php 2 Jul 2008 20:05:11 -0000 1.24 +++ modules/simpletest/drupal_web_test_case.php 4 Jul 2008 02:35:04 -0000 @@ -20,6 +20,7 @@ class DrupalWebTestCase { protected $original_file_directory; var $_results = array('#pass' => 0, '#fail' => 0, '#exception' => 0); + var $_assertions = array(); /** * Constructor for DrupalWebTestCase. @@ -69,6 +70,14 @@ class DrupalWebTestCase { $current_db_prefix = $db_prefix; $db_prefix = $this->db_prefix_original; db_query("INSERT INTO {simpletest} (test_id, test_class, status, message, message_group, caller, line, file) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s')", $this->test_id, get_class($this), $status, $message, $group, $function['function'], $function['line'], $function['file']); + $this->_assertions[] = array( + 'status' => $status, + 'message' => $message, + 'group' => $group, + 'function' => $function['function'], + 'line' => $function['line'], + 'file' => $function['file'], + ); $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 4 Jul 2008 05:16:38 -0000 @@ -1,8 +1,5 @@ /* $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; @@ -17,46 +14,39 @@ 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; -} - -div.simpletest-pass { - color: #33a333; + background-color: #EDF5FA; } -div.simpletest-fail { - color: #a30000; -} - -tr.simpletest-pass.odd { - background: #b6ffb6; +div.simpletest-image { + display: inline; + cursor: pointer; } -tr.simpletest-pass.even { - background: #9bff9b; +li.simpletest-pass { + color: #33a333; } -tr.simpletest-fail.odd { - background: #ffc9c9; +li.simpletest-fail { + color: #db0000; } -tr.simpletest-fail.even { - background: #ffacac; +li.simpletest-exception { + color: #f5e742; } -tr.simpletest-exception.odd { - background: #f4ea71; +#simpletest-test-form > div > div.item-list { + padding-top: 10px; + padding-bottom: 10px; } -tr.simpletest-exception.even { - background: #f5e742; +ul.simpletest-results li div.item-list ul { + padding-left: 20px; } -div.simpletest-image { - display: inline; +ul.simpletest-results li span.simpletest-overview { cursor: pointer; -} +} \ 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 4 Jul 2008 06:54:37 -0000 @@ -27,6 +27,7 @@ Drupal.behaviors.simpleTestMenuCollapse } }); } + Drupal.behaviors.simpleTestSelectAll = function() { $('td.simpletest-select-all').each(function() { var checkboxes = Drupal.settings.simpleTest['simpletest-test-group-'+ $(this).attr('id')].testNames, totalCheckboxes = 0, @@ -60,4 +61,41 @@ Drupal.behaviors.simpleTestSelectAll = f } $(this).append(checkbox); }); +}; + +Drupal.behaviors.simpleTestFilterForm = function() { + var updateResults = function(type, checked) { + $('.simpletest-' + type + ':not(.simpletest-hidden)')[checked ? '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')); +}; + +Drupal.behaviors.simpleTestResultsCollapse = function() { + $('li > span.simpletest-overview').click(function() { + $(this).parent().children().filter('div.item-list').children().filter('ul').toggle().toggleClass('simpletest-hidden'); + }); + $('li > span.simpletest-overview').each(function() { + $(this).parent().children().filter('div.item-list').children().filter('ul').hide().addClass('simpletest-hidden'); + }); +}; + +Drupal.batchUpdate = {}; +Drupal.batchUpdate.simpleTestResultsCollapse = function() { + $('li > span.simpletest-overview').click(function() { + $(this).parent().children().filter('div.item-list').children().filter('ul').toggle().toggleClass('simpletest-hidden'); + }); + $('li > span.simpletest-overview').each(function() { + $(this).parent().children().filter('div.item-list').children().filter('ul').hide().addClass('simpletest-hidden'); + }); }; \ No newline at end of file Index: modules/simpletest/simpletest.module =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.module,v retrieving revision 1.5 diff -u -p -r1.5 simpletest.module --- modules/simpletest/simpletest.module 26 Jun 2008 21:07:59 -0000 1.5 +++ modules/simpletest/simpletest.module 4 Jul 2008 06:45:47 -0000 @@ -57,6 +57,9 @@ function simpletest_theme() { 'simpletest_result_summary' => array( 'arguments' => array('form' => NULL) ), + 'simpletest_results' => array( + 'arguments' => array('results' => NULL, 'assertions' => NULL), + ), ); } @@ -71,82 +74,30 @@ function simpletest_test_form() { if (isset($_SESSION['test_id'])) { $results = db_query("SELECT * FROM {simpletest} WHERE test_id = %d ORDER BY test_class, message_id", $_SESSION['test_id']); unset($_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'))); + $test_results = array(); + $test_assertions = array(); 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->caller, - $map[$status], - ), - 'class' => "simpletest-$status", - ); + if (empty($test_results[$result->test_class])) { + $class = $result->test_class; + $test = new $class(); + $info = $test->getInfo(); + $test_results[$class] = array('#fail' => 0, '#pass' => 0, '#exception' => 0); + foreach ($info as $key => $value) { + $test_results[$class]['#' . $key] = $value; + } } - unset($element); + $test_results[$result->test_class]['#' . $result->status]++; + $assertion = (array)$result; + $assertion['group'] = $assertion['message_group']; + unset($assertion['message_group']); + $assertion['function'] = $assertion['caller']; + unset($assertion['caller']); + $test_assertions[$result->test_class][] = $assertion; + $test_results[$class]['#ok'] = !($test_results[$class]['#fail'] + $test_results[$class]['#exception']); } - $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']['#value'] = 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; + $form['#results'] = $test_results; + $form['#assertions'] = $test_assertions; } foreach ($tests as $group_name => $test_group) { foreach ($test_group as $test) { @@ -202,6 +153,7 @@ function simpletest_test_form() { 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'); + $header = array( array('data' => t('Run'), 'class' => 'simpletest_run checkbox'), array('data' => t('Test'), 'class' => 'simpletest_test'), @@ -250,9 +202,11 @@ function theme_simpletest_test_form($for drupal_add_js(array('simpleTest' => $js), 'setting'); // Output test groups: $output = ''; - if (isset($form['results'])) { - $output .= drupal_render($form['summary']); - $output .= drupal_render($form['results']); + if (isset($form['#results'])) { + $output .= drupal_get_form('simpletest_filter_form'); + $output .= theme('simpletest_results', $form['#results'], $form['#assertions']); + $output .= l(t('Run more tests'), 'admin/build/testing'); + return $output; } if (count($rows)) { $output .= theme('table', $header, $rows, array('id' => 'simpletest-form-table')); @@ -263,12 +217,8 @@ function theme_simpletest_test_form($for return $output; } -function theme_simpletest_result_summary($form, $text = NULL) { - return '
' . _simpletest_format_summary_line($form) . '
'; -} - 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'), @@ -323,6 +273,7 @@ function simpletest_run_tests($test_list 'redirect' => 'admin/build/testing', 'progress_message' => t('Processing tests.'), 'css' => array(drupal_get_path('module', 'simpletest') .'/simpletest.css'), + 'js' => array(drupal_get_path('module', 'simpletest') .'/simpletest.js'), 'init_message' => t('SimpleTest is initializing...') . ' ' . format_plural(count($test_list), "one test case will run.", "@count test cases will run."), ); batch_set($batch); @@ -355,6 +306,7 @@ function _simpletest_batch_operation($te // Nth iteration: get the current values where we last stored them. $test_list = $context['sandbox']['tests']; $test_results = $context['sandbox']['test_results']; + $test_assertions = $context['sandbox']['test_assertions']; } $max = $context['sandbox']['max']; @@ -370,19 +322,18 @@ function _simpletest_batch_operation($te foreach ($test_results[$test_class] as $key => $value) { $test_results[$key] += $value; } - $test_results[$test_class]['#name'] = $info['name']; - $items = array(); - foreach (element_children($test_results) as $class) { - $items[] = '
' . t('@name: @summary', array('@name' => $test_results[$class]['#name'], '@summary' => _simpletest_format_summary_line($test_results[$class]))) . '
'; - } - $message = t('Processed test @num of @max - %test.', array('%test' => $info['name'], '@num' => $max - $size, '@max' => $max)); - $message .= theme('item_list', $items); - $context['message'] = $message; - // TODO: Do we want a summary of all? + $test_assertions[$test_class] = $test->_assertions; + foreach ($info as $key => $value) { + $test_results[$test_class]['#' . $key] = $value; + } + $test_results[$test_class]['#ok'] = !($test_results['#fail'] + $test_results['#exception']); + $context['message'] = t('Processed test @num of @max - %test.', array('%test' => $info['name'], '@num' => $max - $size, '@max' => $max)); + $context['message'] .= theme_simpletest_results($test_results, $test_assertions); // Save working values for the next iteration. $context['sandbox']['tests'] = $test_list; $context['sandbox']['test_results'] = $test_results; + $context['sandbox']['test_assertions'] = $test_assertions; // The test_id is the only thing we need to save for the report page. $context['results']['test_id'] = $test_id; @@ -391,7 +342,9 @@ function _simpletest_batch_operation($te } function _simpletest_batch_finished($success, $results, $operations) { - $_SESSION['test_id'] = $results['test_id']; + if (isset($results['test_id'])) { + $_SESSION['test_id'] = $results['test_id']; + } if ($success) { drupal_set_message(t('The tests have finished running.')); } @@ -468,6 +421,52 @@ function simpletest_categorize_tests($te } /** + * Theme simpletest results. + * + * @param $results + * A nested array of simpletest results. + * @param $assertions + * An array of assertions for each test. + * @return + * A nested list of simpletest items. + */ +function theme_simpletest_results($results, $assertions) { + $items = array(); + $group_data = array(); + foreach (element_children($results) as $class) { + $item = array(); + foreach ($results[$class] as $key => $value) { + if ($key == '#ok') { + $group_data[$results[$class]['#group']][$key] = isset($group_data[$results[$class]['#group']][$key]) ? $group_data[$results[$class]['#group']][$key] && $value : $value; + } + else { + $group_data[$results[$class]['#group']][$key] = isset($group_data[$results[$class]['#group']][$key]) ? $group_data[$results[$class]['#group']][$key] + $value : $value; + } + } + $item['class'] = $results[$class]['#ok'] ? 'simpletest-pass' : 'simpletest-fail'; + $item['data'] = '' . t('@name: @summary', array('@name' => $results[$class]['#name'], '@summary' => _simpletest_format_summary_line($results[$class]))) . ''; + $assertion_items = array(); + foreach ($assertions[$class] as $assertion) { + $assertion_items[] = array( + 'data' => '' . $assertion['message'] . '', + 'class' => ($assertion['status'] == 'pass' ? 'simpletest-pass' : 'simpletest-fail'), + 'children' => array( + t('Group: @group', array('@group' => $assertion['group'])), + t('File: @file', array('@file' => basename($assertion['file']))), + t('Function: @function', array('@function' => $assertion['function'])), + t('Line: @line', array('@line' => $assertion['line'])), + ), + ); + } + $item['children'] = $assertion_items; + $items[$results[$class]['#group']]['children'][] = $item; + $items[$results[$class]['#group']]['data'] = '' . t('@name: @summary', array('@name' => $results[$class]['#group'], '@summary' => _simpletest_format_summary_line($group_data[$results[$class]['#group']]))) . ''; + $items[$results[$class]['#group']]['class'] = $group_data[$results[$class]['#group']]['#ok'] ? 'simpletest-pass' : 'simpletest-fail'; + } + return theme('item_list', $items, NULL, 'ul', array('class' => 'simpletest-results')); +} + +/** * Remove all temporary database tables and directories. */ function simpletest_clean_environment() { @@ -544,6 +543,30 @@ function simpletest_clean_temporary_dire } /** + * FAPI callback for the filtering form. + */ +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; +} + +/** * Remove all files from specified firectory and then remove directory. * * @param string $path Directory path. Index: modules/simpletest/simpletest.test =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.test,v retrieving revision 1.3 diff -u -p -r1.3 simpletest.test --- modules/simpletest/simpletest.test 24 Jun 2008 21:51:02 -0000 1.3 +++ modules/simpletest/simpletest.test 4 Jul 2008 06:48:31 -0000 @@ -88,11 +88,11 @@ class SimpleTestTestCase extends DrupalW * Confirm that the stub test produced the desired results. */ function confirmStubTestResults() { - $this->assertAssertion($this->pass, 'Other', 'Pass'); - $this->assertAssertion($this->fail, 'Other', 'Fail'); + $this->assertAssertion($this->pass, 'Other'); + $this->assertAssertion($this->fail, 'Other'); - $this->assertAssertion(t('Created permissions: @perms', array('@perms' => $this->valid_permission)), 'Role', 'Pass'); - $this->assertAssertion(t('Invalid permission %permission.', array('%permission' => $this->invalid_permission)), 'Role', 'Fail'); + $this->assertAssertion(t('Created permissions: @perms', array('@perms' => $this->valid_permission)), 'Role'); + $this->assertAssertion(t('Invalid permission %permission.', array('%permission' => $this->invalid_permission)), 'Role'); } /** @@ -104,18 +104,17 @@ class SimpleTestTestCase extends DrupalW * @param string $status Assertion status. * @return Assertion result. */ - function assertAssertion($message, $type, $status) { + function assertAssertion($message, $type) { $message = trim(strip_tags($message)); $found = FALSE; - foreach ($this->results['assertions'] as $assertion) { + foreach ($this->results as $assertion) { if ($assertion['message'] == $message && - $assertion['type'] == $type && - $assertion['status'] == $status) { + $assertion['type'] == $type) { $found = TRUE; break; } } - return $this->assertTrue($found, t('Found assertion {"@message", "@type", "@status"}.', array('@message' => $message, '@type' => $type, '@status' => $status))); + return $this->assertTrue($found, t('Found assertion {"@message", "@type"}.', array('@message' => $message, '@type' => $type))); } /** @@ -125,20 +124,13 @@ class SimpleTestTestCase extends DrupalW $results = array(); if ($this->parse()) { - if ($fieldset = $this->getResultFieldSet()) { - // Code assumes this is the only test in group. - $results['summary'] = $this->asText($fieldset->div); - $results['name'] = $this->asText($fieldset->fieldset->legend); - - $results['assertions'] = array(); - $tbody = $fieldset->fieldset->table->tbody; - foreach ($tbody->tr as $row) { + if ($list = $this->getResultList()) { + $results = array(); + foreach ($list->li as $li) { $assertion = array(); - $assertion['message'] = $this->asText($row->td[0]); - $assertion['type'] = $this->asText($row->td[1]); - $ok_url = (url('misc/watchdog-ok.png') == 'misc/watchdog-ok.png') ? 'misc/watchdog-ok.png' : (base_path() . 'misc/watchdog-ok.png'); - $assertion['status'] = ($row->td[5]->img['src'] == $ok_url) ? 'Pass' : 'Fail'; - $results['assertions'][] = $assertion; + $assertion['message'] = $this->asText($li->span); + $assertion['type'] = str_replace('Group: ', '', $this->asText($li->div->ul->li[0])); + $results[] = $assertion; } } } @@ -150,12 +142,11 @@ class SimpleTestTestCase extends DrupalW * * @return fieldset containing the results for group this test is in. */ - function getResultFieldSet() { - $fieldsets = $this->elements->xpath('//fieldset'); - $info = $this->getInfo(); - foreach ($fieldsets as $fieldset) { - if ($fieldset->legend == $info['group']) { - return $fieldset; + function getResultList() { + $lis = $this->elements->xpath('//li'); + foreach ($lis as $li) { + if (strpos($this->asText($li->span), t('SimpleTest: ')) === 0) { + return $li->div->ul->li->div->ul; } } return FALSE;