You are here

public function YamlDirectoryDiscoveryTest::testGetDefinitions in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDirectoryDiscoveryTest.php \Drupal\Tests\Core\Plugin\Discovery\YamlDirectoryDiscoveryTest::testGetDefinitions()
  2. 9 core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDirectoryDiscoveryTest.php \Drupal\Tests\Core\Plugin\Discovery\YamlDirectoryDiscoveryTest::testGetDefinitions()

@covers ::getDefinitions

File

core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDirectoryDiscoveryTest.php, line 21

Class

YamlDirectoryDiscoveryTest
@coversDefaultClass \Drupal\Core\Plugin\Discovery\YamlDirectoryDiscovery

Namespace

Drupal\Tests\Core\Plugin\Discovery

Code

public function testGetDefinitions() {
  vfsStream::setup('modules', NULL, [
    'module_a' => [
      'subdir1' => [
        'plugin1.yml' => "id: plugin1\ntest_provider: module_a",
        'plugin2.yml' => "id: plugin2\ntest_provider: module_a",
      ],
      'subdir2' => [
        'plugin3.yml' => "id: plugin3\ntest_provider: module_a",
      ],
      'subdir3' => [],
    ],
    'module_b' => [
      'subdir1' => [
        'plugin4.yml' => "id: plugin4\ntest_provider: module_b",
      ],
    ],
  ]);
  $directories = [
    'module_a' => [
      vfsStream::url('modules/module_a/subdir1'),
      vfsStream::url('modules/module_a/subdir2'),
      // Empty directory.
      vfsStream::url('modules/module_a/subdir3'),
      // Directory does not exist.
      vfsStream::url('modules/module_a/subdir4'),
    ],
    'module_b' => vfsStream::url('modules/module_b/subdir1'),
  ];
  $discovery = new YamlDirectoryDiscovery($directories, 'test');
  $definitions = $discovery
    ->getDefinitions();
  $this
    ->assertIsArray($definitions);
  $this
    ->assertCount(4, $definitions);
  foreach ($definitions as $id => $definition) {
    foreach ([
      'id',
      'provider',
      ComponentYamlDirectoryDiscovery::FILE_KEY,
    ] as $key) {
      $this
        ->assertArrayHasKey($key, $definition);
    }
    $this
      ->assertEquals($id, $definition['id']);
    $this
      ->assertEquals($definition['test_provider'], $definition['provider']);
  }
}