You are here

public function ElementInfoManagerTest::testGetInfoElementPlugin in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Render/ElementInfoManagerTest.php \Drupal\Tests\Core\Render\ElementInfoManagerTest::testGetInfoElementPlugin()
  2. 9 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 79
Contains \Drupal\Tests\Core\Render\ElementInfoManagerTest.

Class

ElementInfoManagerTest
@coversDefaultClass \Drupal\Core\Render\ElementInfoManager @group Render

Namespace

Drupal\Tests\Core\Render

Code

public function testGetInfoElementPlugin($plugin_class, $expected_info) {
  $this->moduleHandler
    ->expects($this
    ->once())
    ->method('alter')
    ->with('element_info', $this
    ->anything())
    ->will($this
    ->returnArgument(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->cacheTagsInvalidator,
    $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'));
}