summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/simpletest/simpletest.module40
-rwxr-xr-xscripts/run-tests.sh5
2 files changed, 29 insertions, 16 deletions
diff --git a/modules/simpletest/simpletest.module b/modules/simpletest/simpletest.module
index 5476a9795..fe3127758 100644
--- a/modules/simpletest/simpletest.module
+++ b/modules/simpletest/simpletest.module
@@ -123,10 +123,7 @@ function simpletest_test_form() {
}
// 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']);
- }
+ simpletest_clean_results_table($_SESSION['test_id']);
unset($_SESSION['test_id']);
$all_ok = TRUE;
@@ -515,7 +512,8 @@ function simpletest_categorize_tests($tests) {
function simpletest_clean_environment() {
simpletest_clean_database();
simpletest_clean_temporary_directories();
- simpletest_clean_results_table();
+ $count = simpletest_clean_results_table();
+ drupal_set_message(t('Removed @count test results.', array('@count' => $count)));
}
/**
@@ -564,16 +562,34 @@ function simpletest_clean_temporary_directories() {
}
/**
- * Clear the test results tables.
+ * Clear the test result tables.
+ *
+ * @param $test_id
+ * Test ID to remove results for, or NULL to remove all results.
+ * @return
+ * The number of results removed or FALSE.
*/
-function simpletest_clean_results_table() {
+function simpletest_clean_results_table($test_id = NULL) {
if (variable_get('simpletest_clear_results', TRUE)) {
- $count = db_result(db_query('SELECT COUNT(test_id) FROM {simpletest_test_id}'));
+ if ($test_id) {
+ $count = db_result(db_query('SELECT COUNT(test_id) FROM {simpletest_test_id} WHERE test_id = :test_id', array(':test_id' => $test_id)));
+
+ db_delete("simpletest")
+ ->condition('test_id', $test_id)
+ ->execute();
+ db_delete("simpletest_test_id")
+ ->condition('test_id', $test_id)
+ ->execute();
+ }
+ else {
+ $count = db_result(db_query('SELECT COUNT(test_id) FROM {simpletest_test_id}'));
- // Clear test results.
- db_query('DELETE FROM {simpletest}');
- db_query('DELETE FROM {simpletest_test_id}');
+ // Clear test results.
+ db_delete("simpletest")->execute();
+ db_delete("simpletest_test_id")->execute();
+ }
- drupal_set_message(t('Removed @count test results.', array('@count' => $count)));
+ return $count;
}
+ return FALSE;
}
diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh
index f53ad1937..c593e7c52 100755
--- a/scripts/run-tests.sh
+++ b/scripts/run-tests.sh
@@ -81,10 +81,7 @@ simpletest_script_command($args['concurrency'], $test_id, implode(",", $test_lis
simpletest_script_reporter_display_results();
// Cleanup our test results.
-db_delete("simpletest")
- ->condition('test_id', $test_id)
- ->execute();
-
+simpletest_clean_results_table($test_id);
/**
* Print help text.