You are here

public function SimpletestTestForm::submitForm in Zircon Profile 8

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

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

core/modules/simpletest/src/Form/SimpletestTestForm.php, line 206
Contains \Drupal\simpletest\Form\SimpletestTestForm.

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) {
  global $base_url;

  // Test discovery does not run upon form submission.
  simpletest_classloader_register();

  // 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();
  foreach ($form_state
    ->getValue('tests') as $class_name => $value) {
    if ($value === $class_name) {
      if (is_subclass_of($class_name, 'PHPUnit_Framework_TestCase')) {
        $test_type = 'phpunit';
      }
      else {
        $test_type = 'simpletest';
      }
      $tests_list[$test_type][] = $class_name;
    }
  }
  if (!empty($tests_list)) {
    putenv('SIMPLETEST_BASE_URL=' . $base_url);
    $test_id = simpletest_run_tests($tests_list, 'drupal');
    $form_state
      ->setRedirect('simpletest.result_form', array(
      'test_id' => $test_id,
    ));
  }
}