diff --git a/core/tests/bootstrap.php b/core/tests/bootstrap.php index e4272d2..65679fe 100644 --- a/core/tests/bootstrap.php +++ b/core/tests/bootstrap.php @@ -8,85 +8,85 @@ */ /** - * Finds all valid module directories recursively within a given directory. + * Finds all valid extension directories recursively within a given directory. * * @param string $scan_directory * The directory that should be recursively scanned. * @return array - * An associative array of module directories found within the scanned - * directory, keyed by module name. + * An associative array of extension directories found within the scanned + * directory, keyed by extension name. */ -function drupal_phpunit_find_module_directories($scan_directory) { - $module_directories = array(); +function drupal_phpunit_find_extension_directories($scan_directory) { + $extensions = array(); $dir = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($scan_directory, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS)); foreach ($dir as $d) { if (strpos($d->getPathname(), 'info.yml') !== FALSE) { - // Cut off ".info.yml" from the filename and use that as the module name. - $module_directories[substr($d->getFilename(), 0, -9)] = $d->getPathInfo()->getRealPath(); + // Cut off ".info.yml" from the filename to be used as the extension name. + $extensions[substr($d->getFilename(), 0, -9)] = $d->getPathInfo()->getRealPath(); } } - return $module_directories; + return $extensions; } /** - * Finds site-specific module directories given the path to the sites folder. + * Returns directories under which contributed extensions may exist. * - * @param string $sites_path - * The path to the sites folder. * @return array - * An array of site-specific module directories. + * An array of directories under which contributed extensions may exist. */ -function drupal_phpunit_find_site_module_directories($sites_path) { - $module_paths = array_map(function($dir) use ($sites_path) { - $module_dir = "$sites_path/$dir/modules"; - if (is_dir($module_dir)) { - return realpath($module_dir); - } - }, scandir($sites_path)); - return array_filter($module_paths); +function drupal_phpunit_contrib_extension_directory_roots() { + $sites_path = __DIR__ . '/../../sites'; + $paths = array(); + // Note this also checks sites/../modules, themes, and profiles. + foreach (scandir($sites_path) as $site) { + $path = "$sites_path/$site"; + $paths[] = is_dir("$path/modules") ? realpath("$path/modules") : NULL; + $paths[] = is_dir("$path/themes") ? realpath("$path/themes") : NULL; + $paths[] = is_dir("$path/profiles") ? realpath("$path/profiles") : NULL; + } + return array_filter($paths); } /** - * Registers the namespace for each module directory with the autoloader. + * Registers the namespace for each extension directory with the autoloader. * * @param Composer\Autoload\ClassLoader $loader * The supplied autoloader. * @param array $dirs - * An associative array of module directories, keyed by module name. + * An associative array of extension directories, keyed by extension name. */ -function drupal_phpunit_register_module_dirs(Composer\Autoload\ClassLoader $loader, $dirs) { - foreach ($dirs as $module => $dir) { +function drupal_phpunit_register_extension_dirs(Composer\Autoload\ClassLoader $loader, $dirs) { + foreach ($dirs as $extension => $dir) { $lib_path = $dir . '/lib'; if (is_dir($lib_path)) { - $loader->add('Drupal\\' . $module, $lib_path); + $loader->add('Drupal\\' . $extension, $lib_path); } $tests_path = $dir . '/tests'; if (is_dir($tests_path)) { - $loader->add('Drupal\\' . $module, $tests_path); + $loader->add('Drupal\\' . $extension, $tests_path); } } } // Start with classes in known locations. -$loader = require __DIR__ . "/../vendor/autoload.php"; +$loader = require __DIR__ . '/../vendor/autoload.php'; $loader->add('Drupal\\', __DIR__); -$loader->add('Drupal\Core', __DIR__ . "/../../core/lib"); -$loader->add('Drupal\Component', __DIR__ . "/../../core/lib"); +$loader->add('Drupal\Core', __DIR__ . '/../../core/lib'); +$loader->add('Drupal\Component', __DIR__ . '/../../core/lib'); -// Scan for arbitrary module namespaces. -$module_locations = array_merge(array( - __DIR__ . "/../modules", - __DIR__ . "/../../modules", - __DIR__ . "/../../profiles", - __DIR__ . "/../../themes", -), drupal_phpunit_find_site_module_directories(__DIR__ . "/../../sites")); +// Scan for arbitrary extension namespaces from core and contrib. +$extension_roots = array_merge(array( + __DIR__ . '/../modules', + __DIR__ . '/../themes', + __DIR__ . '/../profiles', +), drupal_phpunit_contrib_extension_directory_roots()); -$dirs = array_map('drupal_phpunit_find_module_directories', $module_locations); +$dirs = array_map('drupal_phpunit_find_extension_directories', $extension_roots); $dirs = array_reduce($dirs, 'array_merge', array()); -drupal_phpunit_register_module_dirs($loader, $dirs); +drupal_phpunit_register_extension_dirs($loader, $dirs); -require __DIR__ . "/../../core/lib/Drupal.php"; +require __DIR__ . '/../../core/lib/Drupal.php'; // Look into removing this later. define('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']);