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