You are here

function DrupalUnitTests::DrupalUnitTests in SimpleTest 6

Same name and namespace in other branches
  1. 5 drupal_unit_tests.php \DrupalUnitTests::DrupalUnitTests()

Constructor

Parameters

array $class_list list containing the classes of tests to be processed: default: NULL - run all tests

File

./drupal_unit_tests.php, line 32

Class

DrupalUnitTests

Code

function DrupalUnitTests($class_list = NULL) {
  static $classes;
  $this
    ->DrupalTestSuite('Drupal Unit Tests');

  /* Tricky part to avoid double inclusion */
  if (!$classes) {
    $files = array();
    foreach (module_list() as $module) {
      $module_path = drupal_get_path('module', $module);
      if (file_exists($module_path . '/tests/')) {
        $dir = $module_path . '/tests';
        $tests = file_scan_directory($dir, '\\.test$');
        $files = array_merge($files, $tests);
      }
    }
    $files = array_keys($files);
    $existing_classes = get_declared_classes();
    foreach ($files as $file) {
      if (!preg_match('/class\\s+.*?\\s+extends\\s+DrupalWebTestCase/', file_get_contents($file))) {

        // Ignore tests using the new format.
        include_once $file;
      }
    }
    $classes = array_diff(get_declared_classes(), $existing_classes);
  }
  if (!is_null($class_list)) {
    $classes = $class_list;
  }
  if (count($classes) == 0) {
    $this
      ->addTestCase(new BadGroupTest($test_file, 'No new test cases'));
    return;
  }
  $groups = array();
  foreach ($classes as $class) {
    if (!is_subclass_of($class, 'DrupalTestCase')) {
      continue;
    }
    $this
      ->_addClassToGroups($groups, $class);
  }
  foreach ($groups as $group_name => $group) {
    $group_test =& new DrupalTestSuite($group_name);
    foreach ($group as $key => $v) {
      $group_test
        ->addTestCase($group[$key]);
    }
    $this
      ->addTestCase($group_test);
  }
}