[TASK] Raise PHP version requirement to 5.3.7
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Unit / Controller / DataSubmissionControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Tests\Unit\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011-2013 Christian Kuhn <lolli@schwarzbu.ch>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Test case
29 *
30 * @author Christian Kuhn <lolli@schwarzbu.ch>
31 */
32 class DataSubmissionControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
33
34 ///////////////////////////////
35 // tests concerning __destruct
36 ///////////////////////////////
37
38 /**
39 * Dataprovider for destructorDoesNotRemoveFilesNotWithinTypo3TempDirectory
40 */
41 public function invalidFileReferences() {
42 return array(
43 'not within PATH_site' => array('/tmp/TYPO3-DataSubmissionControllerTest'),
44 'does not start with upload_temp_' => array(PATH_site . 'typo3temp/foo'),
45 'directory traversal' => array(PATH_site . 'typo3temp/../typo3temp/upload_temp_foo'),
46 );
47 }
48
49 /**
50 * @test
51 * @dataProvider invalidFileReferences
52 */
53 public function destructorDoesNotRemoveFilesNotWithinTypo3TempDirectory($file) {
54 if (TYPO3_OS === 'WIN') {
55 $this->markTestSkipped('destructorDoesNotRemoveFilesNotWithinTypo3TempDirectory() test not available on Windows.');
56 }
57
58 // Create test file
59 touch($file);
60 if (!is_file($file)) {
61 $this->markTestSkipped('destructorDoesNotRemoveFilesNotWithinTypo3TempDirectory() skipped: Test file could not be created');
62 }
63
64 $instance = new \TYPO3\CMS\Frontend\Controller\DataSubmissionController(999999999, $lockMethod);
65 $t3libLockReflection = new \ReflectionClass('TYPO3\\CMS\\Frontend\\Controller\\DataSubmissionController');
66 $t3libLockReflectionResourceProperty = $t3libLockReflection->getProperty('temporaryFiles');
67 $t3libLockReflectionResourceProperty->setAccessible(TRUE);
68 $t3libLockReflectionResourceProperty->setValue($instance, array($file));
69
70 // Call release method
71 $instance->__destruct();
72
73 // Check if file is still there and clean up
74 $fileExists = is_file($file);
75 if (is_file($file)) {
76 unlink($file);
77 }
78
79 $this->assertTrue($fileExists);
80 }
81 }
82 ?>