.\n\nRun the specified specified unit tests. If is omitted, all tests are run. should be a list of classes separated by a comma. For example: PageCreationTest,PageViewTest."); case 'drush:test list': return t("Usage drush [options] test list.\n\nList the available tests. Use drush test run command to run them. "); case 'drush:test clean': return t("Usage drush [options] test clean.\n\nClean leftover tables and file directories from prior test runs."); } } /** * Implementation of hook_drush_command(). */ function drush_simpletest_drush_command() { $items['test run'] = array( 'callback' => 'drush_test_run', 'description' => 'Run one or more Simpletest tests.', ); $items['test list'] = array( 'callback' => 'drush_test_list', 'description' => 'List the available Simpletest test classes.', ); $items['test clean'] = array( 'callback' => 'drush_test_clean', 'description' => 'Delete leftover tables and files from prior test runs.', ); return $items; } function drush_test_clean() { simpletest_clean_environment(); drush_print("Simpletest environment successfully cleaned."); } // If you want the rows returned to you instead of printed as a table, send $action = 'rows'. function drush_test_list($action = 'table') { $uncategorized_tests = simpletest_get_all_tests(); $tests = simpletest_categorize_tests($uncategorized_tests); $rows[] = array(t('Group'), t('Class'), t('Name')); foreach ($tests as $group_name => $test_group) { foreach ($test_group as $test) { $test_info = $test->getInfo(); $test_class = get_class($test); $title = $test_info['name']; $description = $test_info['description']; $rows[] = array($group_name, $test_class, $test_info['name']); } } return $action == 'table' ? drush_print_table($rows, 0, TRUE) : $rows; } /** * Present in plain text the failures for a given test run. * * @param $test_id * The test run for which results are needed. These are usually retrieved from $_SESSION['test_id'] */ function drush_results_table($test_id) { $result = db_query("SELECT * FROM {simpletest} WHERE test_id = %d ORDER BY test_class, message_id", $test_id); while ($row = db_fetch_object($result)) { if ($include_pass || $row->status != 'pass') { $rows[] = array( $row->message, $row->message_group, basename($row->file), $row->line, $row->caller, ); } } if (!isset($rows)) { drush_print(t("All tests passed.")); } else { $header = array(t('Message'), t('Group'), t('Filename'), t('Line'), t('Function')); array_unshift($rows, $header); drush_print_table($rows, 0, TRUE); } } // Command callback function drush_test_run($tests = NULL) { simpletest_get_all_tests(); if (is_null($tests)) { drush_print(t('Running all tests')); $rows = drush_test_list('rows'); unset($rows[0]); // Remove header row. foreach ($rows as $row) { $class_names[] = $row[1]; } } else { $class_names = explode(',', $tests); } foreach ($class_names as $class_name) { } if (count($class_names) > 0 ) { simpletest_run_tests($class_names); drush_results_table($_SESSION['test_id']); } else { drush_error(t('No test has been selected.'), 'error'); } }