function ElementInfoManagerTest::testGetInfoElementPlugin

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Render/ElementInfoManagerTest.php \Drupal\Tests\Core\Render\ElementInfoManagerTest::testGetInfoElementPlugin()
  2. 8.9.x core/tests/Drupal/Tests/Core/Render/ElementInfoManagerTest.php \Drupal\Tests\Core\Render\ElementInfoManagerTest::testGetInfoElementPlugin()
  3. 11.x core/tests/Drupal/Tests/Core/Render/ElementInfoManagerTest.php \Drupal\Tests\Core\Render\ElementInfoManagerTest::testGetInfoElementPlugin()

Tests the getInfo() method when render element plugins are used.

@covers ::getInfo
@covers ::buildInfo

@dataProvider providerTestGetInfoElementPlugin

File

core/tests/Drupal/Tests/Core/Render/ElementInfoManagerTest.php, line 77

Class

ElementInfoManagerTest
@coversDefaultClass \Drupal\Core\Render\ElementInfoManager[[api-linebreak]] @group Render

Namespace

Drupal\Tests\Core\Render

Code

public function testGetInfoElementPlugin($plugin_class, $expected_info) : void {
  $this->moduleHandler
    ->expects($this->once())
    ->method('alter')
    ->with('element_info', $this->anything())
    ->willReturnArgument(0);
  $plugin = $this->createMock($plugin_class);
  $plugin->expects($this->once())
    ->method('getInfo')
    ->willReturn([
    '#theme' => 'page',
  ]);
  $element_info = $this->getMockBuilder('Drupal\\Core\\Render\\ElementInfoManager')
    ->setConstructorArgs([
    new \ArrayObject(),
    $this->cache,
    $this->themeHandler,
    $this->moduleHandler,
    $this->themeManager,
  ])
    ->onlyMethods([
    'getDefinitions',
    'createInstance',
  ])
    ->getMock();
  $this->themeManager
    ->expects($this->any())
    ->method('getActiveTheme')
    ->willReturn(new ActiveTheme([
    'name' => 'test',
  ]));
  $element_info->expects($this->once())
    ->method('createInstance')
    ->with('page')
    ->willReturn($plugin);
  $element_info->expects($this->once())
    ->method('getDefinitions')
    ->willReturn([
    'page' => [
      'class' => 'TestElementPlugin',
    ],
  ]);
  $this->assertEquals($expected_info, $element_info->getInfo('page'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.