diff --git a/modules/simpletest/lib/Drupal/simpletest/Tests/PSR0WebTest.php b/modules/simpletest/lib/Drupal/simpletest/Tests/PSR0WebTest.php index 0292956..6a7254d 100644 --- a/modules/simpletest/lib/Drupal/simpletest/Tests/PSR0WebTest.php +++ b/modules/simpletest/lib/Drupal/simpletest/Tests/PSR0WebTest.php @@ -6,13 +6,16 @@ public static function getInfo() { return array( - 'name' => 'PSR0 web test', - 'description' => 'We want to assert that this PSR-0 test case is being discovered.', + 'name' => 'PSR-0 web test', + 'description' => 'Tests the discovery of PSR-0 test classes.', 'group' => 'SimpleTest', ); } - function testArithmetics() { - $this->assert(1 + 1 == 2, '1 + 1 == 2'); + /** + * Asserts the test is found by autolaoders. + */ + function testLoaded() { + $this->pass('PSR-0 test loaded and running.', 'SimpleTest'); } } diff --git a/modules/simpletest/simpletest.module b/modules/simpletest/simpletest.module index 3103af0..e93dd64 100644 --- a/modules/simpletest/simpletest.module +++ b/modules/simpletest/simpletest.module @@ -293,6 +293,9 @@ * PSR-0 classes are found by searching the designated directory for each module * for files matching the PSR-0 standard. * + * @param $reset + * Reset the simpletest classes static cache. + * * @return * An array of tests keyed with the groups specified in each of the tests * getInfo() method and then keyed by the test class. An example of the array @@ -309,10 +312,10 @@ * @endcode * @see simpletest_registry_files_alter() */ -function simpletest_test_get_all() { +function simpletest_test_get_all($reset = FALSE) { $groups = &drupal_static(__FUNCTION__); - if (!$groups) { + if (!$groups || $reset) { // Register a simple class loader for PSR-0 test classes. simpletest_classloader_register(); @@ -388,7 +391,7 @@ return $groups; } -/* +/** * Register a simple class loader that can find D8-style PSR-0 test classes. * * Other PSR-0 class loading can happen in contrib, but those contrib class @@ -414,7 +417,7 @@ * Autoload callback to find PSR-0 test classes. * * This will only work on classes where the namespace is of the pattern - * "Drupal\$extension\Tests\.." + * "Drupal\$extension\Tests\.." */ function _simpletest_autoload_psr0($class) { @@ -442,9 +445,9 @@ if (isset($extensions[$extension])) { // Split the class into namespace and classname. - $nspos = strrpos($class, '\\'); - $namespace = substr($class, 0, $nspos); - $classname = substr($class, $nspos + 1); + $namespace_pos = strrpos($class, '\\'); + $namespace = substr($class, 0, $namespace_pos); + $classname = substr($class, $namespace_pos + 1); // Build the filepath where we expect the class to be defined. $path = dirname($extensions[$extension]) . '/lib/' . diff --git a/modules/simpletest/simpletest.test b/modules/simpletest/simpletest.test index dde162e..cd6d18e 100644 --- a/modules/simpletest/simpletest.test +++ b/modules/simpletest/simpletest.test @@ -657,22 +657,11 @@ } /** - * Verifies that tests in other installation profiles are not found. - * - * @see SimpleTestInstallationProfileModuleTestsTestCase + * Verifies that tests classes are discovered and can be autoloaded. */ class SimpleTestDiscoveryTestCase extends DrupalWebTestCase { /** * Use the Testing profile. - * - * The Testing profile contains drupal_system_listing_compatible_test.test, - * which attempts to: - * - run tests using the Minimal profile (which does not contain the - * drupal_system_listing_compatible_test.module) - * - but still install the drupal_system_listing_compatible_test.module - * contained in the Testing profile. - * - * @see DrupalSystemListingCompatibleTestCase */ protected $profile = 'testing'; @@ -699,13 +688,13 @@ // Don't expect PSR-0 tests to be discovered on older PHP versions. return; } - // TODO: What if we have cached values? Do we need to force a cache refresh? - $classes_all = simpletest_test_get_all(); + // Force the refresh of the static cache. + $classes_all = simpletest_test_get_all(TRUE); foreach (array( 'Drupal\\simpletest\\Tests\\PSR0WebTest', 'Drupal\\psr_0_test\\Tests\\ExampleTest', ) as $class) { - $this->assert(!empty($classes_all['SimpleTest'][$class]), t('Class @class must be discovered by simpletest_test_get_all().', array('@class' => $class))); + $this->assertTrue(!empty($classes_all['SimpleTest'][$class]), format_string('Class @class has been discovered by simpletest_test_get_all().', array('@class' => $class))); } } @@ -714,22 +703,15 @@ */ function testDiscovery() { $this->drupalGet('admin/config/development/testing'); - // Tests within enabled modules. - // (without these, this test wouldn't happen in the first place, so this is - // a bit pointless. We still run it for proof-of-concept.) - // This one is defined in system module. - $this->assertText('Drupal error handlers'); - // This one is defined in simpletest module. - $this->assertText('Discovery of test classes'); - // Tests within disabled modules. + if (version_compare(PHP_VERSION, '5.3') < 0) { // Don't expect PSR-0 tests to be discovered on older PHP versions. return; } // This one is provided by simpletest itself via PSR-0. - $this->assertText('PSR0 web test'); - $this->assertText('PSR0 example test: PSR-0 in disabled modules.'); - $this->assertText('PSR0 example test: PSR-0 in nested subfolders.'); + $this->assertText('PSR-0 web test'); + $this->assertText('PSR-0 example test: disabled modules.'); + $this->assertText('PSR-0 example test: nested subfolders.'); // Test each test individually. foreach (array( @@ -739,8 +721,8 @@ $this->drupalGet('admin/config/development/testing'); $edit = array($class => TRUE); $this->drupalPost(NULL, $edit, t('Run tests')); - $this->assertText('The test run finished', t('Test @class must finish.', array('@class' => $class))); - $this->assertText('1 pass, 0 fails, and 0 exceptions', t('Test @class must pass.', array('@class' => $class))); + $this->assertText('The test run finished', format_string('Test @class has finished.', array('@class' => $class))); + $this->assertText('1 pass, 0 fails, and 0 exceptions', format_string('Test @class has passed.', array('@class' => $class))); } } } diff --git a/modules/simpletest/tests/psr_0_test/lib/Drupal/psr_0_test/Tests/ExampleTest.php b/modules/simpletest/tests/psr_0_test/lib/Drupal/psr_0_test/Tests/ExampleTest.php index 3098c92..7c35f87 100644 --- a/modules/simpletest/tests/psr_0_test/lib/Drupal/psr_0_test/Tests/ExampleTest.php +++ b/modules/simpletest/tests/psr_0_test/lib/Drupal/psr_0_test/Tests/ExampleTest.php @@ -6,13 +6,16 @@ public static function getInfo() { return array( - 'name' => 'PSR0 example test: PSR-0 in disabled modules.', - 'description' => 'We want to assert that this test case is being discovered.', + 'name' => 'PSR-0 example test: disabled modules.', + 'description' => 'Tests the discovery of PSR-0 test classes for disabled modules.', 'group' => 'SimpleTest', ); } - function testArithmetics() { - $this->assert(1 + 1 == 2, '1 + 1 == 2'); + /** + * Asserts the test is found by autolaoders. + */ + function testLoaded() { + $this->pass('PSR-0 test loaded and running.', 'SimpleTest'); } } diff --git a/modules/simpletest/tests/psr_0_test/lib/Drupal/psr_0_test/Tests/Nested/NestedExampleTest.php b/modules/simpletest/tests/psr_0_test/lib/Drupal/psr_0_test/Tests/Nested/NestedExampleTest.php index 324ed43..383e1b3 100644 --- a/modules/simpletest/tests/psr_0_test/lib/Drupal/psr_0_test/Tests/Nested/NestedExampleTest.php +++ b/modules/simpletest/tests/psr_0_test/lib/Drupal/psr_0_test/Tests/Nested/NestedExampleTest.php @@ -6,13 +6,16 @@ public static function getInfo() { return array( - 'name' => 'PSR0 example test: PSR-0 in nested subfolders.', - 'description' => 'We want to assert that this PSR-0 test case is being discovered.', + 'name' => 'PSR-0 example test: nested subfolders.', + 'description' => 'Tests the discovery of PSR-0 test classes in nested subfolders.', 'group' => 'SimpleTest', ); } - function testArithmetics() { - $this->assert(1 + 1 == 2, '1 + 1 == 2'); + /** + * Asserts the test is found by autolaoders. + */ + function testLoaded() { + $this->pass('PSR-0 test loaded and running.', 'SimpleTest'); } } diff --git a/modules/simpletest/tests/psr_0_test/psr_0_test.info b/modules/simpletest/tests/psr_0_test/psr_0_test.info index 48ca8d8..a640f8c 100644 --- a/modules/simpletest/tests/psr_0_test/psr_0_test.info +++ b/modules/simpletest/tests/psr_0_test/psr_0_test.info @@ -1,6 +1,6 @@ name = PSR-0 Test cases description = Test classes to be discovered by simpletest. -core = 7.x - -hidden = TRUE package = Testing +version = VERSION +core = 7.x +hidden = TRUE