function IconTest::providerPreRenderIcon

Data provider for ::testPreRenderIcon().

Return value

\Generator Provide test data as:

  • array of information for the icon
  • result array of render element

File

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

Class

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

Namespace

Drupal\Tests\Core\Theme\Icon

Code

public static function providerPreRenderIcon() : iterable {
    (yield 'minimum icon' => [
        [
            'pack_id' => 'pack_id',
            'icon_id' => 'icon_id',
            'source' => '/foo/bar',
            'template' => 'my_template',
        ],
        [
            '#type' => 'inline_template',
            '#template' => 'my_template',
            '#context' => [
                'icon_id' => 'icon_id',
                'source' => '/foo/bar',
                'attributes' => new Attribute(),
            ],
        ],
    ]);
    (yield 'icon with library' => [
        [
            'pack_id' => 'pack_id',
            'icon_id' => 'icon_id',
            'source' => '/foo/bar',
            'template' => 'my_template',
            // Special library will be transformed to #attached.
'library' => 'my_theme/my_library',
        ],
        [
            '#type' => 'inline_template',
            '#template' => 'my_template',
            '#attached' => [
                'library' => [
                    'my_theme/my_library',
                ],
            ],
            '#context' => [
                'icon_id' => 'icon_id',
                'source' => '/foo/bar',
                'attributes' => new Attribute(),
                'library' => 'my_theme/my_library',
            ],
        ],
    ]);
    (yield 'icon with library and data without attributes.' => [
        [
            'pack_id' => 'pack_id',
            'icon_id' => 'icon_id',
            'template' => 'my_template',
            'source' => '/foo/bar',
            'group' => 'test_group',
            // Special library will be transformed to #attached.
'library' => 'my_theme/my_library',
            // Icon data will moved to Twig #context.
'content' => 'test_content',
            'baz' => 'qux',
        ],
        [
            '#type' => 'inline_template',
            '#template' => 'my_template',
            '#attached' => [
                'library' => [
                    'my_theme/my_library',
                ],
            ],
            '#context' => [
                'icon_id' => 'icon_id',
                'source' => '/foo/bar',
                'content' => 'test_content',
                'baz' => 'qux',
                'attributes' => new Attribute(),
                'library' => 'my_theme/my_library',
            ],
        ],
    ]);
    (yield 'icon with attributes.' => [
        [
            'pack_id' => 'pack_id',
            'icon_id' => 'icon_id',
            'source' => '/foo/bar',
            'template' => 'my_template',
            'attributes' => new Attribute([
                'foo' => 'bar',
                'baz' => 'qux',
            ]),
        ],
        [
            '#type' => 'inline_template',
            '#template' => 'my_template',
            '#context' => [
                'icon_id' => 'icon_id',
                'source' => '/foo/bar',
                'attributes' => new Attribute([
                    'foo' => 'bar',
                    'baz' => 'qux',
                ]),
            ],
        ],
    ]);
    (yield 'icon with data and enabled removed.' => [
        [
            'pack_id' => 'pack_id',
            'icon_id' => 'icon_id',
            'source' => '/foo/bar',
            'template' => 'my_template',
            // Icon data will moved to Twig #context.
'enabled' => 'foo',
            'foo' => 'bar',
        ],
        [
            '#type' => 'inline_template',
            '#template' => 'my_template',
            '#context' => [
                'icon_id' => 'icon_id',
                'source' => '/foo/bar',
                'attributes' => new Attribute(),
                'foo' => 'bar',
                'enabled' => 'foo',
            ],
        ],
    ]);
}

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