You are here

public static function SimpletestResultsForm::addResultForm in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/src/Form/SimpletestResultsForm.php \Drupal\simpletest\Form\SimpletestResultsForm::addResultForm()

Adds the result form to a $form.

This is a static method so that run-tests.sh can use it to generate a results page completely external to Drupal. This is why the UI strings are not wrapped in t().

Parameters

array $form: The form to attach the results to.

array $test_results: The simpletest results.

Return value

array A list of tests the passed and failed. The array has two keys, 'pass' and 'fail'. Each contains a list of test classes.

See also

simpletest_script_open_browser()

run-tests.sh

1 call to SimpletestResultsForm::addResultForm()
SimpletestResultsForm::buildForm in core/modules/simpletest/src/Form/SimpletestResultsForm.php
Form constructor.

File

core/modules/simpletest/src/Form/SimpletestResultsForm.php, line 253
Contains \Drupal\simpletest\Form\SimpletestResultsForm.

Class

SimpletestResultsForm
Test results form for $test_id.

Namespace

Drupal\simpletest\Form

Code

public static function addResultForm(array &$form, array $results) {

  // Transform the test results to be grouped by test class.
  $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;
  }
  $image_status_map = static::buildStatusImageMap();

  // Keep track of which test cases passed or failed.
  $filter = array(
    'pass' => array(),
    'fail' => array(),
  );

  // Summary result widget.
  $form['result'] = array(
    '#type' => 'fieldset',
    '#title' => 'Results',
    // Because this is used in a theme-less situation need to provide a
    // default.
    '#attributes' => array(),
  );
  $form['result']['summary'] = $summary = array(
    '#theme' => 'simpletest_result_summary',
    '#pass' => 0,
    '#fail' => 0,
    '#exception' => 0,
    '#debug' => 0,
  );
  \Drupal::service('test_discovery')
    ->registerTestNamespaces();

  // Cycle through each test group.
  $header = array(
    'Message',
    'Group',
    'Filename',
    'Line',
    'Function',
    array(
      'colspan' => 2,
      'data' => 'Status',
    ),
  );
  $form['result']['results'] = array();
  foreach ($test_results as $group => $assertions) {

    // Create group details with summary information.
    $info = TestDiscovery::getTestInfo($group);
    $form['result']['results'][$group] = array(
      '#type' => 'details',
      '#title' => $info['name'],
      '#open' => TRUE,
      '#description' => $info['description'],
    );
    $form['result']['results'][$group]['summary'] = $summary;
    $group_summary =& $form['result']['results'][$group]['summary'];

    // Create table of assertions for the group.
    $rows = array();
    foreach ($assertions as $assertion) {
      $row = array();
      $row[] = [
        'data' => [
          '#markup' => $assertion->message,
        ],
      ];
      $row[] = $assertion->message_group;
      $row[] = \Drupal::service('file_system')
        ->basename($assertion->file);
      $row[] = $assertion->line;
      $row[] = $assertion->function;
      $row[] = [
        'data' => $image_status_map[$assertion->status],
      ];
      $class = 'simpletest-' . $assertion->status;
      if ($assertion->message_group == 'Debug') {
        $class = 'simpletest-debug';
      }
      $rows[] = array(
        'data' => $row,
        'class' => array(
          $class,
        ),
      );
      $group_summary['#' . $assertion->status]++;
      $form['result']['summary']['#' . $assertion->status]++;
    }
    $form['result']['results'][$group]['table'] = array(
      '#type' => 'table',
      '#header' => $header,
      '#rows' => $rows,
    );

    // Set summary information.
    $group_summary['#ok'] = $group_summary['#fail'] + $group_summary['#exception'] == 0;
    $form['result']['results'][$group]['#open'] = !$group_summary['#ok'];

    // Store test group (class) as for use in filter.
    $filter[$group_summary['#ok'] ? 'pass' : 'fail'][] = $group;
  }

  // Overall summary status.
  $form['result']['summary']['#ok'] = $form['result']['summary']['#fail'] + $form['result']['summary']['#exception'] == 0;
  return $filter;
}