[TASK] Clean up comments about deprecation
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Resource / Utility / FileExtensionFilterTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Resource\Utility;
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
17 use TYPO3\CMS\Core\DataHandling\DataHandler;
18 use TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter;
19 use TYPO3\CMS\Core\Resource\ResourceFactory;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22
23 /**
24 * Test suite for filtering files by their extensions.
25 */
26 class FileExtensionFilterTest extends UnitTestCase
27 {
28 /**
29 * Cleans up this test suite.
30 */
31 protected function tearDown(): void
32 {
33 GeneralUtility::purgeInstances();
34 parent::tearDown();
35 }
36
37 /**
38 * @return array
39 */
40 public function invalidInlineChildrenFilterParametersDataProvider()
41 {
42 return [
43 [null, null, null],
44 ['', '', [0, '', null, false]],
45 [null, null, [0, '', null, false]]
46 ];
47 }
48
49 /**
50 * @param array|string $allowed
51 * @param array|string $disallowed
52 * @param array|string $values
53 * @test
54 * @dataProvider invalidInlineChildrenFilterParametersDataProvider
55 */
56 public function areInlineChildrenFilteredWithInvalidParameters($allowed, $disallowed, $values)
57 {
58 $parameters = [
59 'allowedFileExtensions' => $allowed,
60 'disallowedFileExtensions' => $disallowed,
61 'values' => $values
62 ];
63 $dataHandlerProphecy = $this->prophesize(DataHandler::class);
64 $dataHandlerProphecy->deleteAction()->shouldNotBeCalled();
65 $resourceFactoryProphecy = $this->prophesize(ResourceFactory::class);
66 $resourceFactoryProphecy->getFileReferenceObject()->shouldNotBeCalled();
67 GeneralUtility::setSingletonInstance(ResourceFactory::class, $resourceFactoryProphecy->reveal());
68 (new FileExtensionFilter())->filterInlineChildren($parameters, $dataHandlerProphecy->reveal());
69 }
70
71 /**
72 * @return array
73 */
74 public function extensionFilterIgnoresCaseInAllowedExtensionCheckDataProvider()
75 {
76 return [
77 'Allowed extensions' => [
78 'ext1', 'EXT1', '', true
79 ],
80 'Allowed extensions, lower and upper case mix' => [
81 'ext1', 'ext2, ExT1, Ext3', '', true
82 ],
83 'Disallowed extensions' => [
84 'ext1', '', 'EXT1', false
85 ],
86 'Disallowed extensions, lower and upper case mix' => [
87 'ext1', '', 'ext2, ExT1, Ext3', false
88 ],
89 'Combine allowed / disallowed extensions' => [
90 'ext1', 'EXT1', 'EXT1', false
91 ],
92 ];
93 }
94
95 /**
96 * @param string $fileExtension
97 * @param array|string $allowedExtensions
98 * @param array|string $disallowedExtensions
99 * @param bool $isAllowed
100 * @test
101 * @dataProvider extensionFilterIgnoresCaseInAllowedExtensionCheckDataProvider
102 */
103 public function extensionFilterIgnoresCaseInAllowedExtensionCheck($fileExtension, $allowedExtensions, $disallowedExtensions, $isAllowed)
104 {
105 /** @var FileExtensionFilter $filter */
106 $filter = $this->getAccessibleMock(FileExtensionFilter::class, ['dummy']);
107 $filter->setAllowedFileExtensions($allowedExtensions);
108 $filter->setDisallowedFileExtensions($disallowedExtensions);
109 $result = $filter->_call('isAllowed', $fileExtension);
110 $this->assertEquals($isAllowed, $result);
111 }
112 }