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