[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Resource / Filter / FileNameFilterTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Resource\Filter;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 use TYPO3\CMS\Core\Resource\Driver\DriverInterface;
17 use TYPO3\CMS\Core\Resource\Filter\FileNameFilter;
18
19 /**
20 * Testcase for the filename filter of the TYPO3 VFS
21 */
22 class FileNameFilterTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTestCase
23 {
24 /**
25 * Return combinations of files and paths to test against.
26 *
27 * @return array
28 */
29 public function getItemsAndPathsWithoutHiddenFilesAndFolders_dataProvider()
30 {
31 return [
32 ['file', '/file', true],
33 ['.htaccess', '/.htaccess', -1],
34 ['applypatch-msg.sample', '/.git/applypatch-msg.sample', -1],
35 ['applypatch-msg.sample', '/user_upload/.git/applypatch-msg.sample', -1],
36 ];
37 }
38
39 /**
40 * Return combinations of files and paths to test against.
41 *
42 * @return array
43 */
44 public function getItemsAndPathsWithHiddenFilesAndFolders_dataProvider()
45 {
46 return [
47 ['file', '/file', true],
48 ['.htaccess', '/.htaccess', true],
49 ['applypatch-msg.sample', '/.git/applypatch-msg.sample', true],
50 ['applypatch-msg.sample', '/user_upload/.git/applypatch-msg.sample', true],
51 ];
52 }
53
54 /**
55 * @test
56 * @dataProvider getItemsAndPathsWithoutHiddenFilesAndFolders_dataProvider
57 * @param string $itemName
58 * @param string $itemIdentifier
59 * @param bool|int $expected
60 */
61 public function filterHiddenFilesAndFoldersFiltersHiddenFilesAndFolders($itemName, $itemIdentifier, $expected)
62 {
63 /** @var DriverInterface|\PHPUnit_Framework_MockObject_MockObject $driverMock */
64 $driverMock = $this->createMock(DriverInterface::class);
65 $this->assertSame(
66 $expected,
67 FileNameFilter::filterHiddenFilesAndFolders(
68 $itemName, $itemIdentifier, '', [], $driverMock
69 )
70 );
71 }
72
73 /**
74 * @test
75 * @dataProvider getItemsAndPathsWithHiddenFilesAndFolders_dataProvider
76 * @param string $itemName
77 * @param string $itemIdentifier
78 * @param bool|int $expected
79 */
80 public function filterHiddenFilesAndFoldersAllowsHiddenFilesAndFolders($itemName, $itemIdentifier, $expected)
81 {
82 /** @var DriverInterface|\PHPUnit_Framework_MockObject_MockObject $driverMock */
83 $driverMock = $this->createMock(DriverInterface::class);
84 FileNameFilter::setShowHiddenFilesAndFolders(true);
85 $this->assertSame(
86 FileNameFilter::filterHiddenFilesAndFolders(
87 $itemName, $itemIdentifier, '', [], $driverMock
88 ),
89 $expected
90 );
91 }
92 }