function IconFinderTest::testGetFilesFromSourcesPath

Test the IconFinder::getFilesFromSources method with paths.

@dataProvider providerGetFilesFromSourcesPath

Parameters

array<string> $sources: The list of remote.

array<string, string> $expected: The expected result.

File

core/tests/Drupal/Tests/Core/Theme/Icon/IconFinderTest.php, line 612

Class

IconFinderTest
@coversDefaultClass \Drupal\Core\Theme\Icon\IconFinder[[api-linebreak]]

Namespace

Drupal\Tests\Core\Theme\Icon

Code

public function testGetFilesFromSourcesPath(array $sources, array $expected = []) : void {
  $this->fileUrlGenerator
    ->expects($this->any())
    ->method('generateString')
    ->willReturnCallback(function ($uri) {
    return self::TEST_RELATIVE_URL . $uri;
  });
  $result = $this->iconFinder
    ->getFilesFromSources($sources, self::TEST_ICONS_PATH);
  // Prepare result array matching processFoundFiles() to minimize test data.
  $expected_result = [];
  foreach ($expected as $key => $expected_value) {
    $icon_id = $expected[$key][0];
    $filename = $expected[$key][1];
    $group = $expected[$key][2] ?? NULL;
    $expected_result[$icon_id] = [
      'icon_id' => $icon_id,
      'source' => self::TEST_RELATIVE_URL . '/' . self::TEST_ICONS_PATH . '/' . $filename,
      'absolute_path' => DRUPAL_ROOT . '/' . self::TEST_ICONS_PATH . '/' . $filename,
      'group' => $group,
    ];
  }
  $this->assertEqualsCanonicalizing($expected_result, $result);
}

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