function SvgExtractorTest::testDiscoverIconsSvg

Test the SvgExtractor::discoverIcons() method.

@dataProvider providerDiscoverIconsSvg

Parameters

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

bool $expected_empty: Has icon result, default FALSE.

File

core/tests/Drupal/Tests/Core/Theme/Icon/Plugin/SvgExtractorTest.php, line 121

Class

SvgExtractorTest
@coversDefaultClass \Drupal\Core\Theme\Plugin\IconExtractor\SvgExtractor

Namespace

Drupal\Tests\Core\Theme\Icon\Plugin

Code

public function testDiscoverIconsSvg(array $files, bool $expected_empty = FALSE) : void {
    $this->iconFinder
        ->method('getFilesFromSources')
        ->willReturn($files);
    $result = $this->svgExtractorPlugin
        ->discoverIcons();
    if (TRUE === $expected_empty) {
        $this->assertEmpty($result);
        return;
    }
    $expected_result = [];
    foreach ($files as $index => $icon) {
        $expected_id = $this->pluginId . IconDefinition::ICON_SEPARATOR . $icon['icon_id'];
        $expected_result[$expected_id] = [
            'source' => $icon['source'],
            'absolute_path' => $icon['absolute_path'],
            'group' => $icon['group'],
        ];
    }
    $this->assertEquals($expected_result, $result);
}

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