‪TYPO3CMS  11.5
FileExtensionFilterTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Prophecy\PhpUnit\ProphecyTrait;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
30 class ‪FileExtensionFilterTest extends UnitTestCase
31 {
32  use ProphecyTrait;
33 
37  protected function ‪tearDown(): void
38  {
39  GeneralUtility::purgeInstances();
40  parent::tearDown();
41  }
42 
47  {
48  return [
49  [null, null, null],
50  ['', '', [0, '', null, false]],
51  [null, null, [0, '', null, false]],
52  ];
53  }
54 
62  public function ‪areInlineChildrenFilteredWithInvalidParameters($allowed, $disallowed, $values): void
63  {
64  $parameters = [
65  'allowedFileExtensions' => $allowed,
66  'disallowedFileExtensions' => $disallowed,
67  'values' => $values,
68  ];
69  $dataHandlerProphecy = $this->prophesize(DataHandler::class);
70  $dataHandlerProphecy->deleteAction()->shouldNotBeCalled();
71  $resourceFactoryProphecy = $this->prophesize(ResourceFactory::class);
72  $resourceFactoryProphecy->getFileReferenceObject()->shouldNotBeCalled();
73  GeneralUtility::setSingletonInstance(ResourceFactory::class, $resourceFactoryProphecy->reveal());
74  (new ‪FileExtensionFilter())->filterInlineChildren($parameters, $dataHandlerProphecy->reveal());
75  }
76 
81  {
82  return [
83  'Allowed extensions' => [
84  'ext1', 'EXT1', '', true,
85  ],
86  'Allowed extensions, lower and upper case mix' => [
87  'ext1', 'ext2, ExT1, Ext3', '', true,
88  ],
89  'Disallowed extensions' => [
90  'ext1', '', 'EXT1', false,
91  ],
92  'Disallowed extensions, lower and upper case mix' => [
93  'ext1', '', 'ext2, ExT1, Ext3', false,
94  ],
95  'Combine allowed / disallowed extensions' => [
96  'ext1', 'EXT1', 'EXT1', false,
97  ],
98  ];
99  }
100 
109  public function ‪extensionFilterIgnoresCaseInAllowedExtensionCheck($fileExtension, $allowedExtensions, $disallowedExtensions, $isAllowed): void
110  {
111  $filter = $this->getAccessibleMock(FileExtensionFilter::class, ['dummy']);
112  $filter->setAllowedFileExtensions($allowedExtensions);
113  $filter->setDisallowedFileExtensions($disallowedExtensions);
114  $result = $filter->_call('isAllowed', $fileExtension);
115  self::assertEquals($isAllowed, $result);
116  }
117 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:86
‪TYPO3\CMS\Core\Tests\Unit\Resource\Utility\FileExtensionFilterTest
Definition: FileExtensionFilterTest.php:31
‪TYPO3\CMS\Core\Tests\Unit\Resource\Utility\FileExtensionFilterTest\extensionFilterIgnoresCaseInAllowedExtensionCheckDataProvider
‪array extensionFilterIgnoresCaseInAllowedExtensionCheckDataProvider()
Definition: FileExtensionFilterTest.php:79
‪TYPO3\CMS\Core\Tests\Unit\Resource\Utility\FileExtensionFilterTest\extensionFilterIgnoresCaseInAllowedExtensionCheck
‪extensionFilterIgnoresCaseInAllowedExtensionCheck($fileExtension, $allowedExtensions, $disallowedExtensions, $isAllowed)
Definition: FileExtensionFilterTest.php:108
‪TYPO3\CMS\Core\Tests\Unit\Resource\Utility
Definition: FileExtensionFilterTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Resource\Utility\FileExtensionFilterTest\areInlineChildrenFilteredWithInvalidParameters
‪areInlineChildrenFilteredWithInvalidParameters($allowed, $disallowed, $values)
Definition: FileExtensionFilterTest.php:61
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter
Definition: FileExtensionFilter.php:28
‪TYPO3\CMS\Core\Tests\Unit\Resource\Utility\FileExtensionFilterTest\invalidInlineChildrenFilterParametersDataProvider
‪array invalidInlineChildrenFilterParametersDataProvider()
Definition: FileExtensionFilterTest.php:45
‪TYPO3\CMS\Core\Tests\Unit\Resource\Utility\FileExtensionFilterTest\tearDown
‪tearDown()
Definition: FileExtensionFilterTest.php:36
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50