function SvgSpriteExtractorTest::testDiscoverIconsSvgSprite

Test the SvgSpriteExtractor::discoverIcons() method.

@dataProvider providerDiscoverIconsSvgSprite

Parameters

array<array<string, string>> $files: The files to test from IconFinder::getFilesFromSources.

array<int, array<int, mixed>> $contents_map: The content returned by fileGetContents() based on absolute_path.

array<string> $expected: The icon ids expected.

File

core/tests/Drupal/Tests/Core/Theme/Icon/Plugin/SvgSpriteExtractorTest.php, line 156

Class

SvgSpriteExtractorTest
@coversDefaultClass \Drupal\Core\Theme\Plugin\IconExtractor\SvgSpriteExtractor

Namespace

Drupal\Tests\Core\Theme\Icon\Plugin

Code

public function testDiscoverIconsSvgSprite(array $files = [], array $contents_map = [], array $expected = []) : void {
    $this->iconFinder
        ->method('getFilesFromSources')
        ->willReturn($files);
    $this->iconFinder
        ->method('getFileContents')
        ->willReturnMap($contents_map);
    $result = $this->svgSpriteExtractorPlugin
        ->discoverIcons();
    if (empty($expected)) {
        $this->assertEmpty($result);
        return;
    }
    // Basic data are not altered and can be compared directly.
    $index = 0;
    foreach ($result as $icon_id => $icon_data) {
        $expected_id = $this->pluginId . IconDefinition::ICON_SEPARATOR . $expected[$index];
        $this->assertSame($expected_id, $icon_id);
        $index++;
    }
}

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