TYPO3 CMS  TYPO3_8-7
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 
20 class FileExtensionFilterTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
21 {
25  protected $singletonInstances = [];
26 
30  protected $filter;
31 
35  protected $parameters;
36 
40  protected $dataHandlerMock;
41 
45  protected $fileFactoryMock;
46 
50  protected function setUp()
51  {
53  $this->filter = new \TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter();
54  $this->dataHandlerMock = $this->getMockBuilder(\TYPO3\CMS\Core\DataHandling\DataHandler::class)
55  ->setMethods(['deleteAction'])
56  ->getMock();
57  $this->fileFactoryMock = $this->getMockBuilder(\TYPO3\CMS\Core\Resource\ResourceFactory::class)
58  ->setMethods(['getFileReferenceObject'])
59  ->getMock();
60  \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Resource\ResourceFactory::class, $this->fileFactoryMock);
61  }
62 
66  protected function tearDown()
67  {
69  parent::tearDown();
70  }
71 
76  {
77  return [
78  [null, null, null],
79  ['', '', [0, '', null, false]],
80  [null, null, [0, '', null, false]]
81  ];
82  }
83 
91  public function areInlineChildrenFilteredWithInvalidParameters($allowed, $disallowed, $values)
92  {
93  $this->parameters = [
94  'allowedFileExtensions' => $allowed,
95  'disallowedFileExtensions' => $disallowed,
96  'values' => $values
97  ];
98  $this->dataHandlerMock->expects($this->never())->method('deleteAction');
99  $this->fileFactoryMock->expects($this->never())->method('getFileReferenceObject');
100  $this->filter->filterInlineChildren($this->parameters, $this->dataHandlerMock);
101  }
102 
107  {
108  return [
109  'Allowed extensions' => [
110  'ext1', 'EXT1', '', true
111  ],
112  'Allowed extensions, lower and upper case mix' => [
113  'ext1', 'ext2, ExT1, Ext3', '', true
114  ],
115  'Disallowed extensions' => [
116  'ext1', '', 'EXT1', false
117  ],
118  'Disallowed extensions, lower and upper case mix' => [
119  'ext1', '', 'ext2, ExT1, Ext3', false
120  ],
121  'Combine allowed / disallowed extensions' => [
122  'ext1', 'EXT1', 'EXT1', false
123  ],
124  ];
125  }
126 
135  public function extensionFilterIgnoresCaseInAllowedExtensionCheck($fileExtension, $allowedExtensions, $disallowedExtensions, $isAllowed)
136  {
138  $filter = $this->getAccessibleMock(\TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter::class, ['dummy']);
139  $filter->setAllowedFileExtensions($allowedExtensions);
140  $filter->setDisallowedFileExtensions($disallowedExtensions);
141  $result = $filter->_call('isAllowed', $fileExtension);
142  $this->assertEquals($isAllowed, $result);
143  }
144 }
static setSingletonInstance($className, SingletonInterface $instance)
static resetSingletonInstances(array $newSingletonInstances)