You are here

public function SimpletestTestForm::submitForm in SimpleTest 8.3

Form submission handler.

Parameters

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

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

Overrides FormInterface::submitForm

File

src/Form/SimpletestTestForm.php, line 219

Class

SimpletestTestForm
List tests arranged in groups that can be selected and run.

Namespace

Drupal\simpletest\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Test discovery does not run upon form submission.
  $this->testDiscovery
    ->registerTestNamespaces();

  // This form accepts arbitrary user input for 'tests'.
  // An invalid value will cause the $class_name lookup below to die with a
  // fatal error. Regular user access mechanisms to this form are intact.
  // The only validation effectively being skipped is the validation of
  // available checkboxes vs. submitted checkboxes.
  // @todo Refactor Form API to allow to POST values without constructing the
  //   entire form more easily, BUT retaining routing access security and
  //   retaining Form API CSRF #token security validation, and without having
  //   to rely on form caching.
  $user_input = $form_state
    ->getUserInput();
  if ($form_state
    ->isValueEmpty('tests') && !empty($user_input['tests'])) {
    $form_state
      ->setValue('tests', $user_input['tests']);
  }
  $tests_list = array_filter($form_state
    ->getValue('tests'));
  if (!empty($tests_list)) {
    $test_id = simpletest_run_tests($tests_list, 'drupal');
    $form_state
      ->setRedirect('simpletest.result_form', [
      'test_id' => $test_id,
    ]);
  }
}