Commit ca709290 authored by Dries's avatar Dries

- Patch #343502 by Dave Reid, sun | dbabbage, Dries, boombatower: allow tests...

- 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.
parent f06ed4f6
......@@ -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) {
......
......@@ -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.'));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment