function IconFinderTest::providerGetFilesFromSourcesPath

Data provider for ::testGetFilesFromSourcesPath().

Return value

\Generator The test cases, to minimize test data, result expected is an array with:

  • icon_id: the expected id
  • path: expected path found relative to TEST_ICONS_PATH
  • group: The group name if any

File

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

Class

IconFinderTest
@coversDefaultClass \Drupal\Core\Theme\Icon\IconFinder

Namespace

Drupal\Tests\Core\Theme\Icon

Code

public static function providerGetFilesFromSourcesPath() : iterable {
    (yield 'path empty' => [
        [
            '',
        ],
    ]);
    (yield 'direct file without path' => [
        [
            'foo.svg',
        ],
        [
            [
                'foo',
                'foo.svg',
            ],
        ],
    ]);
    (yield 'direct file without extension' => [
        [
            'foo',
        ],
        [
            [
                'foo',
                'foo.svg',
            ],
        ],
    ]);
    (yield 'direct file without extension wildcard' => [
        [
            'foo.*',
        ],
        [
            [
                'foo',
                'foo.svg',
            ],
        ],
    ]);
    (yield 'direct file with wildcard and extension' => [
        [
            '*.svg',
        ],
        [
            [
                'foo',
                'foo.svg',
            ],
        ],
    ]);
    (yield 'direct file with wildcard only' => [
        [
            '*',
        ],
        [
            [
                'foo',
                'foo.svg',
            ],
        ],
    ]);
    (yield 'direct file with wildcards' => [
        [
            '*.*',
        ],
        [
            [
                'foo',
                'foo.svg',
            ],
        ],
    ]);
    (yield 'path valid' => [
        [
            'icons/flat/foo.png',
            'icons/flat/bar.svg',
        ],
        [
            [
                'foo',
                'icons/flat/foo.png',
            ],
            [
                'bar',
                'icons/flat/bar.svg',
            ],
        ],
    ]);
    (yield 'absolute path valid' => [
        [
            '/' . self::TEST_ICONS_PATH . '/icons/flat/foo.png',
        ],
        [
            [
                'foo',
                'icons/flat/foo.png',
            ],
        ],
    ]);
    (yield 'path not allowed extension' => [
        [
            // File exist but not valid extension.
'icons/flat/foo.webp',
            'icons/flat/*.webp',
            // Non existent file.
'icons/flat/foo-1.jpg',
        ],
    ]);
    (yield 'path without extension' => [
        [
            'icons/flat/foo',
        ],
        [
            [
                'foo',
                'icons/flat/foo.svg',
            ],
        ],
    ]);
    (yield 'path wildcard extension' => [
        [
            'icons/flat/foo.*',
        ],
        [
            [
                'foo',
                'icons/flat/foo.svg',
            ],
        ],
    ]);
    (yield 'path wildcard filename' => [
        [
            'icons/flat/*.svg',
        ],
        [
            [
                'bar-2',
                'icons/flat/bar-2.svg',
            ],
            [
                'bar',
                'icons/flat/bar.svg',
            ],
            [
                'baz-2',
                'icons/flat/baz-2.svg',
            ],
            [
                'foo',
                'icons/flat/foo.svg',
            ],
            [
                '64x64',
                'icons/flat/64x64.svg',
            ],
        ],
    ]);
    (yield 'path wildcard increment filename' => [
        [
            'icons/flat_same_name/*',
        ],
        [
            [
                'foo',
                'icons/flat_same_name/foo.svg',
            ],
        ],
    ]);
    (yield 'path wildcard filename with extension' => [
        [
            'icons/flat/*.svg',
        ],
        [
            [
                'bar-2',
                'icons/flat/bar-2.svg',
            ],
            [
                'baz-2',
                'icons/flat/baz-2.svg',
            ],
            [
                'foo',
                'icons/flat/foo.svg',
            ],
            [
                'bar',
                'icons/flat/bar.svg',
            ],
            [
                '64x64',
                'icons/flat/64x64.svg',
            ],
        ],
    ]);
    (yield 'path wildcard' => [
        [
            '*/flat/*',
        ],
        [
            [
                'bar-2',
                'icons/flat/bar-2.svg',
            ],
            [
                'bar',
                'icons/flat/bar.svg',
            ],
            [
                'baz-1',
                'icons/flat/baz-1.png',
            ],
            [
                'baz-2',
                'icons/flat/baz-2.svg',
            ],
            [
                'foo',
                'icons/flat/foo.svg',
            ],
            [
                '64x64',
                'icons/flat/64x64.svg',
            ],
        ],
    ]);
    (yield 'mix wildcard and extensions' => [
        [
            'icons/flat/foo.*',
            'icons/flat/foo.svg',
        ],
        [
            [
                'foo',
                'icons/flat/foo.svg',
            ],
        ],
    ]);
    (yield 'path group no result' => [
        [
            'icons/group/*',
        ],
        [],
    ]);
    (yield 'path with folder wildcard' => [
        [
            'icons/group/*/*',
        ],
        [
            [
                'bar_group_1',
                'icons/group/group_1/bar_group_1.png',
            ],
            [
                'bar_group_2',
                'icons/group/group_2/bar_group_2.png',
            ],
            [
                'baz_group_1',
                'icons/group/group_1/baz_group_1.png',
            ],
            [
                'baz_group_2',
                'icons/group/group_2/baz_group_2.png',
            ],
            [
                'corge_group_1',
                'icons/group/group_1/corge_group_1.svg',
            ],
            [
                'corge_group_2',
                'icons/group/group_2/corge_group_2.svg',
            ],
            [
                'foo_group_1',
                'icons/group/group_1/foo_group_1.svg',
            ],
            [
                'foo_group_2',
                'icons/group/group_2/foo_group_2.svg',
            ],
        ],
    ]);
    (yield 'path sub group wildcard' => [
        [
            'icons/group/*/sub_sub_group_1/*',
        ],
        [
            [
                'foo_sub_group_1',
                'icons/group/sub_group_1/sub_sub_group_1/foo_sub_group_1.png',
            ],
            [
                'bar_sub_group_1',
                'icons/group/sub_group_1/sub_sub_group_1/bar_sub_group_1.svg',
            ],
        ],
    ]);
    (yield 'path sub group wildcard partial and filename' => [
        [
            'icons/group/*/sub_sub_group_*/*',
        ],
        [
            [
                'foo_sub_group_1',
                'icons/group/sub_group_1/sub_sub_group_1/foo_sub_group_1.png',
            ],
            [
                'corge_sub_group_2',
                'icons/group/sub_group_2/sub_sub_group_2/corge_sub_group_2.png',
            ],
            [
                'bar_sub_group_1',
                'icons/group/sub_group_1/sub_sub_group_1/bar_sub_group_1.svg',
            ],
            [
                'baz_sub_group_2',
                'icons/group/sub_group_2/sub_sub_group_2/baz_sub_group_2.svg',
            ],
        ],
    ]);
    (yield 'path sub group multiple wildcard folder and filename' => [
        [
            'icons/group/*/*/*',
        ],
        [
            [
                'foo_sub_group_1',
                'icons/group/sub_group_1/sub_sub_group_1/foo_sub_group_1.png',
            ],
            [
                'corge_sub_group_2',
                'icons/group/sub_group_2/sub_sub_group_2/corge_sub_group_2.png',
            ],
            [
                'bar_sub_group_1',
                'icons/group/sub_group_1/sub_sub_group_1/bar_sub_group_1.svg',
            ],
            [
                'baz_sub_group_2',
                'icons/group/sub_group_2/sub_sub_group_2/baz_sub_group_2.svg',
            ],
        ],
    ]);
    // Start tests for the {group} placeholder.
    (yield 'path with {group} extracted' => [
        [
            'icons/group/{group}/*',
        ],
        [
            [
                'bar_group_1',
                'icons/group/group_1/bar_group_1.png',
                'group_1',
            ],
            [
                'baz_group_1',
                'icons/group/group_1/baz_group_1.png',
                'group_1',
            ],
            [
                'bar_group_2',
                'icons/group/group_2/bar_group_2.png',
                'group_2',
            ],
            [
                'baz_group_2',
                'icons/group/group_2/baz_group_2.png',
                'group_2',
            ],
            [
                'corge_group_1',
                'icons/group/group_1/corge_group_1.svg',
                'group_1',
            ],
            [
                'foo_group_1',
                'icons/group/group_1/foo_group_1.svg',
                'group_1',
            ],
            [
                'corge_group_2',
                'icons/group/group_2/corge_group_2.svg',
                'group_2',
            ],
            [
                'foo_group_2',
                'icons/group/group_2/foo_group_2.svg',
                'group_2',
            ],
        ],
    ]);
    (yield 'test group extracted wildcard after' => [
        [
            'icons/group/{group}/*/*',
        ],
        [
            [
                'bar_sub_group_1',
                'icons/group/sub_group_1/sub_sub_group_1/bar_sub_group_1.svg',
                'sub_group_1',
            ],
            [
                'baz_sub_group_2',
                'icons/group/sub_group_2/sub_sub_group_2/baz_sub_group_2.svg',
                'sub_group_2',
            ],
            [
                'corge_sub_group_2',
                'icons/group/sub_group_2/sub_sub_group_2/corge_sub_group_2.png',
                'sub_group_2',
            ],
            [
                'foo_sub_group_1',
                'icons/group/sub_group_1/sub_sub_group_1/foo_sub_group_1.png',
                'sub_group_1',
            ],
        ],
    ]);
    (yield 'test group extracted wildcard before' => [
        [
            'icons/group/*/{group}/*',
        ],
        [
            [
                'bar_sub_group_1',
                'icons/group/sub_group_1/sub_sub_group_1/bar_sub_group_1.svg',
                'sub_sub_group_1',
            ],
            [
                'baz_sub_group_2',
                'icons/group/sub_group_2/sub_sub_group_2/baz_sub_group_2.svg',
                'sub_sub_group_2',
            ],
            [
                'corge_sub_group_2',
                'icons/group/sub_group_2/sub_sub_group_2/corge_sub_group_2.png',
                'sub_sub_group_2',
            ],
            [
                'foo_sub_group_1',
                'icons/group/sub_group_1/sub_sub_group_1/foo_sub_group_1.png',
                'sub_sub_group_1',
            ],
        ],
    ]);
    (yield 'test group extracted wildcard both' => [
        [
            'icons/*/{group}/*/*',
        ],
        [
            [
                'bar_sub_group_1',
                'icons/group/sub_group_1/sub_sub_group_1/bar_sub_group_1.svg',
                'sub_group_1',
            ],
            [
                'baz_sub_group_2',
                'icons/group/sub_group_2/sub_sub_group_2/baz_sub_group_2.svg',
                'sub_group_2',
            ],
            [
                'corge_sub_group_2',
                'icons/group/sub_group_2/sub_sub_group_2/corge_sub_group_2.png',
                'sub_group_2',
            ],
            [
                'foo_sub_group_1',
                'icons/group/sub_group_1/sub_sub_group_1/foo_sub_group_1.png',
                'sub_group_1',
            ],
        ],
    ]);
    (yield 'test group same name' => [
        [
            'icons/group_same_name/{group}/*',
        ],
        [
            [
                'foo',
                'icons/group_same_name/group_3/foo.svg',
                'group_3',
            ],
        ],
    ]);
    // Start tests for the {icon_id} placeholder.
    (yield 'direct file with icon_id' => [
        [
            '{icon_id}',
        ],
        [
            [
                'foo',
                'foo.svg',
            ],
        ],
    ]);
    (yield 'direct file with icon_id and extension' => [
        [
            '{icon_id}.svg',
        ],
        [
            [
                'foo',
                'foo.svg',
            ],
        ],
    ]);
    (yield 'direct file with icon_id and extension wildcard' => [
        [
            '{icon_id}.*',
        ],
        [
            [
                'foo',
                'foo.svg',
            ],
        ],
    ]);
    (yield 'direct file with icon_id and wildcard after' => [
        [
            '{icon_id}*',
        ],
        [
            [
                'foo',
                'foo.svg',
            ],
        ],
    ]);
    (yield 'direct file with icon_id and wildcard before' => [
        [
            '*{icon_id}',
        ],
        [
            [
                'foo',
                'foo.svg',
            ],
        ],
    ]);
    (yield 'direct file with icon_id and wildcard around' => [
        [
            '*{icon_id}*',
        ],
        [
            [
                'foo',
                'foo.svg',
            ],
        ],
    ]);
    (yield 'direct file with icon_id and wildcard around and prefix' => [
        [
            'f*{icon_id}*',
        ],
        [
            [
                'oo',
                'foo.svg',
            ],
        ],
    ]);
    (yield 'direct file with icon_id and wildcard around and suffix' => [
        [
            '*{icon_id}*o',
        ],
        [
            [
                'fo',
                'foo.svg',
            ],
        ],
    ]);
    (yield 'direct file with icon_id and wildcard around and prefix and suffix' => [
        [
            'f*{icon_id}*o',
        ],
        [
            [
                'o',
                'foo.svg',
            ],
        ],
    ]);
    (yield 'test icon_id extracted' => [
        [
            'icons/prefix_suffix/{icon_id}.svg',
        ],
        [
            [
                'grault',
                'icons/prefix_suffix/grault.svg',
            ],
            [
                'garply_suffix',
                'icons/prefix_suffix/garply_suffix.svg',
            ],
            [
                'prefix_quux',
                'icons/prefix_suffix/prefix_quux.svg',
            ],
            [
                'prefix_corge_suffix',
                'icons/prefix_suffix/prefix_corge_suffix.svg',
            ],
        ],
    ]);
    (yield 'test icon_id extracted prefix' => [
        [
            'icons/prefix_suffix/prefix_{icon_id}.svg',
        ],
        [
            [
                'quux',
                'icons/prefix_suffix/prefix_quux.svg',
            ],
            [
                'corge_suffix',
                'icons/prefix_suffix/prefix_corge_suffix.svg',
            ],
        ],
    ]);
    (yield 'test icon_id extracted suffix' => [
        [
            'icons/prefix_suffix/{icon_id}_suffix.svg',
        ],
        [
            [
                'garply',
                'icons/prefix_suffix/garply_suffix.svg',
            ],
            [
                'prefix_corge',
                'icons/prefix_suffix/prefix_corge_suffix.svg',
            ],
        ],
    ]);
    (yield 'test icon_id extracted both' => [
        [
            'icons/prefix_suffix/prefix_{icon_id}_suffix.svg',
        ],
        [
            [
                'corge',
                'icons/prefix_suffix/prefix_corge_suffix.svg',
            ],
        ],
    ]);
    (yield 'test icon_id extracted with group' => [
        [
            'icons/prefix_suffix/{group}/{icon_id}.svg',
        ],
        [
            [
                'fred_group',
                'icons/prefix_suffix/group/fred_group.svg',
                'group',
            ],
            [
                'plugh_group_suffix',
                'icons/prefix_suffix/group/plugh_group_suffix.svg',
                'group',
            ],
            [
                'prefix_qux_group',
                'icons/prefix_suffix/group/prefix_qux_group.svg',
                'group',
            ],
            [
                'prefix_waldo_group_suffix',
                'icons/prefix_suffix/group/prefix_waldo_group_suffix.svg',
                'group',
            ],
        ],
    ]);
    (yield 'test icon_id extracted with group and wildcard' => [
        [
            'icons/*/{group}/{icon_id}.svg',
        ],
        [
            [
                'corge_group_1',
                'icons/group/group_1/corge_group_1.svg',
                'group_1',
            ],
            [
                'foo_group_1',
                'icons/group/group_1/foo_group_1.svg',
                'group_1',
            ],
            [
                'corge_group_2',
                'icons/group/group_2/corge_group_2.svg',
                'group_2',
            ],
            [
                'foo_group_2',
                'icons/group/group_2/foo_group_2.svg',
                'group_2',
            ],
            [
                'foo',
                'icons/group_same_name/group_3/foo.svg',
                'group_3',
            ],
            [
                'fred_group',
                'icons/prefix_suffix/group/fred_group.svg',
                'group',
            ],
            [
                'plugh_group_suffix',
                'icons/prefix_suffix/group/plugh_group_suffix.svg',
                'group',
            ],
            [
                'prefix_qux_group',
                'icons/prefix_suffix/group/prefix_qux_group.svg',
                'group',
            ],
            [
                'prefix_waldo_group_suffix',
                'icons/prefix_suffix/group/prefix_waldo_group_suffix.svg',
                'group',
            ],
        ],
    ]);
    (yield 'path {icon_id} partial extracted wildcard extension' => [
        [
            'icons/flat_same_name/f{icon_id}o.*',
        ],
        [
            [
                'o',
                'icons/flat_same_name/foo.svg',
            ],
        ],
    ]);
}

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