diff --git a/core/lib/Drupal/Core/Plugin/Discovery/YamlDiscoveryDecorator.php b/core/lib/Drupal/Core/Plugin/Discovery/YamlDiscoveryDecorator.php new file mode 100644 index 0000000..2957dc0 --- /dev/null +++ b/core/lib/Drupal/Core/Plugin/Discovery/YamlDiscoveryDecorator.php @@ -0,0 +1,58 @@ +decorated = $decorated; + } + + /** + * {@inheritdoc} + */ + public function getDefinitions() { + return parent::getDefinitions() + $this->decorated->getDefinitions(); + } + + /** + * Passes through all unknown calls onto the decorated object. + */ + public function __call($method, $args) { + return call_user_func_array(array($this->decorated, $method), $args); + } + +} diff --git a/core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDiscoveryDecoratorTest.php b/core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDiscoveryDecoratorTest.php new file mode 100644 index 0000000..03141f4 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDiscoveryDecoratorTest.php @@ -0,0 +1,100 @@ + key mappings for testing. + * + * @var array + */ + protected $expectedKeys = array( + 'test_1' => 'test_1_a', + 'another_provider_1' => 'test_1_b', + 'another_provider_2' => 'test_2_a', + 'test_2' => 'test_2_b', + 'decorated_1' => 'decorated_test_1', + 'decorated_2' => 'decorated_test_2', + ); + + public static function getInfo() { + return array( + 'name' => 'YamlDiscoveryDecorator', + 'description' => 'YamlDiscoveryDecorator unit tests.', + 'group' => 'Plugin', + ); + } + + public function setUp() { + parent::setUp(); + + $base_path = __DIR__ . '/Fixtures'; + // Set up the directories to search. + $directories = array( + 'test_1' => $base_path . '/test_1', + 'test_2' => $base_path . '/test_2', + ); + + $definitions = array( + 'decorated_test_1' => array( + 'id' => 'decorated_test_1', + 'name' => 'Decorated test 1', + 'provider' => 'decorated_1', + ), + 'decorated_test_2' => array( + 'id' => 'decorated_test_2', + 'name' => 'Decorated test 1', + 'provider' => 'decorated_2', + ), + ); + + $decorated = $this->getMock('Drupal\Component\Plugin\Discovery\DiscoveryInterface'); + $decorated->expects($this->once()) + ->method('getDefinitions') + ->will($this->returnValue($definitions)); + + $this->discoveryDecorator = new YamlDiscoveryDecorator($decorated, 'test', $directories); + } + + /** + * Tests the getDefinitions() method. + */ + public function testGetDefinitions() { + $definitions = $this->discoveryDecorator->getDefinitions(); + + $this->assertInternalType('array', $definitions); + $this->assertCount(6, $definitions); + + foreach ($this->expectedKeys as $expected_key) { + $this->assertArrayHasKey($expected_key, $definitions); + } + + foreach ($definitions as $id => $definition) { + foreach (array('name', 'id', 'provider') as $key) { + $this->assertArrayHasKey($key, $definition); + } + $this->assertEquals($id, $definition['id']); + $this->assertEquals(array_search($id, $this->expectedKeys), $definition['provider']); + } + } + +}