Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\TestSuites;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\simpletest\TestDiscovery;
|
Chris@14
|
6 use PHPUnit\Framework\TestSuite;
|
Chris@0
|
7
|
Chris@0
|
8 /**
|
Chris@0
|
9 * Base class for Drupal test suites.
|
Chris@0
|
10 */
|
Chris@14
|
11 abstract class TestSuiteBase extends TestSuite {
|
Chris@0
|
12
|
Chris@0
|
13 /**
|
Chris@0
|
14 * Finds extensions in a Drupal installation.
|
Chris@0
|
15 *
|
Chris@0
|
16 * An extension is defined as a directory with an *.info.yml file in it.
|
Chris@0
|
17 *
|
Chris@0
|
18 * @param string $root
|
Chris@0
|
19 * Path to the root of the Drupal installation.
|
Chris@0
|
20 *
|
Chris@0
|
21 * @return string[]
|
Chris@0
|
22 * Associative array of extension paths, with extension name as keys.
|
Chris@0
|
23 */
|
Chris@0
|
24 protected function findExtensionDirectories($root) {
|
Chris@0
|
25 $extension_roots = \drupal_phpunit_contrib_extension_directory_roots($root);
|
Chris@0
|
26
|
Chris@0
|
27 $extension_directories = array_map('drupal_phpunit_find_extension_directories', $extension_roots);
|
Chris@0
|
28 return array_reduce($extension_directories, 'array_merge', []);
|
Chris@0
|
29 }
|
Chris@0
|
30
|
Chris@0
|
31 /**
|
Chris@0
|
32 * Find and add tests to the suite for core and any extensions.
|
Chris@0
|
33 *
|
Chris@0
|
34 * @param string $root
|
Chris@0
|
35 * Path to the root of the Drupal installation.
|
Chris@0
|
36 * @param string $suite_namespace
|
Chris@0
|
37 * SubNamespace used to separate test suite. Examples: Unit, Functional.
|
Chris@0
|
38 */
|
Chris@0
|
39 protected function addTestsBySuiteNamespace($root, $suite_namespace) {
|
Chris@0
|
40 // Core's tests are in the namespace Drupal\${suite_namespace}Tests\ and are
|
Chris@0
|
41 // always inside of core/tests/Drupal/${suite_namespace}Tests. The exception
|
Chris@0
|
42 // to this is Unit tests for historical reasons.
|
Chris@0
|
43 if ($suite_namespace == 'Unit') {
|
Chris@14
|
44 $tests = TestDiscovery::scanDirectory("Drupal\\Tests\\", "$root/core/tests/Drupal/Tests");
|
Chris@14
|
45 $tests = array_flip(array_filter(array_flip($tests), function ($test_class) {
|
Chris@14
|
46 // The Listeners directory does not contain tests. Use the class name
|
Chris@14
|
47 // to be compatible with all operating systems.
|
Chris@14
|
48 return !preg_match('/^Drupal\\\\Tests\\\\Listeners\\\\/', $test_class);
|
Chris@14
|
49 }));
|
Chris@14
|
50 $this->addTestFiles($tests);
|
Chris@0
|
51 }
|
Chris@0
|
52 else {
|
Chris@0
|
53 $this->addTestFiles(TestDiscovery::scanDirectory("Drupal\\${suite_namespace}Tests\\", "$root/core/tests/Drupal/${suite_namespace}Tests"));
|
Chris@0
|
54 }
|
Chris@0
|
55
|
Chris@0
|
56 // Extensions' tests will always be in the namespace
|
Chris@0
|
57 // Drupal\Tests\$extension_name\$suite_namespace\ and be in the
|
Chris@0
|
58 // $extension_path/tests/src/$suite_namespace directory. Not all extensions
|
Chris@0
|
59 // will have all kinds of tests.
|
Chris@0
|
60 foreach ($this->findExtensionDirectories($root) as $extension_name => $dir) {
|
Chris@0
|
61 $test_path = "$dir/tests/src/$suite_namespace";
|
Chris@0
|
62 if (is_dir($test_path)) {
|
Chris@0
|
63 $this->addTestFiles(TestDiscovery::scanDirectory("Drupal\\Tests\\$extension_name\\$suite_namespace\\", $test_path));
|
Chris@0
|
64 }
|
Chris@0
|
65 }
|
Chris@0
|
66 }
|
Chris@0
|
67
|
Chris@0
|
68 }
|