function simpletest_test_get_all

Get a list of all of the tests provided by the system.

The list of test classes is loaded by searching the designated directory for each module for files matching the PSR-0 standard. Once loaded the test list is cached and stored in a static variable.

Return value

An array of tests keyed with the groups specified in each of the tests getInfo() method and then keyed by the test class. An example of the array structure is provided below.


    $groups['Block'] => array(
      'BlockTestCase' => array(
        'name' => 'Block functionality',
        'description' => 'Add, edit and delete custom block...',
        'group' => 'Block',
      ),
    );
  
1 call to simpletest_test_get_all()
SimpletestTestForm::buildForm in drupal/core/modules/simpletest/lib/Drupal/simpletest/Form/SimpletestTestForm.php
Form constructor.

File

drupal/core/modules/simpletest/simpletest.module, line 433
Provides testing functionality.

Code

function simpletest_test_get_all() {
  $groups =& drupal_static(__FUNCTION__);
  if (!$groups) {

    // Make sure that namespaces for disabled modules are registered so that the
    // checks below will find them.
    simpletest_classloader_register();

    // Load test information from cache if available, otherwise retrieve the
    // information from each tests getInfo() method.
    if ($cache = cache()
      ->get('simpletest')) {
      $groups = $cache->data;
    }
    else {

      // Select all PSR-0 classes in the Tests namespace of all modules.
      $classes = array();
      $module_data = system_rebuild_module_data();
      $all_data = $module_data + system_rebuild_theme_data();
      $all_data += drupal_system_listing('/\\.profile$/', 'profiles', 'name');
      foreach ($all_data as $name => $data) {

        // Build directory in which the test files would reside.
        $tests_dir = DRUPAL_ROOT . '/' . dirname($data->uri) . '/lib/Drupal/' . $name . '/Tests';

        // Scan it for test files if it exists.
        if (is_dir($tests_dir)) {
          $files = file_scan_directory($tests_dir, '/.*\\.php/');
          if (!empty($files)) {
            $basedir = DRUPAL_ROOT . '/' . dirname($data->uri) . '/lib/';
            foreach ($files as $file) {

              // Convert the file name into the namespaced class name.
              $replacements = array(
                '/' => '\\',
                $basedir => '',
                '.php' => '',
              );
              $classes[] = strtr($file->uri, $replacements);
            }
          }
        }
      }

      // Check that each class has a getInfo() method and store the information
      // in an array keyed with the group specified in the test information.
      $groups = array();
      foreach ($classes as $class) {

        // Test classes need to implement getInfo() to be valid.
        if (class_exists($class) && method_exists($class, 'getInfo')) {
          $info = call_user_func(array(
            $class,
            'getInfo',
          ));

          // If this test class requires a non-existing module, skip it.
          if (!empty($info['dependencies'])) {
            foreach ($info['dependencies'] as $module) {
              if (!isset($module_data[$module])) {
                continue 2;
              }
            }
          }
          $groups[$info['group']][$class] = $info;
        }
      }

      // Sort the groups and tests within the groups by name.
      uksort($groups, 'strnatcasecmp');
      foreach ($groups as $group => &$tests) {
        uksort($tests, 'strnatcasecmp');
      }

      // Allow modules extending core tests to disable originals.
      drupal_alter('simpletest', $groups);
      cache()
        ->set('simpletest', $groups);
    }
  }
  return $groups;
}