diff --git a/core/lib/Drupal/Core/Render/ElementInfoManager.php b/core/lib/Drupal/Core/Render/ElementInfoManager.php index 4756903..98e3d36 100644 --- a/core/lib/Drupal/Core/Render/ElementInfoManager.php +++ b/core/lib/Drupal/Core/Render/ElementInfoManager.php @@ -49,6 +49,9 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac parent::__construct('Element', $namespaces, $module_handler, 'Drupal\Core\Render\Annotation\RenderElement'); } + /** + * {@inheritdoc} + */ public function getInfo($type) { if (!isset($this->elementInfo)) { $this->elementInfo = $this->buildInfo(); diff --git a/core/tests/Drupal/Tests/Core/Render/ElementInfoTest.php b/core/tests/Drupal/Tests/Core/Render/ElementInfoManagerTest.php similarity index 57% rename from core/tests/Drupal/Tests/Core/Render/ElementInfoTest.php rename to core/tests/Drupal/Tests/Core/Render/ElementInfoManagerTest.php index 4479566..fa9cbb3 100644 --- a/core/tests/Drupal/Tests/Core/Render/ElementInfoTest.php +++ b/core/tests/Drupal/Tests/Core/Render/ElementInfoManagerTest.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Tests\Core\Render\ElementInfoTest. + * Contains \Drupal\Tests\Core\Render\ElementInfoManagerTest. */ namespace Drupal\Tests\Core\Render; @@ -14,7 +14,7 @@ * @coversDefaultClass \Drupal\Core\Render\ElementInfoManager * @group Render */ -class ElementInfoTest extends UnitTestCase { +class ElementInfoManagerTest extends UnitTestCase { /** * The class under test. @@ -122,4 +122,76 @@ function ($alter_name, array &$info) { return $data; } + /** + * Tests the getInfo() method when render element plugins are used. + * + * @covers ::getInfo + * @covers ::buildInfo + * + * @dataProvider providerTestGetInfoElementPlugin + */ + public function testGetInfoElementPlugin($plugin_class, $expected_info) { + $this->moduleHandler->expects($this->once()) + ->method('invokeAll') + ->with('element_info') + ->willReturn(array()); + $this->moduleHandler->expects($this->once()) + ->method('alter') + ->with('element_info', $this->anything()) + ->will($this->returnArgument(0)); + + $plugin = $this->getMock($plugin_class); + $plugin->expects($this->once()) + ->method('getInfo') + ->willReturn(array( + '#show_messages' => TRUE, + '#theme' => 'page', + )); + + $element_info = $this->getMockBuilder('Drupal\Core\Render\ElementInfoManager') + ->setConstructorArgs(array(new \ArrayObject(), $this->cache, $this->moduleHandler)) + ->setMethods(array('getDefinitions', 'createInstance')) + ->getMock(); + $element_info->expects($this->once()) + ->method('createInstance') + ->with('page') + ->willReturn($plugin); + $element_info->expects($this->once()) + ->method('getDefinitions') + ->willReturn(array( + 'page' => array('class' => 'TestElementPlugin'), + )); + + $this->assertEquals($expected_info, $element_info->getInfo('page')); + } + + /** + * Provides tests data for testGetInfoElementPlugin(). + * + * @return array + */ + public function providerTestGetInfoElementPlugin() { + $data = array(); + $data[] = array( + 'Drupal\Core\Render\Element\ElementInterface', + array( + '#type' => 'page', + '#show_messages' => TRUE, + '#theme' => 'page', + ), + ); + + $data[] = array( + 'Drupal\Core\Render\Element\FormElementInterface', + array( + '#type' => 'page', + '#show_messages' => TRUE, + '#theme' => 'page', + '#input' => TRUE, + '#value_callback' => array('TestElementPlugin', 'valueCallback'), + ), + ); + return $data; + } + }