';
+}
+
+/**
+ * Get test results for $test_id.
+ *
+ * @param $test_id The test_id to retrieve results of.
+ * @return Array of results grouped by test_class.
+ */
+function simpletest_result_get($test_id) {
+ $results = db_select('simpletest')
+ ->fields('simpletest')
+ ->condition('test_id', $test_id)
+ ->orderBy('test_class')
+ ->orderBy('message_id')
+ ->execute();
+
+ $test_results = array();
+ foreach ($results as $result) {
+ if (!isset($test_results[$result->test_class])) {
+ $test_results[$result->test_class] = array();
+ }
+ $test_results[$result->test_class][] = $result;
+ }
+ return $test_results;
+}
+
+/**
+ * Get the appropriate image for the status.
+ *
+ * @param $status Status string, either: pass, fail, exception.
+ * @return HTML image or false.
+ */
+function simpletest_result_status_image($status) {
+ // $map does not use drupal_static() as its value never changes.
+ static $map;
+
+ if (!isset($map)) {
+ $map = array(
+ 'pass' => theme('image', array('path' => 'misc/watchdog-ok.png', 'width' => 18, 'height' => 18, 'alt' => t('Pass'))),
+ 'fail' => theme('image', array('path' => 'misc/watchdog-error.png', 'width' => 18, 'height' => 18, 'alt' => t('Fail'))),
+ 'exception' => theme('image', array('path' => 'misc/watchdog-warning.png', 'width' => 18, 'height' => 18, 'alt' => t('Exception'))),
+ 'debug' => theme('image', array('path' => 'misc/watchdog-warning.png', 'width' => 18, 'height' => 18, 'alt' => t('Debug'))),
+ );
+ }
+ if (isset($map[$status])) {
+ return $map[$status];
+ }
+ return FALSE;
+}
+
+/**
+ * Provides settings form for SimpleTest variables.
+ *
+ * @ingroup forms
+ * @see simpletest_settings_form_validate()
+ */
+function simpletest_settings_form($form, &$form_state) {
+ $form['general'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('General'),
+ );
+ $form['general']['simpletest_clear_results'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Clear results after each complete test suite run'),
+ '#description' => t('By default SimpleTest will clear the results after they have been viewed on the results page, but in some cases it may be useful to leave the results in the database. The results can then be viewed at admin/config/development/testing/[test_id]. The test ID can be found in the database, simpletest table, or kept track of when viewing the results the first time. Additionally, some modules may provide more analysis or features that require this setting to be disabled.'),
+ '#default_value' => variable_get('simpletest_clear_results', TRUE),
+ );
+ $form['general']['simpletest_verbose'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Provide verbose information when running tests'),
+ '#description' => t('The verbose data will be printed along with the standard assertions and is useful for debugging. The verbose data will be erased between each test suite run. The verbose data output is very detailed and should only be used when debugging.'),
+ '#default_value' => variable_get('simpletest_verbose', TRUE),
+ );
+
+ $form['httpauth'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('HTTP authentication'),
+ '#description' => t('HTTP auth settings to be used by the SimpleTest browser during testing. Useful when the site requires basic HTTP authentication.'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ );
+ $form['httpauth']['simpletest_httpauth_method'] = array(
+ '#type' => 'select',
+ '#title' => t('Method'),
+ '#options' => array(
+ CURLAUTH_BASIC => t('Basic'),
+ CURLAUTH_DIGEST => t('Digest'),
+ CURLAUTH_GSSNEGOTIATE => t('GSS negotiate'),
+ CURLAUTH_NTLM => t('NTLM'),
+ CURLAUTH_ANY => t('Any'),
+ CURLAUTH_ANYSAFE => t('Any safe'),
+ ),
+ '#default_value' => variable_get('simpletest_httpauth_method', CURLAUTH_BASIC),
+ );
+ $username = variable_get('simpletest_httpauth_username');
+ $password = variable_get('simpletest_httpauth_password');
+ $form['httpauth']['simpletest_httpauth_username'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Username'),
+ '#default_value' => $username,
+ );
+ if ($username && $password) {
+ $form['httpauth']['simpletest_httpauth_username']['#description'] = t('Leave this blank to delete both the existing username and password.');
+ }
+ $form['httpauth']['simpletest_httpauth_password'] = array(
+ '#type' => 'password',
+ '#title' => t('Password'),
+ );
+ if ($password) {
+ $form['httpauth']['simpletest_httpauth_password']['#description'] = t('To change the password, enter the new password here.');
+ }
+
+ return system_settings_form($form);
+}
+
+/**
+ * Validation handler for simpletest_settings_form().
+ */
+function simpletest_settings_form_validate($form, &$form_state) {
+ // If a username was provided but a password wasn't, preserve the existing
+ // password.
+ if (!empty($form_state['values']['simpletest_httpauth_username']) && empty($form_state['values']['simpletest_httpauth_password'])) {
+ $form_state['values']['simpletest_httpauth_password'] = variable_get('simpletest_httpauth_password', '');
+ }
+
+ // If a password was provided but a username wasn't, the credentials are
+ // incorrect, so throw an error.
+ if (empty($form_state['values']['simpletest_httpauth_username']) && !empty($form_state['values']['simpletest_httpauth_password'])) {
+ form_set_error('simpletest_httpauth_username', t('HTTP authentication credentials must include a username in addition to a password.'));
+ }
+}
+