function IconTest::testPreRenderIcon

Test the Icon::preRenderIcon method.

@dataProvider providerPreRenderIcon

Parameters

array $data: The icon data.

array $expected: The result expected.

File

core/tests/Drupal/Tests/Core/Theme/Icon/IconTest.php, line 192

Class

IconTest
@coversDefaultClass \Drupal\Core\Render\Element\Icon

Namespace

Drupal\Tests\Core\Theme\Icon

Code

public function testPreRenderIcon(array $data, array $expected) : void {
    $icon = $this->createTestIcon($data);
    $icon_full_id = IconDefinition::createIconId($data['pack_id'], $data['icon_id']);
    $prophecy = $this->prophesize(IconPackManagerInterface::class);
    $prophecy->getIcon($icon_full_id)
        ->willReturn($icon);
    $pluginManagerIconPack = $prophecy->reveal();
    $this->container
        ->set('plugin.manager.icon_pack', $pluginManagerIconPack);
    $element = [
        '#type' => 'icon',
        '#pack_id' => $data['pack_id'],
        '#icon_id' => $data['icon_id'],
        '#settings' => $data['icon_settings'] ?? [],
    ];
    $actual = Icon::preRenderIcon($element);
    $this->assertEquals($expected, $actual['inline-template']);
}

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