Skip to content
Snippets Groups Projects
Select Git revision
  • d6693eb36db42c7977dd87c04fa39426e8af1cd1
  • 11.x default protected
  • 11.2.x protected
  • 10.5.x protected
  • 10.6.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 8.9.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
  • 11.1.6 protected
  • 10.3.14 protected
  • 10.4.5 protected
  • 11.0.13 protected
41 results

SimpletestTestForm.php

Blame
  • webchick's avatar
    Issue #2072323 by tim.plunkett: Modernize simpletest.module forms.
    Angie Byron authored
    d6693eb3
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    SimpletestTestForm.php 3.61 KiB
    <?php
    
    /**
     * @file
     * Contains \Drupal\simpletest\Form\SimpletestTestForm.
     */
    
    namespace Drupal\simpletest\Form;
    
    use Drupal\Core\Form\FormBase;
    
    /**
     * List tests arranged in groups that can be selected and run.
     */
    class SimpletestTestForm extends FormBase {
    
      /**
       * {@inheritdoc}
       */
      public function getFormID() {
        return 'simpletest_test_form';
      }
    
      /**
       * {@inheritdoc}
       */
      public function buildForm(array $form, array &$form_state) {
        // JavaScript-only table filters.
        $form['filters'] = array(
          '#type' => 'container',
          '#attributes' => array(
            'class' => array('table-filter', 'js-show'),
          ),
        );
        $form['filters']['text'] = array(
          '#type' => 'search',
          '#title' => $this->t('Search'),
          '#size' => 30,
          '#placeholder' => $this->t('Enter test name…'),
          '#attributes' => array(
            'class' => array('table-filter-text'),
            'data-table' => '#simpletest-test-form',
            'autocomplete' => 'off',
            'title' => $this->t('Enter at least 3 characters of the test name or description to filter by.'),
          ),
        );
    
        $form['tests'] = array(
          '#type' => 'details',
          '#title' => $this->t('Tests'),
          '#description' => $this->t('Select the test(s) or test group(s) you would like to run, and click <em>Run tests</em>.'),
        );
    
        $form['tests']['table'] = array(
          '#theme' => 'simpletest_test_table',
        );
    
        // Generate the list of tests arranged by group.
        $groups = simpletest_test_get_all();
        $groups['PHPUnit'] = simpletest_phpunit_get_available_tests();
        $form_state['storage']['PHPUnit'] = $groups['PHPUnit'];
    
        foreach ($groups as $group => $tests) {
          $form['tests']['table'][$group] = array(
            '#collapsed' => TRUE,
          );
    
          foreach ($tests as $class => $info) {
            $form['tests']['table'][$group][$class] = array(
              '#type' => 'checkbox',
              '#title' => $info['name'],
              '#description' => $info['description'],
            );
          }
        }
    
        // Action buttons.
        $form['tests']['op'] = array(
          '#type' => 'submit',
          '#value' => $this->t('Run tests'),
        );
        $form['clean'] = array(
          '#type' => 'fieldset',
          '#title' => $this->t('Clean test environment'),
          '#description' => $this->t('Remove tables with the prefix "simpletest" and temporary directories that are left over from tests that crashed. This is intended for developers when creating tests.'),
        );
        $form['clean']['op'] = array(
          '#type' => 'submit',
          '#value' => $this->t('Clean environment'),
          '#submit' => array('simpletest_clean_environment'),
        );
    
        return $form;
      }
    
      /**
       * {@inheritdoc}
       */
      public function validateForm(array &$form, array &$form_state) {
      }
    
      /**
       * {@inheritdoc}
       */
      public function submitForm(array &$form, array &$form_state) {
        // Get list of tests.
        $tests_list = array();
        simpletest_classloader_register();
    
        $phpunit_all = array_keys($form_state['storage']['PHPUnit']);
    
        foreach ($form_state['values'] as $class_name => $value) {
          // Since class_exists() will likely trigger an autoload lookup,
          // we do the fast check first.
          if ($value === 1 && class_exists($class_name)) {
            $test_type = in_array($class_name, $phpunit_all) ? 'UnitTest' : 'WebTest';
            $tests_list[$test_type][] = $class_name;
          }
        }
        if (count($tests_list) > 0 ) {
          $test_id = simpletest_run_tests($tests_list, 'drupal');
          $form_state['redirect'] = 'admin/config/development/testing/results/' . $test_id;
        }
        else {
          drupal_set_message($this->t('No test(s) selected.'), 'error');
        }
      }
    
    }