[TASK] Use name-resolution instead of strings where possible: 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 * 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
17 /**
18 * Test case
19 *
20 * @author Christian Kuhn <lolli@schwarzbu.ch>
21 */
22 class DataSubmissionControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
23
24 ///////////////////////////////
25 // tests concerning __destruct
26 ///////////////////////////////
27
28 /**
29 * Dataprovider for destructorDoesNotRemoveFilesNotWithinTypo3TempDirectory
30 */
31 public function invalidFileReferences() {
32 return array(
33 'not within PATH_site' => array('/tmp/TYPO3-DataSubmissionControllerTest'),
34 'does not start with upload_temp_' => array(PATH_site . 'typo3temp/foo'),
35 'directory traversal' => array(PATH_site . 'typo3temp/../typo3temp/upload_temp_foo'),
36 );
37 }
38
39 /**
40 * @test
41 * @dataProvider invalidFileReferences
42 */
43 public function destructorDoesNotRemoveFilesNotWithinTypo3TempDirectory($file) {
44 if (TYPO3_OS === 'WIN') {
45 $this->markTestSkipped('destructorDoesNotRemoveFilesNotWithinTypo3TempDirectory() test not available on Windows.');
46 }
47
48 // Create test file
49 touch($file);
50 if (!is_file($file)) {
51 $this->markTestSkipped('destructorDoesNotRemoveFilesNotWithinTypo3TempDirectory() skipped: Test file could not be created');
52 }
53
54 $instance = new \TYPO3\CMS\Frontend\Controller\DataSubmissionController(999999999, $lockMethod);
55 $t3libLockReflection = new \ReflectionClass(\TYPO3\CMS\Frontend\Controller\DataSubmissionController::class);
56 $t3libLockReflectionResourceProperty = $t3libLockReflection->getProperty('temporaryFiles');
57 $t3libLockReflectionResourceProperty->setAccessible(TRUE);
58 $t3libLockReflectionResourceProperty->setValue($instance, array($file));
59
60 // Call release method
61 $instance->__destruct();
62
63 // Check if file is still there and clean up
64 $fileExists = is_file($file);
65 if (is_file($file)) {
66 unlink($file);
67 }
68
69 $this->assertTrue($fileExists);
70 }
71 }