diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-10-08 15:18:27 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-10-08 15:18:27 +0000 |
commit | ca709290cc6e8345a358f44636928fc4db86db6b (patch) | |
tree | 85d0516706b65a0f195f81e1477979ff7b28a633 | |
parent | f06ed4f6707b40b2eaa16523a8f777418c1db547 (diff) | |
download | brdo-ca709290cc6e8345a358f44636928fc4db86db6b.tar.gz brdo-ca709290cc6e8345a358f44636928fc4db86db6b.tar.bz2 |
- Patch #343502 by Dave Reid, sun | dbabbage, Dries, boombatower: allow tests to require and test existence of modules. Required to make testing contributed modules possible.
-rw-r--r-- | modules/simpletest/simpletest.module | 23 | ||||
-rw-r--r-- | modules/simpletest/simpletest.test | 22 |
2 files changed, 34 insertions, 11 deletions
diff --git a/modules/simpletest/simpletest.module b/modules/simpletest/simpletest.module index 84ce85e71..234ecb89d 100644 --- a/modules/simpletest/simpletest.module +++ b/modules/simpletest/simpletest.module @@ -334,29 +334,30 @@ function simpletest_test_get_all() { } else { // Select all clases in files ending with .test. - $classes = db_select('registry') - ->fields('registry', array('name')) - ->condition('type', 'class') - ->condition('filename', '%.test', 'LIKE') - ->execute(); - - $groups = array(); + $classes = db_query("SELECT name FROM {registry} WHERE type = :type AND filename LIKE :name", array(':type' => 'class', ':name' => '%.test')); // 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) { $class = $class->name; + // Test classes need to implement getInfo() to be valid. if (class_exists($class) && method_exists($class, 'getInfo')) { - // Valid test class, retrieve test information. $info = call_user_func(array($class, 'getInfo')); - // Initialize test groups. - if (!isset($groups[$info['group']])) { - $groups[$info['group']] = array(); + // 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) { diff --git a/modules/simpletest/simpletest.test b/modules/simpletest/simpletest.test index a4ee6741e..31046392c 100644 --- a/modules/simpletest/simpletest.test +++ b/modules/simpletest/simpletest.test @@ -382,3 +382,25 @@ class SimpleTestMailCaptureTestCase extends DrupalWebTestCase { $this->assertEqual(count($captured_emails), 2, t('All e-mails with the same id are returned when filtering by id.'), t('E-mail')); } } + +/** + * Test required modules for tests. + */ +class SimpleTestMissingDependentModuleUnitTest extends DrupalUnitTestCase { + public static function getInfo() { + return array( + 'title' => 'Testing dependent module test', + 'description' => 'This test should not load since it requires a module that is not found.', + 'group' => 'SimpleTest', + 'dependencies' => array('simpletest_missing_module'), + ); + } + + /** + * Ensure that this test will not be loaded despite its dependency. + */ + function testFail() { + $this->fail(t('Running test with missing required module.')); + } +} + |