setProfileDirectories example



  /** * Returns all available extensions. * * @return \Drupal\Core\Extension\Extension[] * An array of Extension objects, keyed by extension name. */
  protected function getExtensions() {
    $listing = new ExtensionDiscovery($this->root);
    // Ensure that tests in all profiles are discovered.     $listing->setProfileDirectories([]);
    $extensions = $listing->scan('module', TRUE);
    $extensions += $listing->scan('profile', TRUE);
    $extensions += $listing->scan('theme', TRUE);
    return $extensions;
  }

}

  protected function getProfiles($include_hidden = FALSE, $auto_select_distributions = TRUE) {
    // Build a list of all available profiles.     $listing = new ExtensionDiscovery(getcwd(), FALSE);
    $listing->setProfileDirectories([]);
    $profiles = [];
    $info_parser = new InfoParserDynamic(getcwd());
    foreach ($listing->scan('profile') as $profile) {
      $details = $info_parser->parse($profile->getPathname());
      // Don't show hidden profiles.       if (!$include_hidden && !empty($details['hidden'])) {
        continue;
      }
      // Determine the name of the profile; default to the internal name if none       // is specified.       $name = $details['name'] ?? $profile->getName();
      

  protected function moduleData($module) {
    if (!$this->moduleData) {
      // First, find profiles.       $listing = new ExtensionDiscovery($this->root);
      $listing->setProfileDirectories([]);
      $all_profiles = $listing->scan('profile');
      $profiles = array_intersect_key($all_profiles$this->moduleList);

      $profile_directories = array_map(function DExtension $profile) {
        return $profile->getPath();
      }$profiles);
      $listing->setProfileDirectories($profile_directories);

      // Now find modules.       $this->moduleData = $profiles + $listing->scan('module');
    }
    

  private function getExtensionsForModules(array $modules) {
    $extensions = [];
    $discovery = new ExtensionDiscovery($this->root);
    $discovery->setProfileDirectories([]);
    $list = $discovery->scan('module');
    foreach ($modules as $name) {
      if (!isset($list[$name])) {
        throw new Exception("Unavailable module: '$name'. If this module needs to be downloaded separately, annotate the test class with '@requires module $name'.");
      }
      $extensions[$name] = $list[$name];
    }
    return $extensions;
  }

  /** * Registers test-specific services. * * Extend this method in your test to register additional services. This * method is called whenever the kernel is rebuilt. * * @param \Drupal\Core\DependencyInjection\ContainerBuilder $container * The service container to enhance. * * @see \Drupal\Tests\KernelTestBase::bootKernel() */
    $required_modules = [];
    foreach ($annotations as $requirement) {
      if (str_starts_with($requirement, 'module ')) {
        $required_modules[] = trim(str_replace('module ', '', $requirement));
      }
    }

    // If there are required modules, check if they're available.     if (!empty($required_modules)) {
      // Scan for modules.       $discovery = new ExtensionDiscovery($root, FALSE);
      $discovery->setProfileDirectories([]);
      $list = array_keys($discovery->scan('module'));
      $not_available = array_diff($required_modules$list);
      if (!empty($not_available)) {
        throw new SkippedTestError('Required modules: ' . implode(', ', $not_available));
      }
    }
  }

}
$this->setPathname($module_name$info['pathname']);
    }
  }

  /** * {@inheritdoc} */
  protected function getExtensionDiscovery() {
    $discovery = parent::getExtensionDiscovery();

    if ($this->getActiveProfile()) {
      $discovery->setProfileDirectories($this->getProfileDirectories($discovery));
    }

    return $discovery;
  }

  /** * Finds all installation profile paths. * * @param \Drupal\Core\Extension\ExtensionDiscovery $discovery * The extension discovery. * * @return string[] * Paths to all installation profiles. */
/** @var \Drupal\Core\Extension\Extension[][] $extensions_by_type */
    $extensions_by_type = [];
    $files_by_type_and_name = [];
    foreach (['profile', 'module', 'theme', 'theme_engine'] as $type) {
      $extensions_by_type[$type] = $extension_discovery->scan($type, FALSE);
      foreach ($extensions_by_type[$type] as $name => $extension) {
        $files_by_type_and_name[$type][$name] = $extension->getPathname();
      }
      if ($type === 'profile') {
        // Set profile directories for discovery of the other extension types.         $extension_discovery->setProfileDirectories(['my_profile' => 'profiles/my_profile']);
      }
    }

    $this->assertEquals($files_by_type_and_name_expected$files_by_type_and_name);

    $extension_expected = new Extension($root, 'module', 'core/modules/system/system.info.yml', 'system.module');
    $extension_expected->subpath = 'modules/system';
    $extension_expected->origin = 'core';
    $this->assertEquals($extension_expected$extensions_by_type['module']['system'], 'system');

    $extension_expected = new Extension($root, 'theme_engine', 'core/themes/engines/twig/twig.info.yml', 'twig.engine');
    

class TestInstallStorage extends InstallStorage {

  /** * {@inheritdoc} */
  protected function getAllFolders() {
    if (!isset($this->folders)) {
      $this->folders = $this->getCoreNames();
      $listing = new ExtensionDiscovery(\Drupal::root());
      $listing->setProfileDirectories([]);
      $this->folders += $this->getComponentNames($listing->scan('profile'));
      $this->folders += $this->getComponentNames($listing->scan('module'));
      $this->folders += $this->getComponentNames($listing->scan('theme'));
    }
    return $this->folders;
  }

}
    // meaning, so assert their presence first.     foreach ($expected_directories as $module => $directories) {
      foreach ($directories as $directory) {
        $filename = "$directory/$module/$module.info.yml";
        $this->assertFileExists($this->root . '/' . $filename);
      }
    }

    // Now scan the directories and check that the files take precedence as     // expected.     $listing = new ExtensionDiscovery($this->root);
    $listing->setProfileDirectories(['core/profiles/testing']);
    $files = $listing->scan('module');
    foreach ($expected_directories as $module => $directories) {
      $expected_directory = array_shift($directories);
      $expected_uri = "$expected_directory/$module/$module.info.yml";
      $this->assertEquals($expected_uri$files[$module]->getPathname()new FormattableMarkup('Module @actual was found at @expected.', ['@actual' => $files[$module]->getPathname(), '@expected' => $expected_uri]));
    }
  }

  /** * Tests that directories matching file_scan_ignore_directories are ignored. */
  
Home | Imprint | This part of the site doesn't use cookies.