/**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     // 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.
     if (empty($form_state['values']['tests']) && !empty($form_state['input']['tests'])) {
         $form_state['values']['tests'] = $form_state['input']['tests'];
     }
     $tests_list = array();
     foreach ($form_state['values']['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)) {
         $test_id = simpletest_run_tests($tests_list, 'drupal');
         $form_state['redirect_route'] = array('route_name' => 'simpletest.result_form', 'route_parameters' => array('test_id' => $test_id));
     }
 }
 /**
  * {@inheritdoc}
  */
 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));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function boot()
 {
     // Ensure that required Settings exist.
     if (!Settings::getAll()) {
         new Settings(array('hash_salt' => 'run-tests'));
     }
     // Remove Drupal's error/exception handlers; they are designed for HTML
     // and there is no storage nor a (watchdog) logger here.
     restore_error_handler();
     restore_exception_handler();
     // In addition, ensure that PHP errors are not hidden away in logs.
     ini_set('display_errors', TRUE);
     parent::boot();
     $this->getContainer()->get('module_handler')->loadAll();
     simpletest_classloader_register();
 }
 /**
  * {@inheritdoc}
  */
 public function boot()
 {
     // Ensure that required Settings exist.
     if (!Settings::getAll()) {
         new Settings(array('hash_salt' => 'run-tests', 'file_public_path' => 'sites/default/files'));
     }
     // Remove Drupal's error/exception handlers; they are designed for HTML
     // and there is no storage nor a (watchdog) logger here.
     restore_error_handler();
     restore_exception_handler();
     // In addition, ensure that PHP errors are not hidden away in logs.
     ini_set('display_errors', TRUE);
     parent::boot();
     $this->getContainer()->get('module_handler')->loadAll();
     simpletest_classloader_register();
     // Create the build/artifacts directory if necessary.
     if (!is_dir('public://simpletest')) {
         mkdir('public://simpletest', 0777, TRUE);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, array &$form_state, $test_id = NULL)
 {
     $this->buildStatusImageMap();
     // 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(url('admin/config/development/testing', array('absolute' => TRUE)));
     }
     // Load all classes and include CSS.
     $form['#attached']['css'][] = drupal_get_path('module', 'simpletest') . '/css/simpletest.module.css';
     // Keep track of which test cases passed or failed.
     $filter = array('pass' => array(), 'fail' => array());
     // Summary result widget.
     $form['result'] = array('#type' => 'fieldset', '#title' => $this->t('Results'));
     $form['result']['summary'] = $summary = array('#theme' => 'simpletest_result_summary', '#pass' => 0, '#fail' => 0, '#exception' => 0, '#debug' => 0);
     simpletest_classloader_register();
     // Cycle through each test group.
     $header = array($this->t('Message'), $this->t('Group'), $this->t('Filename'), $this->t('Line'), $this->t('Function'), array('colspan' => 2, 'data' => $this->t('Status')));
     $form['result']['results'] = array();
     foreach ($results as $group => $assertions) {
         // Create group details with summary information.
         $info = TestDiscovery::getTestInfo(new \ReflectionClass($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();
             // Assertion messages are in code, so we assume they are safe.
             $row[] = SafeMarkup::set($assertion->message);
             $row[] = $assertion->message_group;
             $row[] = drupal_basename($assertion->file);
             $row[] = $assertion->line;
             $row[] = $assertion->function;
             $row[] = $this->statusImageMap[$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;
     // Actions.
     $form['#action'] = url('admin/config/development/testing/results/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'), '#href' => 'admin/config/development/testing');
     if (is_numeric($test_id)) {
         simpletest_clean_results_table($test_id);
     }
     return $form;
 }
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // 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_filter($form_state->getValue('tests'));
     if (!empty($tests_list)) {
         $test_id = simpletest_run_tests($tests_list, 'drupal');
         $form_state->setRedirect('simpletest.result_form', array('test_id' => $test_id));
     }
 }