diff --git a/core/lib/Drupal/Core/Extension/Discovery/RecursiveExtensionFilterIterator.php b/core/lib/Drupal/Core/Extension/Discovery/RecursiveExtensionFilterIterator.php index 34a0c72..be2051a 100644 --- a/core/lib/Drupal/Core/Extension/Discovery/RecursiveExtensionFilterIterator.php +++ b/core/lib/Drupal/Core/Extension/Discovery/RecursiveExtensionFilterIterator.php @@ -24,10 +24,9 @@ class RecursiveExtensionFilterIterator extends \RecursiveFilterIterator { // Root subdirectories. 'includes', 'scripts', - // @todo -// 'sites', // @todo Skip ./config directories (but not modules/config). -// 'config', // 'schema', + //'config', + //'schema', ); protected $acceptTests = FALSE; @@ -38,7 +37,6 @@ public function acceptTests($flag = NULL) { } if (!$this->acceptTests) { $this->skipDirs[] = 'tests'; - $this->skipDirs[] = 'testing'; } } @@ -49,17 +47,15 @@ public function getChildren() { } public function accept() { + // Should normally never be TRUE, since ExtensionDiscovery passes the + // FilesystemIterator::SKIP_DOTS flag to RecursiveDirectoryIterator, but + // in case this filter is instantiated from elsewhere, ensure that we are + // not recursing into parent directories. if ($this->isDot()) { return FALSE; } if ($this->isDir()) { -// if ($name[0] == '.') { -// return FALSE; -// } - if (in_array($this->current()->getFilename(), $this->skipDirs, TRUE)) { - return FALSE; - } - return TRUE; + return !in_array($this->current()->getFilename(), $this->skipDirs, TRUE); } else { return substr($this->current()->getFilename(), -9) == '.info.yml'; diff --git a/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php index ce5d80e..bb859b2 100644 --- a/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php +++ b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php @@ -71,7 +71,7 @@ class ExtensionDiscovery { * extensions of type 'module'. * @param bool $include_tests * (optional) Whether to include test extensions. Defaults to FALSE; i.e., - * all 'tests' and 'testing' directories are excluded in the search. + * all 'tests' directories are excluded in the search. * * @return RecursiveDirectoryIterator[] * An associative array of RecursiveDirectoryIterator (SplFileInfo) objects, @@ -117,19 +117,21 @@ public function scan($directory, $include_tests = FALSE) { $searchdirs[] = 'sites/all/' . $directory; $searchdirs[] = "$site/$directory"; + // Unless explicitly requested by Simpletest, manually check whether we are + // are in a test environment, in which case test extensions must be included. + if (!$include_tests) { + // @todo Replace with drupal_valid_test_ua() once avaiable. + // @see https://drupal.org/node/2171683 + $include_tests = !empty($GLOBALS['drupal_test_info']['test_run_id']); + } + $files = array(); foreach ($searchdirs as $dir) { - if ($include_tests) { - $directory_extensions = $this->scanDirectory($dir, $include_tests); - } - else { - if (!isset(static::$files[$dir])) { - static::$files[$dir] = $this->scanDirectory($dir); - } - $directory_extensions = static::$files[$dir]; + if (!isset(static::$files[$dir][$include_tests])) { + static::$files[$dir][$include_tests] = $this->scanDirectory($dir, $include_tests); } - if (isset($directory_extensions[$type])) { - $files = array_merge($files, $this->process($files, $directory_extensions[$type])); + if (isset(static::$files[$dir][$include_tests][$type])) { + $files = array_merge($files, $this->process($files, static::$files[$dir][$include_tests][$type])); } } return $files; @@ -213,21 +215,15 @@ protected function process(array $files, array $files_to_add) { * Recursively scans a base directory for the requested extension type. * * @param string $dir - * The base directory or URI to scan, without trailing slash. - * @param string $key - * The key to be used for the returned associative array of files. Possible - * values are: - * - 'uri' for the file's URI. - * - 'filename' for the basename of the file. - * - 'name' for the name of the file without the extension. - * @param string $mask - * The preg_match() regular expression of the files to find. - * @param string $nomask - * The preg_match() regular expression of the files to ignore. + * The base directory to scan, without trailing slash. + * @param bool $include_tests + * (optional) Whether to include test extensions. Defaults to FALSE; i.e., + * all 'tests' directories are excluded in the search. * * @return array - * An associative array (keyed on the chosen key) of objects with 'uri', - * 'filename', and 'name' members corresponding to the matching files. + * An associative array whose keys are extension types and whose values are + * associative arrays of RecursiveDirectoryIterator (SplFileInfo) objects, + * keyed by extension name. */ protected function scanDirectory($dir, $include_tests = FALSE) { $files = array();