' . t('The SimpleTest module is a framework for running automated unit tests in Drupal. It can be used to verify a working state of Drupal before and after any code changes, or as a means for developers to write and execute tests for their modules.') . '
'; $output .= '' . t('Visit Administer >> Site building >> SimpleTest to display a list of available tests. For comprehensive testing, select all tests, or individually select tests for more targeted testing. Note that it might take several minutes for all tests to complete.)', array('@admin-simpletest' => url('admin/development/testing'))) . '
'; $output .= '' . t('After the tests have run, a message will be displayed next to each test group indicating whether tests within it passed, failed, or had exceptions. A pass means that a test returned the expected results, while fail means that it did not. An exception normally indicates an error outside of the test, such as a PHP warning or notice. If there were fails or exceptions, the results are expanded, and the tests that had issues will be indicated in red or pink rows. Use these results to refine your code and tests until all tests return a pass.') . '
'; $output .= '' . t('For more information on creating and modifying your own tests, see the SimpleTest API Documentation in the Drupal handbook.', array('@simpletest-api' => 'http://drupal.org/simpletest')) . '
'; $output .= '' . t('For more information, see the online handbook entry for SimpleTest module.', array('@simpletest' => 'http://drupal.org/handbook/modules/simpletest')) . '
'; return $output; } } /** * Implement hook_menu(). */ function simpletest_menu() { $items['admin/development/testing'] = array( 'title' => 'Testing', 'page callback' => 'drupal_get_form', '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'), ); $items['admin/development/testing/results/%'] = array( 'title' => 'Test result', 'page callback' => 'drupal_get_form', 'page arguments' => array('simpletest_result_form', 4), 'description' => 'View result of tests.', 'access arguments' => array('administer unit tests'), 'type' => MENU_CALLBACK, ); return $items; } /** * Implement hook_perm(). */ function simpletest_perm() { return array( 'administer unit tests' => array( 'title' => t('Administer unit tests'), 'description' => t('Manage and run automated testing. %warning', array('%warning' => t('Warning: Give to trusted roles only; this permission has security implications.'))), ), ); } /** * Implement hook_theme(). */ function simpletest_theme() { return array( 'simpletest_test_table' => array( 'arguments' => array('table' => NULL), 'file' => 'simpletest.pages.inc', ), 'simpletest_result_summary' => array( 'arguments' => array('form' => NULL), 'file' => 'simpletest.pages.inc', ), ); } /** * Implement hook_js_alter(). */ function simpletest_js_alter(&$javascript) { // Since SimpleTest is a special use case for the table select, stick the // SimpleTest JavaScript above the table select. $simpletest = drupal_get_path('module', 'simpletest') . '/simpletest.js'; if (array_key_exists($simpletest, $javascript) && array_key_exists('misc/tableselect.js', $javascript)) { $javascript[$simpletest]['weight'] = $javascript['misc/tableselect.js']['weight'] - 1; } } function _simpletest_format_summary_line($summary) { 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'), )); } /** * Actually runs tests. * * @param $test_list * List of tests to run. * @param $reporter * Which reporter to use. Allowed values are: text, xml, html and drupal, * drupal being the default. */ function simpletest_run_tests($test_list, $reporter = 'drupal') { cache_clear_all(); $test_id = db_insert('simpletest_test_id') ->useDefaults(array('test_id')) ->execute(); // Get the info for the first test being run. $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', 'progress_message' => '', 'css' => array(drupal_get_path('module', 'simpletest') . '/simpletest.css'), 'init_message' => t('Processing test @num of @max - %test.', array('%test' => $info['name'], '@num' => '1', '@max' => count($test_list))), ); batch_set($batch); module_invoke_all('test_group_started'); // Normally, the forms portion of the batch API takes care of calling // batch_process(), but in the process it saves the whole $form into the // database (which is huge for the test selection form). // By calling batch_process() directly, we skip that behavior and ensure // that we don't exceed the size of data that can be sent to the database // (max_allowed_packet on MySQL). batch_process('admin/development/testing/results/' . $test_id); } /** * Batch operation callback. */ function _simpletest_batch_operation($test_list_init, $test_id, &$context) { // Get working values. if (!isset($context['sandbox']['max'])) { // First iteration: initialize working values. $test_list = $test_list_init; $context['sandbox']['max'] = count($test_list); $test_results = array('#pass' => 0, '#fail' => 0, '#exception' => 0); } else { // Nth iteration: get the current values where we last stored them. $test_list = $context['sandbox']['tests']; $test_results = $context['sandbox']['test_results']; } $max = $context['sandbox']['max']; // Perform the next test. $test_class = array_shift($test_list); $test = new $test_class($test_id); $test->run(); $size = count($test_list); $info = $test->getInfo(); module_invoke_all('test_finished', $test->results); // Gather results and compose the report. $test_results[$test_class] = $test->results; 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) { array_unshift($items, '