function PathExtractorTest::testDiscoverIconsPath

Test the PathExtractor::discoverIcons() method.

@dataProvider providerDiscoverIconsPath

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/PathExtractorTest.php, line 116

Class

PathExtractorTest
@coversDefaultClass \Drupal\Core\Theme\Plugin\IconExtractor\PathExtractor[[api-linebreak]]

Namespace

Drupal\Tests\Core\Theme\Icon\Plugin

Code

public function testDiscoverIconsPath(array $files, bool $expected_empty = FALSE) : void {
  $this->iconFinder
    ->method('getFilesFromSources')
    ->willReturn($files);
  $result = $this->pathExtractorPlugin
    ->discoverIcons();
  if (TRUE === $expected_empty) {
    $this->assertEmpty($result);
    return;
  }
  // Result expected is keyed by icon_id with values 'source' and 'group'.
  $expected_result = [];
  foreach ($files as $icon) {
    $expected_id = $this->pluginId . IconDefinition::ICON_SEPARATOR . $icon['icon_id'];
    if (!isset($icon['group'])) {
      $icon['group'] = NULL;
    }
    unset($icon['icon_id']);
    $expected_result[$expected_id] = $icon;
  }
  $this->assertEquals($expected_result, $result);
}

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