TYPO3 CMS  TYPO3_6-2
FileExtensionFilterTest.php
Go to the documentation of this file.
1 <?php
3 
23 
27  protected $singletonInstances = array();
28 
32  protected $filter;
33 
37  protected $parameters;
38 
42  protected $tceMainMock;
43 
47  protected $fileFactoryMock;
48 
52  protected function setUp() {
54  $this->filter = new \TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter();
55  $this->tceMainMock = $this->getMock('TYPO3\\CMS\\Core\\DataHandling\\DataHandler', array('deleteAction'), array());
56  $this->fileFactoryMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', array('getFileReferenceObject'), array());
57  \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', $this->fileFactoryMock);
58  }
59 
63  protected function tearDown() {
65  parent::tearDown();
66  }
67 
72  return array(
73  array(NULL, NULL, NULL),
74  array('', '', array(0, '', NULL, FALSE)),
75  array(NULL, NULL, array(0, '', NULL, FALSE))
76  );
77  }
78 
86  public function areInlineChildrenFilteredWithInvalidParameters($allowed, $disallowed, $values) {
87  $this->parameters = array(
88  'allowedFileExtensions' => $allowed,
89  'disallowedFileExtensions' => $disallowed,
90  'values' => $values
91  );
92  $this->tceMainMock->expects($this->never())->method('deleteAction');
93  $this->fileFactoryMock->expects($this->never())->method('getFileReferenceObject');
94  $this->filter->filterInlineChildren($this->parameters, $this->tceMainMock);
95  }
96 
101  return array(
102  'Allowed extensions' => array(
103  'ext1', 'EXT1', '', TRUE
104  ),
105  'Allowed extensions, lower and upper case mix' => array(
106  'ext1', 'ext2, ExT1, Ext3', '', TRUE
107  ),
108  'Disallowed extensions' => array(
109  'ext1', '', 'EXT1', FALSE
110  ),
111  'Disallowed extensions, lower and upper case mix' => array(
112  'ext1', '', 'ext2, ExT1, Ext3', FALSE
113  ),
114  'Combine allowed / disallowed extensions' => array(
115  'ext1', 'EXT1', 'EXT1', FALSE
116  ),
117  );
118  }
119 
128  public function extensionFilterIgnoresCaseInAllowedExtensionCheck($fileExtension, $allowedExtensions, $disallowedExtensions, $isAllowed) {
130  $filter = $this->getAccessibleMock('\TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter', array('dummy'));
131  $filter->setAllowedFileExtensions($allowedExtensions);
132  $filter->setDisallowedFileExtensions($disallowedExtensions);
133  $result = $filter->_call('isAllowed', 'file.' . $fileExtension);
134  $this->assertEquals($isAllowed, $result);
135  }
136 }
static setSingletonInstance($className, \TYPO3\CMS\Core\SingletonInterface $instance)
static resetSingletonInstances(array $newSingletonInstances)
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.