YamlDiscoveryTest.php 1.13 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php

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

namespace Drupal\Tests\Component\Discovery;

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

/**
 * Tests the YamlDiscovery component class.
 */
class YamlDiscoveryTest extends UnitTestCase {

  public static function getInfo() {
    return array(
      'name' => 'YamlDiscovery',
      'description' => 'YamlDiscovery component unit tests.',
      'group' => 'Discovery',
    );
  }

  /**
   * 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',
    );

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

    $this->assertEquals(count($data), 2);
    $this->assertArrayHasKey('test_1', $data);
    $this->assertArrayHasKey('test_2', $data);

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

}