function ElementInfoManagerTest::testGetInfoElementPlugin

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

Class

ElementInfoManagerTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Render%21ElementInfoManager.php/class/ElementInfoManager/9" title="Provides a plugin manager for element plugins." class="local">\Drupal\Core\Render\ElementInfoManager</a> @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'));
}

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