You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* a static variable. In order to list tests provided by disabled modules
290
291
* hook_registry_files_alter() is used to forcefully add them to the registry.
291
292
*
293
+
* PSR-0 classes are found by searching the designated directory for each module
294
+
* for files matching the PSR-0 standard.
295
+
*
292
296
* @return
293
297
* An array of tests keyed with the groups specified in each of the tests
294
298
* getInfo() method and then keyed by the test class. An example of the array
@@ -309,6 +313,9 @@ function simpletest_test_get_all() {
309
313
$groups = &drupal_static(__FUNCTION__);
310
314
311
315
if (!$groups) {
316
+
// Register a simple class loader for PSR-0 test classes.
317
+
simpletest_classloader_register();
318
+
312
319
// Load test information from cache if available, otherwise retrieve the
313
320
// information from each tests getInfo() method.
314
321
if ($cache = cache_get('simpletest', 'cache')) {
@@ -318,6 +325,34 @@ function simpletest_test_get_all() {
318
325
// Select all clases in files ending with .test.
319
326
$classes = db_query("SELECT name FROM {registry} WHERE type = :type AND filename LIKE :name", array(':type' => 'class', ':name' => '%.test'))->fetchCol();
320
327
328
+
// Also discover PSR-0 test classes, if the PHP version allows it.
329
+
if (version_compare(PHP_VERSION, '5.3') > 0) {
330
+
331
+
// Select all PSR-0 classes in the Tests namespace of all modules.
332
+
$system_list = db_query("SELECT name, filename FROM {system}")->fetchAllKeyed();
333
+
334
+
foreach ($system_list as $name => $filename) {
335
+
// Build directory in which the test files would reside.
class SimpleTestDiscoveryTestCase extends DrupalWebTestCase {
665
+
/**
666
+
* Use the Testing profile.
667
+
*
668
+
* The Testing profile contains drupal_system_listing_compatible_test.test,
669
+
* which attempts to:
670
+
* - run tests using the Minimal profile (which does not contain the
671
+
* drupal_system_listing_compatible_test.module)
672
+
* - but still install the drupal_system_listing_compatible_test.module
673
+
* contained in the Testing profile.
674
+
*
675
+
* @see DrupalSystemListingCompatibleTestCase
676
+
*/
677
+
protected $profile = 'testing';
678
+
679
+
public static function getInfo() {
680
+
return array(
681
+
'name' => 'Discovery of test classes',
682
+
'description' => 'Verifies that tests classes are discovered and can be autoloaded (class_exists).',
683
+
'group' => 'SimpleTest',
684
+
);
685
+
}
686
+
687
+
function setUp() {
688
+
parent::setUp(array('simpletest'));
689
+
690
+
$this->admin_user = $this->drupalCreateUser(array('administer unit tests'));
691
+
$this->drupalLogin($this->admin_user);
692
+
}
693
+
694
+
/**
695
+
* Test discovery of PSR-0 test classes.
696
+
*/
697
+
function testDiscoveryFunctions() {
698
+
if (version_compare(PHP_VERSION, '5.3') < 0) {
699
+
// Don't expect PSR-0 tests to be discovered on older PHP versions.
700
+
return;
701
+
}
702
+
// TODO: What if we have cached values? Do we need to force a cache refresh?
703
+
$classes_all = simpletest_test_get_all();
704
+
foreach (array(
705
+
'Drupal\\simpletest\\Tests\\PSR0WebTest',
706
+
'Drupal\\psr_0_test\\Tests\\ExampleTest',
707
+
) as $class) {
708
+
$this->assert(!empty($classes_all['SimpleTest'][$class]), t('Class @class must be discovered by simpletest_test_get_all().', array('@class' => $class)));
0 commit comments