You are here

public function SimpletestResultsForm::buildForm 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::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

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

Class

SimpletestResultsForm
Test results form for $test_id.

Namespace

Drupal\simpletest\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $test_id = NULL) {

  // Make sure there are test results to display and a re-run is not being
  // performed.
  $results = array();
  if (is_numeric($test_id) && !($results = $this
    ->getResults($test_id))) {
    drupal_set_message($this
      ->t('No test results to display.'), 'error');
    return new RedirectResponse($this
      ->url('simpletest.test_form', array(), array(
      'absolute' => TRUE,
    )));
  }

  // Load all classes and include CSS.
  $form['#attached']['library'][] = 'simpletest/drupal.simpletest';

  // Add the results form.
  $filter = static::addResultForm($form, $results, $this
    ->getStringTranslation());

  // Actions.
  $form['#action'] = $this
    ->url('simpletest.result_form', array(
    'test_id' => 're-run',
  ));
  $form['action'] = array(
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Actions'),
    '#attributes' => array(
      'class' => array(
        'container-inline',
      ),
    ),
    '#weight' => -11,
  );
  $form['action']['filter'] = array(
    '#type' => 'select',
    '#title' => 'Filter',
    '#options' => array(
      'all' => $this
        ->t('All (@count)', array(
        '@count' => count($filter['pass']) + count($filter['fail']),
      )),
      'pass' => $this
        ->t('Pass (@count)', array(
        '@count' => count($filter['pass']),
      )),
      'fail' => $this
        ->t('Fail (@count)', array(
        '@count' => count($filter['fail']),
      )),
    ),
  );
  $form['action']['filter']['#default_value'] = $filter['fail'] ? 'fail' : 'all';

  // Categorized test classes for to be used with selected filter value.
  $form['action']['filter_pass'] = array(
    '#type' => 'hidden',
    '#default_value' => implode(',', $filter['pass']),
  );
  $form['action']['filter_fail'] = array(
    '#type' => 'hidden',
    '#default_value' => implode(',', $filter['fail']),
  );
  $form['action']['op'] = array(
    '#type' => 'submit',
    '#value' => $this
      ->t('Run tests'),
  );
  $form['action']['return'] = array(
    '#type' => 'link',
    '#title' => $this
      ->t('Return to list'),
    '#url' => Url::fromRoute('simpletest.test_form'),
  );
  if (is_numeric($test_id)) {
    simpletest_clean_results_table($test_id);
  }
  return $form;
}