YamlDiscoveryTest.php 1.13 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php

/**
 * @file
 * Contains \Drupal\Tests\Component\Discovery\YamlDiscoveryTest.
 */

namespace Drupal\Tests\Component\Discovery;

use Drupal\Tests\UnitTestCase;
use Drupal\Component\Discovery\YamlDiscovery;

/**
14
15
16
 * YamlDiscovery component unit tests.
 *
 * @group Discovery
17
18
19
20
21
22
23
24
25
26
27
28
 */
class YamlDiscoveryTest extends UnitTestCase {

  /**
   * Tests the YAML file discovery.
   */
  public function testDiscovery() {
    $base_path = __DIR__ . '/Fixtures';
    // Set up the directories to search.
    $directories = array(
      'test_1' => $base_path . '/test_1',
      'test_2' => $base_path . '/test_2',
29
30
      // Use the same directory with a different provider name.
      'test_3' => $base_path . '/test_2',
31
32
33
34
35
    );

    $discovery = new YamlDiscovery('test', $directories);
    $data = $discovery->findAll();

36
    $this->assertEquals(count($data), count($directories));
37
38
    $this->assertArrayHasKey('test_1', $data);
    $this->assertArrayHasKey('test_2', $data);
39
    $this->assertArrayHasKey('test_3', $data);
40
41
42
43
44
45
46
47

    foreach ($data as $item) {
      $this->assertArrayHasKey('name', $item);
      $this->assertEquals($item['name'], 'test');
    }
  }

}