function ElementInfoManagerTest::testGetInfoElementPlugin

Same name 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 \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'));
}

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