diff --git a/core/modules/simpletest/src/TestDiscovery.php b/core/modules/simpletest/src/TestDiscovery.php index a6c0e62..f3a0449 100644 --- a/core/modules/simpletest/src/TestDiscovery.php +++ b/core/modules/simpletest/src/TestDiscovery.php @@ -79,8 +79,9 @@ public function registerTestNamespaces() { $existing = $this->classLoader->getPrefixesPsr4(); - // Add PHPUnit test namespace of Drupal core. + // Add PHPUnit test namespaces of Drupal core. $this->testNamespaces['Drupal\\Tests\\'] = [DRUPAL_ROOT . '/core/tests/Drupal/Tests']; + $this->testNamespaces['Drupal\\FunctionalTests\\'] = [DRUPAL_ROOT . '/core/tests/Drupal/FunctionalTests']; $this->availableExtensions = array(); foreach ($this->getExtensions() as $name => $extension) { @@ -95,8 +96,9 @@ public function registerTestNamespaces() { // Add Simpletest test namespace. $this->testNamespaces["Drupal\\$name\\Tests\\"][] = "$base_path/src/Tests"; - // Add PHPUnit test namespace. - $this->testNamespaces["Drupal\\Tests\\$name\\"][] = "$base_path/tests/src"; + // Add PHPUnit test namespaces. + $this->testNamespaces["Drupal\\Tests\\$name\\Unit\\"][] = "$base_path/tests/src/Unit"; + $this->testNamespaces["Drupal\\Tests\\$name\\Functional\\"][] = "$base_path/tests/src/Functional"; } foreach ($this->testNamespaces as $prefix => $paths) { @@ -322,7 +324,7 @@ public static function getTestInfo($classname, $doc_comment = NULL) { throw new MissingGroupException(sprintf('Missing @group annotation in %s', $classname)); } // Force all PHPUnit tests into the same group. - if (strpos($classname, 'Drupal\\Tests\\') === 0) { + if (static::isUnitTest($classname)) { $info['group'] = 'PHPUnit'; } else { @@ -408,6 +410,31 @@ public static function parseTestClassAnnotations(\ReflectionClass $class) { } /** + * Determines if the provided classname is a unit test. + * + * @param $classname + * The test classname. + * + * @return bool + * TRUE if the class is a unit test. FALSE if not. + */ + public static function isUnitTest($classname) { + if (strpos($classname, 'Drupal\\Tests\\') === 0) { + $namespace = explode('\\', $classname); + $first_letter = Unicode::substr($namespace[2], 0, 1); + if (Unicode::strtoupper($first_letter) === $first_letter) { + // A core unit test. + return TRUE; + } + else if ($namespace[3] == 'Unit') { + // A module unit test + return TRUE; + } + } + return FALSE; + } + + /** * Returns all available extensions. * * @return \Drupal\Core\Extension\Extension[] diff --git a/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php b/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php index e384a3c..c86933d 100644 --- a/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php +++ b/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php @@ -138,11 +138,19 @@ public function testTestingThroughUI() { $this->drupalGet('admin/config/development/testing'); $edit = array( - // A PHPUnit test. + // A PHPUnit unit test. 'tests[Drupal\Tests\action\Unit\Menu\ActionLocalTasksTest]' => TRUE, ); $this->drupalPostForm(NULL, $edit, t('Run tests')); $this->assertText('0 fails, 0 exceptions'); + + $this->drupalGet('admin/config/development/testing'); + $edit = array( + // A PHPUnit functional test. + 'tests[Drupal\Tests\simpletest\Functional\BrowserTestBaseTest]' => TRUE, + ); + $this->drupalPostForm(NULL, $edit, t('Run tests')); + $this->assertText('0 fails, 0 exceptions'); } } diff --git a/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php b/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php index 03a87b7..4df976f 100644 --- a/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php +++ b/core/modules/simpletest/tests/src/Unit/TestInfoParsingTest.php @@ -20,6 +20,7 @@ public function testTestInfoParser($expected, $classname, $doc_comment = NULL) { } public function infoParserProvider() { + // A module provided unit test. $tests[] = [ // Expected result. [ @@ -31,6 +32,32 @@ public function infoParserProvider() { 'Drupal\Tests\simpletest\Unit\TestInfoParsingTest', ]; + // A core unit test. + $tests[] = [ + // Expected result. + [ + 'name' => 'Drupal\Tests\Core\DrupalTest', + 'group' => 'PHPUnit', + 'description' => 'Tests \Drupal.', + ], + // Classname. + 'Drupal\Tests\Core\DrupalTest', + ]; + + // Functional PHPUnit test. + $tests[] = [ + // Expected result. + [ + 'name' => 'Drupal\Tests\simpletest\Functional\BrowserTestBaseTest', + 'group' => 'simpletest', + 'description' => 'Tests BrowserTestBase functionality.', + ], + // Classname. + 'Drupal\Tests\simpletest\Functional\BrowserTestBaseTest', + ]; + + // Simpletest classes can not be autoloaded in a PHPUnit test, therefore + // provide a docblock. $tests[] = [ // Expected result. [ diff --git a/core/phpunit.xml.dist b/core/phpunit.xml.dist index 78f2f0e..2143771 100644 --- a/core/phpunit.xml.dist +++ b/core/phpunit.xml.dist @@ -10,10 +10,10 @@ - ./tests - ./modules/*/tests - ../modules - ../sites/*/modules + ./tests/Drupal/Tests + ./modules/*/tests/src/Unit + ../modules/*/tests/src/Unit + ../sites/*/modules/*/tests/src/Unit ./vendor @@ -23,6 +23,7 @@ ./modules/*/tests/src/Functional + ./tests/Drupal/FunctionalTests ./vendor