[TASK] Remove last mentions of t3lib_formmail
[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 // Reflection needs php 5.3.2 or above
58 if (version_compare(phpversion(), '5.3.2', '<')) {
59 $this->markTestSkipped('destructorDoesNotRemoveFilesNotWithinTypo3TempDirectory() test not available with php version smaller than 5.3.2');
60 }
61
62 // Create test file
63 touch($file);
64 if (!is_file($file)) {
65 $this->markTestSkipped('destructorDoesNotRemoveFilesNotWithinTypo3TempDirectory() skipped: Test file could not be created');
66 }
67
68 $instance = new \TYPO3\CMS\Frontend\Controller\DataSubmissionController(999999999, $lockMethod);
69 $t3libLockReflection = new \ReflectionClass('TYPO3\\CMS\\Frontend\\Controller\\DataSubmissionController');
70 $t3libLockReflectionResourceProperty = $t3libLockReflection->getProperty('temporaryFiles');
71 $t3libLockReflectionResourceProperty->setAccessible(TRUE);
72 $t3libLockReflectionResourceProperty->setValue($instance, array($file));
73
74 // Call release method
75 $instance->__destruct();
76
77 // Check if file is still there and clean up
78 $fileExists = is_file($file);
79 if (is_file($file)) {
80 unlink($file);
81 }
82
83 $this->assertTrue($fileExists);
84 }
85 }
86 ?>