summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/simpletest/simpletest.module23
-rw-r--r--modules/simpletest/simpletest.test22
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.'));
+ }
+}
+