You are here

function drupal_phpunit_contrib_extension_directory_roots in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/bootstrap.php \drupal_phpunit_contrib_extension_directory_roots()
  2. 10 core/tests/bootstrap.php \drupal_phpunit_contrib_extension_directory_roots()

Returns directories under which contributed extensions may exist.

Parameters

string $root: (optional) Path to the root of the Drupal installation.

Return value

array An array of directories under which contributed extensions may exist.

1 call to drupal_phpunit_contrib_extension_directory_roots()
drupal_phpunit_populate_class_loader in core/tests/bootstrap.php
Populate class loader with additional namespaces for tests.

File

core/tests/bootstrap.php, line 57
Autoloader for Drupal PHPUnit testing.

Code

function drupal_phpunit_contrib_extension_directory_roots($root = NULL) {
  if ($root === NULL) {
    $root = dirname(dirname(__DIR__));
  }
  $paths = [
    $root . '/core/modules',
    $root . '/core/profiles',
    $root . '/modules',
    $root . '/profiles',
    $root . '/themes',
  ];
  $sites_path = $root . '/sites';

  // Note this also checks sites/../modules and sites/../profiles.
  foreach (scandir($sites_path) as $site) {
    if ($site[0] === '.' || $site === 'simpletest') {
      continue;
    }
    $path = "{$sites_path}/{$site}";
    $paths[] = is_dir("{$path}/modules") ? realpath("{$path}/modules") : NULL;
    $paths[] = is_dir("{$path}/profiles") ? realpath("{$path}/profiles") : NULL;
    $paths[] = is_dir("{$path}/themes") ? realpath("{$path}/themes") : NULL;
  }
  return array_filter($paths, 'file_exists');
}