function SvgExtractorTest::testLoadIconSvg

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Theme/Icon/Plugin/SvgExtractorTest.php \Drupal\Tests\Core\Theme\Icon\Plugin\SvgExtractorTest::testLoadIconSvg()

Test the SvgExtractor::loadIcon() method.

Attributes

#[DataProvider('providerLoadIconSvg')]

Parameters

array<array<string, string>> $icons_extracted: The icons data to test.

array<string> $file_content: The content returned by IconFinder:getFileContents.

array<string> $expected_content: The icons expected content.

array<string, string> $expected_attributes: The attributes expected.

File

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

Class

SvgExtractorTest
Tests Drupal\Core\Theme\Plugin\IconExtractor\SvgExtractor.

Namespace

Drupal\Tests\Core\Theme\Icon\Plugin

Code

public function testLoadIconSvg(array $icons_extracted = [], array $file_content = [], array $expected_content = [], ?array $expected_attributes = NULL) : void {
  foreach ($icons_extracted as $index => $icon) {
    $this->iconFinder
      ->method('getFileContents')
      ->with($icon['absolute_path'])
      ->willReturn($file_content[$index]);
    $icon_loaded = $this->svgExtractorPlugin
      ->loadIcon($icon);
    // Empty or ignored file test.
    if (empty($expected_content[$index])) {
      $this->assertNull($icon_loaded);
      continue;
    }
    $this->assertInstanceOf(IconDefinitionInterface::class, $icon_loaded);
    $data_loaded = $icon_loaded->getAllData();
    $this->assertEquals($expected_content[$index], $data_loaded['content']);
    $expected_attributes[$index] = new Attribute($expected_attributes[$index] ?? []);
    $this->assertEquals($expected_attributes[$index], $data_loaded['attributes']);
    $expected_id = $this->pluginId . IconDefinition::ICON_SEPARATOR . $icon['icon_id'];
    $this->assertSame($expected_id, $icon_loaded->getId());
    // Basic data are not altered and can be compared directly.
    $this->assertSame($icon['icon_id'], $icon_loaded->getIconId());
    $this->assertSame($icon['source'], $icon_loaded->getSource());
    $this->assertSame($icon['group'] ?? NULL, $icon_loaded->getGroup());
  }
}

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