You are here

public function ExtensionDiscoveryTest::testExtensionDiscoveryVfs in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Extension/ExtensionDiscoveryTest.php \Drupal\Tests\Core\Extension\ExtensionDiscoveryTest::testExtensionDiscoveryVfs()
  2. 9 core/tests/Drupal/Tests/Core/Extension/ExtensionDiscoveryTest.php \Drupal\Tests\Core\Extension\ExtensionDiscoveryTest::testExtensionDiscoveryVfs()

Tests extension discovery in a virtual filesystem with vfsStream.

@covers ::scan

File

core/tests/Drupal/Tests/Core/Extension/ExtensionDiscoveryTest.php, line 25

Class

ExtensionDiscoveryTest
Tests discovery of extensions.

Namespace

Drupal\Tests\Core\Extension

Code

public function testExtensionDiscoveryVfs() {

  // Set up the file system.
  $filesystem = [];
  $files_by_type_and_name_expected = $this
    ->populateFilesystemStructure($filesystem);
  $vfs = vfsStream::setup('root', NULL, $filesystem);
  $root = $vfs
    ->url();
  $this
    ->assertFileExists($root . '/core/modules/system/system.module');
  $this
    ->assertFileExists($root . '/core/modules/system/system.info.yml');

  // Create an ExtensionDiscovery with $root.
  $extension_discovery = new ExtensionDiscovery($root, FALSE, NULL, 'sites/default');

  /** @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');
  $extension_expected->subpath = 'themes/engines/twig';
  $extension_expected->origin = 'core';
  $this
    ->assertEquals($extension_expected, $extensions_by_type['theme_engine']['twig'], 'twig');
}