ResourceUtilityTest.php 3.27 KB
Newer Older
1
<?php
2

3
4
declare(strict_types=1);

5
/*
6
 * This file is part of the TYPO3 CMS project.
7
 *
8
9
10
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
11
 *
12
13
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
16
 * The TYPO3 project - inspiring people to share!
 */
17

18
namespace TYPO3\CMS\Core\Tests\UnitDeprecated\Utility;
19

20
use TYPO3\CMS\Core\Utility\ResourceUtility;
21
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22
23
24
25

/**
 * Testcase for class \TYPO3\CMS\Core\Utility\ResourceUtility
 */
26
class ResourceUtilityTest extends UnitTestCase
27
28
29
30
{
    /**
     * @return array
     */
31
    public function recursiveFileListSortingHelperTestDataProvider(): array
32
    {
33
34
35
        return [
            'normal file list' => [
                ['fileB', 'fileA', 'someFile'],
36
                ['fileA', 'fileB', 'someFile'],
37
38
39
            ],
            'already in correct order' => [
                ['fileA', 'fileB', 'someFile'],
40
                ['fileA', 'fileB', 'someFile'],
41
42
43
            ],
            'hidden file' => [
                ['someFile', '.hiddenFile'],
44
                ['.hiddenFile', 'someFile'],
45
46
47
            ],
            'mixed capitalization' => [
                ['alllower', 'allCAPS', 'ALLcaps', 'mIxedinanotherway', 'ALLCAPS', 'MiXeDcApItAlIzAtIoN'],
48
                ['ALLCAPS', 'ALLcaps', 'allCAPS', 'alllower', 'MiXeDcApItAlIzAtIoN', 'mIxedinanotherway'],
49
50
51
            ],
            'mixed capitalization reversed' => [
                ['MiXeDcApItAlIzAtIoN', 'mIxedinanotherway', 'ALLcaps', 'allCAPS', 'ALLCAPS', 'alllower'],
52
                ['ALLCAPS', 'ALLcaps', 'allCAPS', 'alllower', 'MiXeDcApItAlIzAtIoN', 'mIxedinanotherway'],
53
54
55
            ],
            'recursive list with one sublevel' => [
                ['fileA', 'fileB', 'anotherDir/someFile', 'someDir/someFile', 'anotherDir/anotherFile'],
56
                ['anotherDir/anotherFile', 'anotherDir/someFile', 'someDir/someFile', 'fileA', 'fileB'],
57
58
59
            ],
            'recursive list with two sub-levels' => [
                ['file', 'someDir/someFile', 'someDir/subdir/file', 'someDir/subdir/somefile', 'someDir/anotherDir/somefile', 'anotherDir/someFile'],
60
                ['anotherDir/someFile', 'someDir/anotherDir/somefile', 'someDir/subdir/file', 'someDir/subdir/somefile', 'someDir/someFile', 'file'],
61
62
63
            ],
            'recursive list with three sub-levels' => [
                ['someDir/someSubdir/file', 'someDir/someSubdir/someSubsubdir/someFile', 'someDir/someSubdir/someSubsubdir/anotherFile'],
64
65
                ['someDir/someSubdir/someSubsubdir/anotherFile', 'someDir/someSubdir/someSubsubdir/someFile', 'someDir/someSubdir/file'],
            ],
66
        ];
67
    }
68

69
70
71
72
73
74
    /**
     * @dataProvider recursiveFileListSortingHelperTestDataProvider
     * @test
     * @param array $unsortedList
     * @param array $expectedList
     */
75
    public function recursiveFileListSortingHelperCorrectlySorts(array $unsortedList, array $expectedList): void
76
77
78
79
    {
        $result = $unsortedList;
        usort(
            $result,
80
            [ResourceUtility::class, 'recursiveFileListSortingHelper']
81
        );
82
        self::assertSame($expectedList, $result);
83
    }
84
}