You are here

protected function ExtensionListTest::setupTestExtensionList in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php \Drupal\Tests\Core\Extension\ExtensionListTest::setupTestExtensionList()
  2. 10 core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php \Drupal\Tests\Core\Extension\ExtensionListTest::setupTestExtensionList()

Sets up an a test extension list.

Parameters

string[] $extension_names: The names of the extensions to create.

mixed[] $additional_info_values: The additional values to add to extensions info.yml files. These values will be encoded using '\Drupal\Component\Serialization\Yaml::encode()'. The array keys should be valid top level yaml file keys.

Return value

\Drupal\Tests\Core\Extension\TestExtension The test extension list.

12 calls to ExtensionListTest::setupTestExtensionList()
ExtensionListTest::testCheckIncompatibility in core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php
@covers ::checkIncompatibility
ExtensionListTest::testGet in core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php
@covers ::get
ExtensionListTest::testGetAllAvailableInfo in core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php
@covers ::getAllAvailableInfo
ExtensionListTest::testGetAllInstalledInfo in core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php
@covers ::getAllInstalledInfo
ExtensionListTest::testGetExtensionInfo in core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php
@covers ::getExtensionInfo @covers ::getAllInstalledInfo

... See full list

File

core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php, line 279

Class

ExtensionListTest
@coversDefaultClass \Drupal\Core\Extension\ExtensionList @group Extension

Namespace

Drupal\Tests\Core\Extension

Code

protected function setupTestExtensionList(array $extension_names = [
  'test_name',
], array $additional_info_values = []) {
  vfsStream::setup('drupal_root');
  $folders = [
    'example' => [],
  ];
  foreach ($extension_names as $extension_name) {
    $folders['example'][$extension_name][$extension_name . '.info.yml'] = Yaml::encode([
      'name' => 'test name',
      'type' => 'test_extension',
      'core' => '8.x',
    ] + $additional_info_values);
  }
  vfsStream::create($folders);
  foreach ($extension_names as $extension_name) {
    touch("vfs://drupal_root/example/{$extension_name}/{$extension_name}.info.yml", 123456789);
  }
  list($cache, $info_parser, $module_handler, $state) = $this
    ->getMocks();
  $info_parser
    ->parse(Argument::any())
    ->will(function ($args) {
    return Yaml::decode(file_get_contents('vfs://drupal_root/' . $args[0]));
  });
  $test_extension_list = new TestExtension('vfs://drupal_root', 'test_extension', $cache
    ->reveal(), $info_parser
    ->reveal(), $module_handler
    ->reveal(), $state
    ->reveal(), 'testing');
  $extension_discovery = $this
    ->prophesize(ExtensionDiscovery::class);
  $extension_scan_result = [];
  foreach ($extension_names as $extension_name) {
    $extension_scan_result[$extension_name] = new Extension('vfs://drupal_root', 'test_extension', "example/{$extension_name}/{$extension_name}.info.yml");
  }
  $extension_discovery
    ->scan('test_extension')
    ->willReturn($extension_scan_result);
  $test_extension_list
    ->setExtensionDiscovery($extension_discovery
    ->reveal());
  return $test_extension_list;
}