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