‪TYPO3CMS  10.4
FileExtensionFilterTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪FileExtensionFilterTest extends UnitTestCase
28 {
32  protected function ‪tearDown(): void
33  {
34  GeneralUtility::purgeInstances();
35  parent::tearDown();
36  }
37 
42  {
43  return [
44  [null, null, null],
45  ['', '', [0, '', null, false]],
46  [null, null, [0, '', null, false]]
47  ];
48  }
49 
57  public function ‪areInlineChildrenFilteredWithInvalidParameters($allowed, $disallowed, $values)
58  {
59  $parameters = [
60  'allowedFileExtensions' => $allowed,
61  'disallowedFileExtensions' => $disallowed,
62  'values' => $values
63  ];
64  $dataHandlerProphecy = $this->prophesize(DataHandler::class);
65  $dataHandlerProphecy->deleteAction()->shouldNotBeCalled();
66  $resourceFactoryProphecy = $this->prophesize(ResourceFactory::class);
67  $resourceFactoryProphecy->getFileReferenceObject()->shouldNotBeCalled();
68  GeneralUtility::setSingletonInstance(ResourceFactory::class, $resourceFactoryProphecy->reveal());
69  (new ‪FileExtensionFilter())->filterInlineChildren($parameters, $dataHandlerProphecy->reveal());
70  }
71 
76  {
77  return [
78  'Allowed extensions' => [
79  'ext1', 'EXT1', '', true
80  ],
81  'Allowed extensions, lower and upper case mix' => [
82  'ext1', 'ext2, ExT1, Ext3', '', true
83  ],
84  'Disallowed extensions' => [
85  'ext1', '', 'EXT1', false
86  ],
87  'Disallowed extensions, lower and upper case mix' => [
88  'ext1', '', 'ext2, ExT1, Ext3', false
89  ],
90  'Combine allowed / disallowed extensions' => [
91  'ext1', 'EXT1', 'EXT1', false
92  ],
93  ];
94  }
95 
104  public function ‪extensionFilterIgnoresCaseInAllowedExtensionCheck($fileExtension, $allowedExtensions, $disallowedExtensions, $isAllowed)
105  {
107  $filter = $this->getAccessibleMock(FileExtensionFilter::class, ['dummy']);
108  $filter->setAllowedFileExtensions($allowedExtensions);
109  $filter->setDisallowedFileExtensions($disallowedExtensions);
110  $result = $filter->_call('isAllowed', $fileExtension);
111  self::assertEquals($isAllowed, $result);
112  }
113 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:84
‪TYPO3\CMS\Core\Tests\Unit\Resource\Utility\FileExtensionFilterTest
Definition: FileExtensionFilterTest.php:28
‪TYPO3\CMS\Core\Tests\Unit\Resource\Utility\FileExtensionFilterTest\extensionFilterIgnoresCaseInAllowedExtensionCheckDataProvider
‪array extensionFilterIgnoresCaseInAllowedExtensionCheckDataProvider()
Definition: FileExtensionFilterTest.php:75
‪TYPO3\CMS\Core\Tests\Unit\Resource\Utility\FileExtensionFilterTest\extensionFilterIgnoresCaseInAllowedExtensionCheck
‪extensionFilterIgnoresCaseInAllowedExtensionCheck($fileExtension, $allowedExtensions, $disallowedExtensions, $isAllowed)
Definition: FileExtensionFilterTest.php:104
‪TYPO3\CMS\Core\Tests\Unit\Resource\Utility
Definition: FileExtensionFilterTest.php:16
‪TYPO3\CMS\Core\Tests\Unit\Resource\Utility\FileExtensionFilterTest\areInlineChildrenFilteredWithInvalidParameters
‪areInlineChildrenFilteredWithInvalidParameters($allowed, $disallowed, $values)
Definition: FileExtensionFilterTest.php:57
‪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:41
‪TYPO3\CMS\Core\Tests\Unit\Resource\Utility\FileExtensionFilterTest\tearDown
‪tearDown()
Definition: FileExtensionFilterTest.php:32
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46