Index: modules/simpletest/drupal_web_test_case.php =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v retrieving revision 1.13 diff -u -r1.13 drupal_web_test_case.php --- modules/simpletest/drupal_web_test_case.php 3 Jun 2008 19:53:42 -0000 1.13 +++ modules/simpletest/drupal_web_test_case.php 4 Jun 2008 00:03:22 -0000 @@ -198,12 +198,13 @@ $form_state['values'] = array('status' => $this->_modules, 'op' => t('Save configuration')); drupal_execute('system_modules', $form_state); - //rebuilding all caches + // Rebuilding all caches drupal_rebuild_theme_registry(); node_types_rebuild(); menu_rebuild(); cache_clear_all('schema', 'cache'); module_rebuild_cache(); + module_list(TRUE); return $this->assertTrue(module_exists($name), t('@name enabled.', array('@name' => $name)), t('Module')); } Index: modules/simpletest/simpletest.module =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.module,v retrieving revision 1.3 diff -u -r1.3 simpletest.module --- modules/simpletest/simpletest.module 10 May 2008 07:46:22 -0000 1.3 +++ modules/simpletest/simpletest.module 4 Jun 2008 02:24:12 -0000 @@ -82,24 +82,20 @@ simpletest_load(); drupal_add_css(drupal_get_path('module', 'simpletest') . '/simpletest.css', 'module'); drupal_add_js(drupal_get_path('module', 'simpletest') . '/simpletest.js', 'module'); - $output = drupal_get_form('simpletest_overview_form'); - if (simpletest_running_output()) { - return simpletest_running_output() . $output; + $output = drupal_get_form('simpletest_overview_form'); + + if (isset($_SESSION['simpletest_reporter'])) { + $reporter = unserialize($_SESSION['simpletest_reporter']); + $output = $reporter->getOutput() . drupal_get_form('simpletest_overview_form'); + unset($_SESSION['simpletest_reporter']); + return $output; } else { return $output; } } -function simpletest_running_output($output = NULL) { - static $o; - if ($output != NULL) { - $o = $output; - } - return $o; -} - /** * Form callback; make the form to run tests */ @@ -280,7 +276,6 @@ drupal_set_message(t('No test has been selected.'), 'error'); } - simpletest_running_output($output); return FALSE; } @@ -387,7 +382,8 @@ static $test_running; if (!$test_running) { $test_running = TRUE; - $test = simpletest_get_total_test($test_list); + $batch = FALSE; + $tests = simpletest_get_total_test($test_list); switch ($reporter) { case 'text': $reporter = &new TextReporter(); @@ -399,26 +395,81 @@ $reporter = &new HtmlReporter(); break; case 'drupal': + $batch = TRUE; $reporter = &new DrupalReporter(); break; } cache_clear_all(); - $results = $test->run($reporter); - $test_running = FALSE; - switch (get_class($reporter)) { - case 'TextReporter': - case 'XMLReporter': - case 'HtmlReporter': - return $results; - case 'DrupalReporter': - return $reporter->getOutput(); + if ($batch) { + $operations = array(); + $operations[] = array('_simpletest_batch_operation', array(serialize($tests), serialize($reporter))); + + $batch = array( + 'title' => t('Running SimpleTests'), + 'operations' => $operations, + 'finished' => '_simpletest_batch_finished', + 'redirect' => 'admin/build/testing', + 'progressive' => TRUE, + ); + batch_set($batch); + } + else { + $results = $tests->run($reporter); + $test_running = FALSE; + return $results; } } } /** + * Batch operation callback. + */ +function _simpletest_batch_operation($tests, $reporter, &$context) { + // Ensure that all classes are loaded. + simpletest_get_total_test(); + $reporter = unserialize( isset($context['sandbox']['reporter']) ? $context['sandbox']['reporter'] : $reporter); + $tests = unserialize( isset($context['sandbox']['tests']) ? $context['sandbox']['tests'] : $tests); + + if (!isset($content['sandbox']['progress'])) { + $context['sandbox']['progress'] = 0; + $context['sandbox']['max'] = $tests->getSize(); + } + + $test_ran = $tests->runOneByOne($reporter); + $context['sandbox']['progress']++; + + $context['message'] = t('Processed test %test', array('%test' => $test_ran)); + + // Put back the reporter and tests + $context['sandbox']['reporter'] = serialize($reporter); + $context['sandbox']['tests'] = serialize($tests); + + // Multistep processing: report progress. + if (($size = $tests->getSize()) != 0) { + $context['finished'] = 1 - $size / $context['sandbox']['max']; + } + else { + // Finished: save the reporter + $context['results'][] = $context['sandbox']['reporter']; + } +} + +/** + * Batch finished callback. + */ +function _simpletest_batch_finished($success, $results, $operations) { + $_SESSION['simpletest_reporter'] = array_pop($results); + if ($success) { + drupal_set_message(t('The tests have finished running.')); + } + else { + drupal_set_message(t('The tests did not successfully finish.'), 'error'); + } +} + +/** * This function makes sure no unnecessary copies of the DrupalTests object are instantiated * @param array $classes list of all classes the test should concern or * DEFAULT NULL @@ -473,5 +524,4 @@ ); return system_settings_form($form); - } Index: modules/simpletest/test_case.php =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/test_case.php,v retrieving revision 1.3 diff -u -r1.3 test_case.php --- modules/simpletest/test_case.php 10 May 2008 06:55:09 -0000 1.3 +++ modules/simpletest/test_case.php 4 Jun 2008 02:24:43 -0000 @@ -390,6 +390,7 @@ class TestSuite { var $_label; var $_test_cases; + var $_already_ran = false; /** * Sets the name of the test suite. @@ -509,6 +510,40 @@ return $reporter->getStatus(); } + function runOneByOne(&$reporter) { + if (!$this->_already_ran) { + $this->_already_ran = TRUE; + $reporter->paintGroupStart($this->getLabel(), $this->getSize()); + } + + error_log("In runOneByOne, found: ".serialize($this->_test_cases)); + + $test = array_shift($this->_test_cases); + if (is_string($test)) { + $test = &new $test(); + } + + if (is_a($test, 'TestSuite')) { + $test_ran = $test->runOneByOne($reporter); + array_unshift($this->_test_cases, $test); + } + else { + $test->run($reporter); + $test_ran = $test->getLabel(); + } + + if (count($this->_test_cases) == 0) { + $reporter->paintGroupEnd($this->getLabel()); + } + return $test_ran; + } + /** * Number of contained test cases. * @return integer Total count of cases in the group.