'. 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. It integrates with the SimpleTest PHP library.', array('@simpletest-official' => 'http://www.simpletest.org/')) .'
';
$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: Selecting all tests may take several minutes to complete.)', array('@admin-simpletest' => url('admin/build/simpletest'))) .'
';
$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;
}
}
/**
* Implementation of hook_menu().
*/
function simpletest_menu() {
$items['admin/build/simpletest'] = array(
'title' => 'SimpleTest',
'page callback' => 'simpletest_entrypoint',
'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/build/simpletest/all'] = array(
'title' => 'All',
'page callback' => 'simpletest_entrypoint',
'access arguments' => array('administer unit tests'),
'type' => MENU_DEFAULT_LOCAL_TASK
);
$items['admin/build/simpletest/functional'] = array(
'title' => 'Functional',
'page callback' => 'simpletest_entrypoint',
'access arguments' => array('administer unit tests'),
'type' => MENU_LOCAL_TASK
);
$items['admin/build/simpletest/unit'] = array(
'title' => 'Unit',
'page callback' => 'simpletest_entrypoint',
'access arguments' => array('administer unit tests'),
'type' => MENU_LOCAL_TASK
);
$items['admin/settings/simpletest'] = array(
'title' => 'SimpleTest',
'description' => 'Configure SimpleTest framework.',
'page callback' => 'drupal_get_form',
'page arguments' => array('simpletest_settings'),
'access arguments' => array('access administration pages'),
);
return $items;
}
/**
* Implementation of hook_perm().
*/
function simpletest_perm() {
return array('administer unit tests');
}
/**
* Implemenation of hook_theme().
*/
function simpletest_theme() {
return array(
'simpletest_overview_form' => array(
'arguments' => array('form' => NULL)
),
);
}
/**
* Try to load the simepletest
* @return boolean TRUE if the load succeeded
*/
function simpletest_load() {
static $loaded;
if ($loaded) {
return true;
}
global $user;
if ($user->uid != 1) {
drupal_set_message(t('It is strongly suggested to run the tests with the first user!'));
}
$loaded = true;
if (!defined('SIMPLE_TEST')) {
define('SIMPLE_TEST', drupal_get_path('module', 'simpletest') .'/simpletest');
}
if (!is_dir(SIMPLE_TEST)) {
return simpletest_trigger_error('not available');
}
require_once(SIMPLE_TEST .'/simpletest.php');
require_once(SIMPLE_TEST .'/unit_tester.php');
require_once(SIMPLE_TEST .'/reporter.php');
require_once('drupal_reporter.php');
$path = drupal_get_path('module', 'simpletest') .'/';
require_once($path .'drupal_web_test_case.php');
require_once($path .'drupal_unit_test_case.php');
require_once($path .'drupal_unit_tests.php');
return true;
}
/**
* Menu callback for both running tests and listing possible tests
*/
function simpletest_entrypoint() {
global $simpletest_ua_key;
if (!simpletest_load()) {
// @TODO - Find a better way for this return. It is currently needed to show error,
// and returning true leads to page not found
return ' ';
}
if (!$simpletest_ua_key) {
$output = t('Please add the following code to the bottom of settings.php');
$output .=
'