‪TYPO3CMS  9.5
FileExtensionFilterTest.php
Go to the documentation of this file.
1 <?php
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 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪FileExtensionFilterTest extends UnitTestCase
27 {
31  protected function ‪tearDown()
32  {
33  GeneralUtility::purgeInstances();
34  parent::tearDown();
35  }
36 
41  {
42  return [
43  [null, null, null],
44  ['', '', [0, '', null, false]],
45  [null, null, [0, '', null, false]]
46  ];
47  }
48 
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 
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 
103  public function ‪extensionFilterIgnoresCaseInAllowedExtensionCheck($fileExtension, $allowedExtensions, $disallowedExtensions, $isAllowed)
104  {
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 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:81
‪TYPO3\CMS\Core\Tests\Unit\Resource\Utility\FileExtensionFilterTest
Definition: FileExtensionFilterTest.php:27
‪TYPO3\CMS\Core\Tests\Unit\Resource\Utility\FileExtensionFilterTest\extensionFilterIgnoresCaseInAllowedExtensionCheckDataProvider
‪array extensionFilterIgnoresCaseInAllowedExtensionCheckDataProvider()
Definition: FileExtensionFilterTest.php:74
‪TYPO3\CMS\Core\Tests\Unit\Resource\Utility\FileExtensionFilterTest\extensionFilterIgnoresCaseInAllowedExtensionCheck
‪extensionFilterIgnoresCaseInAllowedExtensionCheck($fileExtension, $allowedExtensions, $disallowedExtensions, $isAllowed)
Definition: FileExtensionFilterTest.php:103
‪TYPO3\CMS\Core\Tests\Unit\Resource\Utility
Definition: FileExtensionFilterTest.php:2
‪TYPO3\CMS\Core\Tests\Unit\Resource\Utility\FileExtensionFilterTest\areInlineChildrenFilteredWithInvalidParameters
‪areInlineChildrenFilteredWithInvalidParameters($allowed, $disallowed, $values)
Definition: FileExtensionFilterTest.php:56
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:33
‪TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter
Definition: FileExtensionFilter.php:28
‪TYPO3\CMS\Core\Tests\Unit\Resource\Utility\FileExtensionFilterTest\invalidInlineChildrenFilterParametersDataProvider
‪array invalidInlineChildrenFilterParametersDataProvider()
Definition: FileExtensionFilterTest.php:40
‪TYPO3\CMS\Core\Tests\Unit\Resource\Utility\FileExtensionFilterTest\tearDown
‪tearDown()
Definition: FileExtensionFilterTest.php:31
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45