function simpletest_test_get_all

7.x simpletest.module simpletest_test_get_all()

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

The list of test classes is loaded from the registry where it looks for files ending in ".test". Once loaded the test list is cached and stored in a static variable. In order to list tests provided by disabled modules hook_registry_files_alter() is used to forcefully add them to the registry.

PSR-0 classes are found by searching the designated directory for each module for files matching the PSR-0 standard.

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['Blog'] => array(
      'BlogTestCase' => array(
        'name' => 'Blog functionality',
        'description' => 'Create, view, edit, delete, ...',
        'group' => 'Blog',
      ),
    );
  

See also

simpletest_registry_files_alter()

2 calls to simpletest_test_get_all()
SimpleTestDiscoveryTestCase::testDiscoveryFunctions in drupal-7.x/modules/simpletest/simpletest.test
Test discovery of PSR-0 test classes.
simpletest_test_form in drupal-7.x/modules/simpletest/simpletest.pages.inc
List tests arranged in groups that can be selected and run.

File

drupal-7.x/modules/simpletest/simpletest.module, line 312
Provides testing functionality.

Code

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

  if (!$groups) {
    // Register a simple class loader for PSR-0 test classes.
    simpletest_classloader_register();

    // Load test information from cache if available, otherwise retrieve the
    // information from each tests getInfo() method.
    if ($cache = cache_get('simpletest', 'cache')) {
      $groups = $cache->data;
    }
    else {
      // Select all clases in files ending with .test.
      $classes = db_query("SELECT name FROM {registry} WHERE type = :type AND filename LIKE :name", array(':type' => 'class', ':name' => '%.test'))->fetchCol();

      // Also discover PSR-0 test classes, if the PHP version allows it.
      if (version_compare(PHP_VERSION, '5.3') > 0) {

        // Select all PSR-0 classes in the Tests namespace of all modules.
        $system_list = db_query("SELECT name, filename FROM {system}")->fetchAllKeyed();

        foreach ($system_list as $name => $filename) {
          // Build directory in which the test files would reside.
          $tests_dir = DRUPAL_ROOT . '/' . dirname($filename) . '/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($filename) . '/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 (!drupal_get_filename('module', $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;
}