00001 <?php
00002
00003
00007 class DrupalTestSuite extends TestSuite {
00008 var $_cleanupModules = array();
00009
00010 function DrupalTestSuite($label) {
00011 $this->TestSuite($label);
00012 }
00013
00018 function getTestInstances() {
00019 for ($i = 0, $count = count($this->_test_cases); $i < $count; $i++) {
00020 if (is_string($this->_test_cases[$i])) {
00021 $class = $this->_test_cases[$i];
00022 $this->_test_cases[$i] = &new $class();
00023 }
00024 }
00025 return $this->_test_cases;
00026 }
00027 }
00028
00029 class DrupalTests extends DrupalTestSuite {
00037 function DrupalTests($class_list = NULL) {
00038 static $classes;
00039 $this->DrupalTestSuite('Drupal Unit Tests');
00040
00041
00042 if (!$classes) {
00043
00044 $files = $this->getFiles();
00045
00046 $existing_classes = get_declared_classes();
00047 foreach ($files as $file) {
00048 include_once($file);
00049 }
00050 $classes = array_diff(get_declared_classes(), $existing_classes);
00051 }
00052 if (!is_null($class_list)) {
00053 $classes = $class_list;
00054 }
00055 if (count($classes) == 0) {
00056 drupal_set_message('No test cases found.', 'error');
00057 return;
00058 }
00059 $groups = array();
00060 foreach ($classes as $class) {
00061 if ($this->classIsTest($class)) {
00062 $this->_addClassToGroups($groups, $class);
00063 }
00064 }
00065 foreach ($groups as $group_name => $group) {
00066 $group_test = &new DrupalTestSuite($group_name);
00067 foreach ($group as $key => $v) {
00068 $group_test->addTestCase($group[$key]);
00069 }
00070 $this->addTestCase($group_test);
00071 }
00072 }
00073
00082 function _addClassToGroups(&$groups, $class) {
00083 $test = &new $class();
00084 if (method_exists($test, 'getInfo')) {
00085 $info = $test->getInfo();
00086 $groups[$info['group']][] = $test;
00087 }
00088 }
00089
00100 function run(&$reporter) {
00101 @set_time_limit(0);
00102 ignore_user_abort(TRUE);
00103
00104 $this->cleanupBeforeRun();
00105 $result = parent::run($reporter);
00106 return $result;
00107 }
00108
00115 function getFiles() {
00116 $files = array();
00117 foreach (array_keys(module_rebuild_cache()) as $module) {
00118 $module_path = drupal_get_path('module', $module);
00119 $test = $module_path . "/$module.test";
00120 if (file_exists($test)) {
00121 $files[] = $test;
00122 }
00123 }
00124 foreach (file_scan_directory('includes', '\.test$') as $file) {
00125 $files[] = $file->filename;
00126 }
00127 return $files;
00128 }
00129
00136 function classIsTest($class) {
00137 return is_subclass_of($class, 'DrupalWebTestCase');
00138 }
00139
00143 function cleanupBeforeRun() {
00144 cache_clear_all();
00145
00146 if (!variable_get('simpletest_devel', FALSE)) {
00147 $GLOBALS['devel_shutdown'] = FALSE;
00148 }
00149 }
00150 }