From c80f4fb242cd7f34f502a9f7999ce07263a075de Mon Sep 17 00:00:00 2001 From: Anja Leichsenring <aleichsenring@ab-softlab.de> Date: Sat, 5 Jul 2014 18:58:34 +0200 Subject: [PATCH] [CLEANUP] Move test file deletion into UnitTestCase class In order to unify removal of files and directories created by unit tests, the basic UnitTestCase class get a property to register created files and directories. Removing those files is implemented in tearDown(). Tests now just need to add created files to $this->testFilesToDelete to get the automatically cleaned up after test run. The method is constructed to only remove stuff within typo3conf/ext and typo3temp to reduce the risk of removing too, it throws an exception if this rule is not followed. Change-Id: Ibca2b3a006432f2335fff8f0b0c05c62e363878c Resolves: #60123 Releases: 6.3 Reviewed-on: http://review.typo3.org/31359 Reviewed-by: Helmut Hummel <helmut.hummel@typo3.org> Tested-by: Helmut Hummel <helmut.hummel@typo3.org> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> --- .../Tests/Unit/Utility/IconUtilityTest.php | 2 +- .../core/Classes/Utility/GeneralUtility.php | 2 +- ...ure-60123-UnitTestCaseRemovesTestFiles.rst | 17 ++++++ .../ConfigurationManagerTest.php | 17 +----- .../Unit/Resource/Driver/LocalDriverTest.php | 1 + .../Unit/TypoScript/TemplateServiceTest.php | 7 --- .../ExtensionManagementUtilityTest.php | 19 +----- .../Tests/Unit/Utility/GeneralUtilityTest.php | 34 ++++++----- typo3/sysext/core/Tests/UnitTestCase.php | 37 +++++++++++ .../Unit/Database/DatabaseConnectionTest.php | 18 +----- .../Unit/Utility/FileHandlingUtilityTest.php | 61 ++++++++----------- .../Tests/Unit/Utility/InstallUtilityTest.php | 4 +- .../indexed_search/Tests/Unit/IndexerTest.php | 24 ++------ .../Unit/FolderStructure/AbstractNodeTest.php | 31 +++------- .../FolderStructure/DirectoryNodeTest.php | 39 ++++-------- .../Unit/FolderStructure/FileNodeTest.php | 57 ++++++----------- .../Unit/FolderStructure/LinkNodeTest.php | 25 ++------ .../Unit/FolderStructure/RootNodeTest.php | 21 +------ 18 files changed, 154 insertions(+), 262 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Feature-60123-UnitTestCaseRemovesTestFiles.rst diff --git a/typo3/sysext/backend/Tests/Unit/Utility/IconUtilityTest.php b/typo3/sysext/backend/Tests/Unit/Utility/IconUtilityTest.php index 868e39e5af43..369b353b6b8f 100644 --- a/typo3/sysext/backend/Tests/Unit/Utility/IconUtilityTest.php +++ b/typo3/sysext/backend/Tests/Unit/Utility/IconUtilityTest.php @@ -110,12 +110,12 @@ class IconUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { // Create image resource, determine target filename, fake target permission, run method and clean up $fixtureGifRessource = imagecreatefromgif($fixtureGifFile); $targetFilename = PATH_site . 'typo3temp/' . uniqid('test_') . '.gif'; + $this->testFilesToDelete[] = $targetFilename; $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777'; $subject = $this->subject; $subject::imagemake($fixtureGifRessource, $targetFilename); clearstatcache(); $resultFilePermissions = substr(decoct(fileperms($targetFilename)), 2); - \TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile($targetFilename); $this->assertEquals($resultFilePermissions, '0777'); } diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php index c43f6737c3ba..f2425a087e52 100644 --- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php +++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php @@ -5094,7 +5094,7 @@ Connection: close require_once ExtensionManagementUtility::extPath('core') . 'Classes/Locking/Locker.php'; } // Write a longer message to the deprecation log - $destination = self::getDeprecationLogFileName(); + $destination = static::getDeprecationLogFileName(); $file = @fopen($destination, 'a'); if ($file) { @fwrite($file, ($date . $msg . LF)); diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-60123-UnitTestCaseRemovesTestFiles.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-60123-UnitTestCaseRemovesTestFiles.rst new file mode 100644 index 000000000000..6c597c59d3fd --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Feature-60123-UnitTestCaseRemovesTestFiles.rst @@ -0,0 +1,17 @@ +======================================================== +Feature: #60123 - Unit base test case removes test files +======================================================== + +Description +=========== + +Some unit tests need to create test files or directories to check the system +under test. Those files should be removed again. +A test can now register absolute file paths in $this->testFilesToDelete, and +the generic tearDown() method will then remove them. Only files, links and directories +within typo3temp/ are allowed. + +Impact +====== + +This allows tests to clean up the environment without leaving obsolete test files behind. \ No newline at end of file diff --git a/typo3/sysext/core/Tests/Unit/Configuration/ConfigurationManagerTest.php b/typo3/sysext/core/Tests/Unit/Configuration/ConfigurationManagerTest.php index 3c4ae26e0b63..db9d2d8a28b1 100644 --- a/typo3/sysext/core/Tests/Unit/Configuration/ConfigurationManagerTest.php +++ b/typo3/sysext/core/Tests/Unit/Configuration/ConfigurationManagerTest.php @@ -21,12 +21,6 @@ namespace TYPO3\CMS\Core\Tests\Unit\Configuration; */ class ConfigurationManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { - /** - * Absolute path to files that must be removed - * after a test - handled in tearDown - */ - protected $testFilesToDelete = array(); - /** * @var \TYPO3\CMS\Core\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject */ @@ -41,16 +35,6 @@ class ConfigurationManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { ); } - /** - * Tear down test case - */ - public function tearDown() { - foreach ($this->testFilesToDelete as $absoluteFileName) { - \TYPO3\CMS\Core\Utility\GeneralUtility::unlink_tempfile($absoluteFileName); - } - parent::tearDown(); - } - /** * @param array $methods */ @@ -446,6 +430,7 @@ class ConfigurationManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $result = $fixture->canWriteConfiguration(); $this->assertTrue($result); + $this->testFilesToDelete[] = $absoluteDirectory; } /** diff --git a/typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php b/typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php index dcd90bcbe02c..99a3c1da05da 100644 --- a/typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php +++ b/typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php @@ -794,6 +794,7 @@ class LocalDriverTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase { )); $fixture = $this->createDriverFixture(); $filePath = GeneralUtility::fixWindowsFilePath($fixture->_call('copyFileToTemporaryPath', '/someDir/someFile')); + $this->testFilesToDelete[] = $filePath; $this->assertContains('/typo3temp/', $filePath); $this->assertEquals($fileContents, file_get_contents($filePath)); } diff --git a/typo3/sysext/core/Tests/Unit/TypoScript/TemplateServiceTest.php b/typo3/sysext/core/Tests/Unit/TypoScript/TemplateServiceTest.php index a8bc9cee357e..226d0905e655 100644 --- a/typo3/sysext/core/Tests/Unit/TypoScript/TemplateServiceTest.php +++ b/typo3/sysext/core/Tests/Unit/TypoScript/TemplateServiceTest.php @@ -23,13 +23,6 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; */ class TemplateServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { - /** - * Enable backup of global and system variables - * - * @var boolean - */ - protected $backupGlobals = TRUE; - /** * @var \TYPO3\CMS\Core\TypoScript\TemplateService */ diff --git a/typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php b/typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php index faa2684937c4..5ded17dc92a1 100644 --- a/typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php +++ b/typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php @@ -30,14 +30,6 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase */ protected $singletonInstances = array(); - /** - * Absolute path to files that must be removed - * after a test - handled in tearDown - * - * @TODO : Check if the tests can use vfs:// instead - */ - protected $testFilesToDelete = array(); - /** * @var \TYPO3\CMS\Core\Package\PackageManager */ @@ -46,19 +38,12 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase public function setUp() { $this->singletonInstances = GeneralUtility::getSingletonInstances(); $this->createAccessibleProxyClass(); - $this->testFilesToDelete = array(); $this->backUpPackageManager = ExtensionManagementUtilityAccessibleProxy::getPackageManager(); $this->singletonInstances = GeneralUtility::getSingletonInstances(); } public function tearDown() { ExtensionManagementUtility::clearExtensionKeyMap(); - foreach ($this->testFilesToDelete as $absoluteFileName) { - GeneralUtility::unlink_tempfile($absoluteFileName); - } - if (file_exists(PATH_site . 'typo3temp/test_ext/')) { - GeneralUtility::rmdir(PATH_site . 'typo3temp/test_ext/', TRUE); - } ExtensionManagementUtilityAccessibleProxy::setPackageManager($this->backUpPackageManager); ExtensionManagementUtilityAccessibleProxy::setCacheManager(NULL); $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($this->backUpPackageManager); @@ -127,8 +112,9 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase * @return object */ protected function createMockPackageManagerWithMockPackage($packageKey, $packageMethods = array('getPackagePath', 'getPackageKey')) { - $packagePath = PATH_site . 'typo3temp/test_ext/' . $packageKey . '/'; + $packagePath = PATH_site . 'typo3temp/' . $packageKey . '/'; GeneralUtility::mkdir_deep($packagePath); + $this->testFilesToDelete[] = $packagePath; $package = $this->getMockBuilder('TYPO3\\CMS\\Core\\Package\\Package') ->disableOriginalConstructor() ->setMethods($packageMethods) @@ -859,7 +845,6 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase $extensionName = uniqid('foo'); $packageManager = $this->createMockPackageManagerWithMockPackage($extensionName); $extLocalconfLocation = $packageManager->getPackage($extensionName)->getPackagePath() . 'ext_localconf.php'; - $this->testFilesToDelete[] = $extLocalconfLocation; $uniqueStringInLocalconf = uniqid('foo'); file_put_contents($extLocalconfLocation, "<?php\n\n" . $uniqueStringInLocalconf . "\n\n?>"); $GLOBALS['TYPO3_LOADED_EXT'] = new \TYPO3\CMS\Core\Compatibility\LoadedExtensionsArray($packageManager); diff --git a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php index 2e2e38495023..f89c4d4f62fa 100644 --- a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php +++ b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php @@ -28,11 +28,6 @@ use \org\bovigo\vfs\vfsStreamWrapper; */ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { - /** - * @var array Files, directories and links to be deleted after a test - */ - protected $testFilesToDelete = array(); - /** * @var array A backup of registered singleton instances */ @@ -47,9 +42,6 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { public function tearDown() { Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances); - foreach ($this->testFilesToDelete as $absoluteFileName) { - Utility\GeneralUtility::rmdir($absoluteFileName, TRUE); - } parent::tearDown(); } @@ -2947,13 +2939,13 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { } // Create and prepare test file $filename = PATH_site . 'typo3temp/../typo3temp/' . uniqid('test_'); - $this->testFilesToDelete[] = $filename; touch($filename); chmod($filename, 482); // Set target permissions and run method $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0660'; $fixPermissionsResult = Utility\GeneralUtility::fixPermissions($filename); clearstatcache(); + $this->testFilesToDelete[] = $filename; $this->assertFalse($fixPermissionsResult); } @@ -4288,16 +4280,26 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { if (TYPO3_OS == 'WIN') { $this->markTestSkipped('deprecationLogFixesPermissionsOnLogFile() test not available on Windows.'); } - // Fake all required settings and get an unique logfilename - $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = uniqid('test_'); - $deprecationLogFilename = Utility\GeneralUtility::getDeprecationLogFileName(); + // Create extending class and let getDeprecationLogFileName return something within typo3temp/ + $className = uniqid('GeneralUtility'); + /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Utility\GeneralUtility $subject */ + $subject = __NAMESPACE__ . '\\' . $className; + eval( + 'namespace ' . __NAMESPACE__ . ';' . + 'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Utility\\GeneralUtility {' . + ' static public function getDeprecationLogFileName() {' . + ' return PATH_site . \'typo3temp/test_deprecation/test.log\';' . + ' }' . + '}' + ); + $filePath = PATH_site . 'typo3temp/test_deprecation/'; + @mkdir($filePath); + $this->testFilesToDelete[] = $filePath; $GLOBALS['TYPO3_CONF_VARS']['SYS']['enableDeprecationLog'] = TRUE; $GLOBALS['TYPO3_CONF_VARS']['BE']['fileCreateMask'] = '0777'; - // Call method, get actual permissions and clean up - Utility\GeneralUtility::deprecationLog('foo'); - $this->testFilesToDelete[] = $deprecationLogFilename; + $subject::deprecationLog('foo'); clearstatcache(); - $resultFilePermissions = substr(decoct(fileperms($deprecationLogFilename)), 2); + $resultFilePermissions = substr(decoct(fileperms($filePath . 'test.log')), 2); $this->assertEquals('0777', $resultFilePermissions); } diff --git a/typo3/sysext/core/Tests/UnitTestCase.php b/typo3/sysext/core/Tests/UnitTestCase.php index d65f144769f8..d5321e00bca7 100644 --- a/typo3/sysext/core/Tests/UnitTestCase.php +++ b/typo3/sysext/core/Tests/UnitTestCase.php @@ -13,6 +13,9 @@ namespace TYPO3\CMS\Core\Tests; * * The TYPO3 project - inspiring people to share! */ +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\PathUtility; +use TYPO3\CMS\Core\Utility\StringUtility; /** * Base test case for unit tests. @@ -32,6 +35,15 @@ abstract class UnitTestCase extends BaseTestCase { */ protected $backupGlobalsBlacklist = array('TYPO3_LOADED_EXT'); + /** + * Absolute path to files that should be removed after a test. + * Handled in tearDown. Tests can register here to get any files + * within typo3temp/ or typo3conf/ext cleaned up again. + * + * @var array + */ + protected $testFilesToDelete = array(); + /** * Unset all additional properties of test classes to help PHP * garbage collection. This reduces memory footprint with lots @@ -41,9 +53,11 @@ abstract class UnitTestCase extends BaseTestCase { * parent::tearDown() at the end. Unsetting of own properties * is not needed this way. * + * @throws \RuntimeException * @return void */ protected function tearDown() { + // Unset properties of test classes to safe memory $reflection = new \ReflectionObject($this); foreach ($reflection->getProperties() as $property) { $declaringClass = $property->getDeclaringClass()->getName(); @@ -58,5 +72,28 @@ abstract class UnitTestCase extends BaseTestCase { } } unset($reflection); + + // Delete registered test files and directories + foreach ($this->testFilesToDelete as $absoluteFileName) { + $absoluteFileName = GeneralUtility::fixWindowsFilePath(PathUtility::getCanonicalPath($absoluteFileName)); + if (!GeneralUtility::validPathStr($absoluteFileName)) { + throw new \RuntimeException('tearDown() cleanup: Filename contains illegal characters', 1410633087); + } + if (!StringUtility::beginsWith($absoluteFileName, PATH_site . 'typo3temp/')) { + throw new \RuntimeException( + 'tearDown() cleanup: Files to delete must be within typo3temp/', + 1410633412 + ); + } + // file_exists returns false for links pointing to not existing targets, so handle links before next check. + if (@is_link($absoluteFileName) || @is_file($absoluteFileName)) { + unlink($absoluteFileName); + } elseif(@is_dir($absoluteFileName)) { + GeneralUtility::rmdir($absoluteFileName, TRUE); + } else { + throw new \RuntimeException('tearDown() cleanup: File, link or directory does not exist', 1410633510); + } + } + $this->testFilesToDelete = array(); } } diff --git a/typo3/sysext/dbal/Tests/Unit/Database/DatabaseConnectionTest.php b/typo3/sysext/dbal/Tests/Unit/Database/DatabaseConnectionTest.php index d5171d522834..751c222edec0 100644 --- a/typo3/sysext/dbal/Tests/Unit/Database/DatabaseConnectionTest.php +++ b/typo3/sysext/dbal/Tests/Unit/Database/DatabaseConnectionTest.php @@ -26,11 +26,6 @@ class DatabaseConnectionTest extends AbstractTestCase { */ protected $subject; - /** - * @var array - */ - protected $temporaryFiles = array(); - /** * Set up */ @@ -60,17 +55,6 @@ class DatabaseConnectionTest extends AbstractTestCase { $this->subject = $subject; } - /** - * Tear down. - */ - public function tearDown() { - // Delete temporary files - foreach ($this->temporaryFiles as $filename) { - unlink($filename); - } - parent::tearDown(); - } - /** * Creates a fake extension with a given table definition. * @@ -84,7 +68,7 @@ class DatabaseConnectionTest extends AbstractTestCase { if (!GeneralUtility::writeFile($ext_tables, $tableDefinition)) { throw new \RuntimeException('Can\'t write temporary ext_tables file.'); } - $this->temporaryFiles[] = $ext_tables; + $this->testFilesToDelete[] = $ext_tables; $GLOBALS['TYPO3_LOADED_EXT'] = array( 'test_dbal' => array( 'ext_tables.sql' => $ext_tables diff --git a/typo3/sysext/extensionmanager/Tests/Unit/Utility/FileHandlingUtilityTest.php b/typo3/sysext/extensionmanager/Tests/Unit/Utility/FileHandlingUtilityTest.php index 8fdd0dde67ba..b54ab3e827ff 100644 --- a/typo3/sysext/extensionmanager/Tests/Unit/Utility/FileHandlingUtilityTest.php +++ b/typo3/sysext/extensionmanager/Tests/Unit/Utility/FileHandlingUtilityTest.php @@ -25,28 +25,6 @@ class FileHandlingUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { */ protected $fakedExtensions = array(); - /** - * @var array List of resources (files or empty directories) that need to be removed in tearDown() again - */ - protected $resourcesToRemove = array(); - - /** - * @return void - */ - public function tearDown() { - foreach ($this->fakedExtensions as $extension => $dummy) { - \TYPO3\CMS\Core\Utility\GeneralUtility::rmdir(PATH_site . 'typo3conf/ext/' . $extension, TRUE); - } - foreach ($this->resourcesToRemove as $resource) { - if (file_exists($resource) && is_file($resource)) { - unlink($resource); - } elseif(file_exists($resource) && is_dir($resource)) { - rmdir($resource); - } - } - parent::tearDown(); - } - /** * Creates a fake extension inside typo3temp/. No configuration is created, * just the folder @@ -56,8 +34,8 @@ class FileHandlingUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { */ protected function createFakeExtension($extkeyOnly = FALSE) { $extKey = strtolower(uniqid('testing')); - $absExtPath = PATH_site . 'typo3conf/ext/' . $extKey . '/'; - $relPath = 'typo3conf/ext/' . $extKey . '/'; + $absExtPath = PATH_site . 'typo3temp/ext-' . $extKey . '/'; + $relPath = 'typo3temp/ext-' . $extKey . '/'; $this->fakedExtensions[$extKey] = array( 'siteRelPath' => $relPath, 'siteAbsPath' => $absExtPath @@ -66,6 +44,7 @@ class FileHandlingUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { return $extKey; } \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($absExtPath); + $this->testFilesToDelete[] = PATH_site . 'typo3temp/ext-' . $extKey; return $extKey; } @@ -75,8 +54,13 @@ class FileHandlingUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { */ public function makeAndClearExtensionDirRemovesExtensionDirIfAlreadyExists() { $extKey = $this->createFakeExtension(); - $fileHandlerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\FileHandlingUtility', array('removeDirectory', 'addDirectory'), array(), '', FALSE); - $fileHandlerMock->expects($this->once())->method('removeDirectory')->with(PATH_site . 'typo3conf/ext/' . $extKey . '/'); + $fileHandlerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\FileHandlingUtility', array('removeDirectory', 'addDirectory', 'getExtensionDir'), array(), '', FALSE); + $fileHandlerMock->expects($this->once()) + ->method('removeDirectory') + ->with(PATH_site . 'typo3temp/ext-' . $extKey . '/'); + $fileHandlerMock->expects($this->any()) + ->method('getExtensionDir') + ->willReturn(PATH_site . 'typo3temp/ext-' . $extKey . '/'); $fileHandlerMock->_call('makeAndClearExtensionDir', $extKey); } @@ -130,8 +114,13 @@ class FileHandlingUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { */ public function makeAndClearExtensionDirAddsDir() { $extKey = $this->createFakeExtension(); - $fileHandlerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\FileHandlingUtility', array('removeDirectory', 'addDirectory')); - $fileHandlerMock->expects($this->once())->method('addDirectory')->with(PATH_site . 'typo3conf/ext/' . $extKey . '/'); + $fileHandlerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\FileHandlingUtility', array('removeDirectory', 'addDirectory', 'getExtensionDir')); + $fileHandlerMock->expects($this->once()) + ->method('addDirectory') + ->with(PATH_site . 'typo3temp/ext-' . $extKey . '/'); + $fileHandlerMock->expects($this->any()) + ->method('getExtensionDir') + ->willReturn(PATH_site . 'typo3temp/ext-' . $extKey . '/'); $fileHandlerMock->_call('makeAndClearExtensionDir', $extKey); } @@ -152,9 +141,9 @@ class FileHandlingUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { * @return void */ public function addDirectoryAddsDirectory() { - $extDirPath = $this->fakedExtensions[$this->createFakeExtension(TRUE)]['siteAbsPath']; + $extDirPath = PATH_site . '/typo3temp/' . uniqid('test-extensions-', TRUE); + $this->testFilesToDelete[] = $extDirPath; $fileHandlerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\FileHandlingUtility', array('dummy')); - $this->assertFalse(is_dir($extDirPath)); $fileHandlerMock->_call('addDirectory', $extDirPath); $this->assertTrue(is_dir($extDirPath)); } @@ -164,9 +153,9 @@ class FileHandlingUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { * @return void */ public function removeDirectoryRemovesDirectory() { - $extDirPath = $this->fakedExtensions[$this->createFakeExtension()]['siteAbsPath']; + $extDirPath = PATH_site . '/typo3temp/' . uniqid('test-extensions-', TRUE); + @mkdir($extDirPath); $fileHandlerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\FileHandlingUtility', array('dummy')); - $this->assertTrue(is_dir($extDirPath)); $fileHandlerMock->_call('removeDirectory', $extDirPath); $this->assertFalse(is_dir($extDirPath)); } @@ -179,7 +168,7 @@ class FileHandlingUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $absoluteSymlinkPath = PATH_site . 'typo3temp/' . uniqid('test_symlink_'); $absoluteFilePath = PATH_site . 'typo3temp/' . uniqid('test_file_'); touch($absoluteFilePath); - $this->resourcesToRemove[] = $absoluteFilePath; + $this->testFilesToDelete[] = $absoluteFilePath; symlink($absoluteFilePath, $absoluteSymlinkPath); $fileHandler = new \TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility(); $fileHandler->removeDirectory($absoluteSymlinkPath); @@ -198,8 +187,8 @@ class FileHandlingUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { mkdir($absoluteDirectoryPath); touch($absoluteDirectoryPath . $relativeFilePath); - $this->resourcesToRemove[] = $absoluteDirectoryPath . $relativeFilePath; - $this->resourcesToRemove[] = $absoluteDirectoryPath; + $this->testFilesToDelete[] = $absoluteDirectoryPath . $relativeFilePath; + $this->testFilesToDelete[] = $absoluteDirectoryPath; symlink($absoluteDirectoryPath, $absoluteSymlinkPath); @@ -567,7 +556,7 @@ class FileHandlingUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { // File was created $this->assertTrue(file_exists($filename), 'Zip file not created'); - $this->resourcesToRemove[] = $filename; + $this->testFilesToDelete[] = $filename; // Read archive and check its contents $archive = new \ZipArchive(); diff --git a/typo3/sysext/extensionmanager/Tests/Unit/Utility/InstallUtilityTest.php b/typo3/sysext/extensionmanager/Tests/Unit/Utility/InstallUtilityTest.php index a29801e89f29..4132f99c0a63 100644 --- a/typo3/sysext/extensionmanager/Tests/Unit/Utility/InstallUtilityTest.php +++ b/typo3/sysext/extensionmanager/Tests/Unit/Utility/InstallUtilityTest.php @@ -85,8 +85,8 @@ class InstallUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { * @return void */ public function tearDown() { - foreach ($this->fakedExtensions as $extension => $dummy) { - \TYPO3\CMS\Core\Utility\GeneralUtility::rmdir(PATH_site . 'typo3temp/' . $extension, TRUE); + foreach ($this->fakedExtensions as $fakeExtkey => $fakeExtension) { + $this->testFilesToDelete[] = PATH_site . 'typo3temp/' . $fakeExtkey; } parent::tearDown(); } diff --git a/typo3/sysext/indexed_search/Tests/Unit/IndexerTest.php b/typo3/sysext/indexed_search/Tests/Unit/IndexerTest.php index dafef50e0136..5349723f5989 100644 --- a/typo3/sysext/indexed_search/Tests/Unit/IndexerTest.php +++ b/typo3/sysext/indexed_search/Tests/Unit/IndexerTest.php @@ -29,13 +29,6 @@ class IndexerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { */ protected $fixture = NULL; - /** - * A name of the temporary file - * - * @var string - */ - protected $temporaryFileName = ''; - /** * Sets up the test */ @@ -43,16 +36,6 @@ class IndexerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $this->fixture = $this->getMock('TYPO3\CMS\IndexedSearch\Indexer', array('dummy')); } - /** - * Explicitly clean up the indexer object to prevent any memory leaks - */ - public function tearDown() { - if ($this->temporaryFileName) { - @unlink($this->temporaryFileName); - } - parent::tearDown(); - } - /** * @test */ @@ -67,14 +50,15 @@ class IndexerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { * @test */ public function extractHyperLinksReturnsCorrectFileUsingT3Vars() { - $this->temporaryFileName = tempnam(sys_get_temp_dir(), 't3unit-'); + $temporaryFileName = tempnam(PATH_site . 'typo3temp/', 't3unit-'); + $this->testFilesToDelete[] = $temporaryFileName; $html = 'test <a href="testfile">test</a> test'; $GLOBALS['T3_VAR']['ext']['indexed_search']['indexLocalFiles'] = array( - \TYPO3\CMS\Core\Utility\GeneralUtility::shortMD5('testfile') => $this->temporaryFileName, + \TYPO3\CMS\Core\Utility\GeneralUtility::shortMD5('testfile') => $temporaryFileName, ); $result = $this->fixture->extractHyperLinks($html); $this->assertEquals(1, count($result)); - $this->assertEquals($this->temporaryFileName, $result[0]['localPath']); + $this->assertEquals($temporaryFileName, $result[0]['localPath']); } /** diff --git a/typo3/sysext/install/Tests/Unit/FolderStructure/AbstractNodeTest.php b/typo3/sysext/install/Tests/Unit/FolderStructure/AbstractNodeTest.php index 19468aedd0bb..dd743a314afe 100644 --- a/typo3/sysext/install/Tests/Unit/FolderStructure/AbstractNodeTest.php +++ b/typo3/sysext/install/Tests/Unit/FolderStructure/AbstractNodeTest.php @@ -19,23 +19,6 @@ namespace TYPO3\CMS\Install\Tests\Unit\FolderStructure; */ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { - /** - * @var array Directories or files in typo3temp/ created during tests to delete afterwards - */ - protected $testNodesToDelete = array(); - - /** - * Tear down - */ - public function tearDown() { - foreach($this->testNodesToDelete as $node) { - if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($node, PATH_site . 'typo3temp/')) { - \TYPO3\CMS\Core\Utility\GeneralUtility::rmdir($node, TRUE); - } - } - parent::tearDown(); - } - /** * @test */ @@ -127,7 +110,7 @@ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode', array('getAbsolutePath'), array(), '', FALSE); $path = PATH_site . 'typo3temp/' . uniqid('dir_'); \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $this->assertTrue($node->_call('exists')); } @@ -144,7 +127,7 @@ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $path = PATH_site . 'typo3temp/' . uniqid('link_'); $target = PATH_site . 'typo3temp/' . uniqid('notExists_'); symlink($target, $path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $this->assertTrue($node->_call('exists')); } @@ -203,7 +186,7 @@ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $subPath = $path . '/' . uniqid('dir_'); mkdir($subPath); chmod($path, 02000); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath)); $node->_set('targetPermission', '2770'); $this->assertInstanceOf('TYPO3\\CMS\\Install\\Status\\NoticeStatus', $node->_call('fixPermission')); @@ -235,7 +218,7 @@ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $subPath = $path . '/' . uniqid('dir_'); mkdir($subPath); chmod($path, 02000); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath)); $node->_set('targetPermission', '2770'); $this->assertInstanceOf('TYPO3\\CMS\\Install\\Status\\NoticeStatus', $node->_call('fixPermission')); @@ -264,7 +247,7 @@ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $subPath = $path . '/' . uniqid('dir_'); mkdir($subPath); chmod($path, 02770); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->_set('targetPermission', '2770'); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath)); $this->assertInstanceOf('TYPO3\\CMS\\Install\\Status\\OkStatus', $node->_call('fixPermission')); @@ -305,7 +288,7 @@ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode', array('getAbsolutePath'), array(), '', FALSE); $path = PATH_site . 'typo3temp/' . uniqid('dir_'); \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; chmod($path, 02775); clearstatcache(); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); @@ -323,7 +306,7 @@ class AbstractNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\AbstractNode', array('getAbsolutePath'), array(), '', FALSE); $file = PATH_site . 'typo3temp/' . uniqid('file_'); touch($file); - $this->testNodesToDelete[] = $file; + $this->testFilesToDelete[] = $file; chmod($file, 0770); clearstatcache(); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($file)); diff --git a/typo3/sysext/install/Tests/Unit/FolderStructure/DirectoryNodeTest.php b/typo3/sysext/install/Tests/Unit/FolderStructure/DirectoryNodeTest.php index 3f4050e42d6b..76013a92c209 100644 --- a/typo3/sysext/install/Tests/Unit/FolderStructure/DirectoryNodeTest.php +++ b/typo3/sysext/install/Tests/Unit/FolderStructure/DirectoryNodeTest.php @@ -19,23 +19,6 @@ namespace TYPO3\CMS\Install\Tests\Unit\FolderStructure; */ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { - /** - * @var array Directories or files in typo3temp/ created during tests to delete afterwards - */ - protected $testNodesToDelete = array(); - - /** - * Tear down - */ - public function tearDown() { - foreach ($this->testNodesToDelete as $node) { - if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($node, PATH_site . 'typo3temp/')) { - \TYPO3\CMS\Core\Utility\GeneralUtility::rmdir($node, TRUE); - } - } - parent::tearDown(); - } - /** * @test * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException @@ -185,7 +168,7 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { ); $path = PATH_site . 'typo3temp/' . uniqid('dir_'); touch ($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE)); $node->expects($this->any())->method('isDirectory')->will($this->returnValue(FALSE)); @@ -211,7 +194,7 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { ); $path = PATH_site . 'typo3temp/' . uniqid('dir_'); touch ($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE)); $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE)); @@ -237,7 +220,7 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { ); $path = PATH_site . 'typo3temp/' . uniqid('dir_'); touch ($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE)); $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE)); @@ -263,7 +246,7 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { ); $path = PATH_site . 'typo3temp/' . uniqid('dir_'); touch ($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE)); $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE)); @@ -442,7 +425,7 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('exists', 'getAbsolutePath'), array(), '', FALSE); $path = PATH_site . 'typo3temp/' . uniqid('dir_'); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->_call('createDirectory'); @@ -456,7 +439,7 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { /** @var $node \TYPO3\CMS\Install\FolderStructure\DirectoryNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('exists', 'getAbsolutePath'), array(), '', FALSE); $path = PATH_site . 'typo3temp/' . uniqid('dir_'); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $this->assertInstanceOf('TYPO3\\CMS\Install\\Status\\StatusInterface', $node->_call('createDirectory')); @@ -475,7 +458,7 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { mkdir($path); chmod($path, 02550); $subPath = $path . '/' . uniqid('dir_'); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath)); $this->assertInstanceOf('TYPO3\\CMS\Install\\Status\\StatusInterface', $node->_call('createDirectory')); @@ -576,7 +559,7 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('getAbsolutePath'), array(), '', FALSE); $path = PATH_site . 'typo3temp/' . uniqid('root_'); \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $this->assertTrue($node->isWritable()); } @@ -595,7 +578,7 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('getAbsolutePath'), array(), '', FALSE); $path = PATH_site . 'typo3temp/' . uniqid('root_'); \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; chmod($path, 02550); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $this->assertFalse($node->isWritable()); @@ -609,7 +592,7 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('getAbsolutePath'), array(), '', FALSE); $path = PATH_site . 'typo3temp/' . uniqid('dir_'); \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $this->assertTrue($node->_call('isDirectory')); } @@ -625,7 +608,7 @@ class DirectoryNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\DirectoryNode', array('getAbsolutePath'), array(), '', FALSE); $path = PATH_site . 'typo3temp/' . uniqid('root_'); \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $link = uniqid('link_'); $dir = uniqid('dir_'); mkdir($path . '/' . $dir); diff --git a/typo3/sysext/install/Tests/Unit/FolderStructure/FileNodeTest.php b/typo3/sysext/install/Tests/Unit/FolderStructure/FileNodeTest.php index 682cbbce3f3b..eae711adee52 100644 --- a/typo3/sysext/install/Tests/Unit/FolderStructure/FileNodeTest.php +++ b/typo3/sysext/install/Tests/Unit/FolderStructure/FileNodeTest.php @@ -19,23 +19,6 @@ namespace TYPO3\CMS\Install\Tests\Unit\FolderStructure; */ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { - /** - * @var array Directories or files in typo3temp/ created during tests to delete afterwards - */ - protected $testNodesToDelete = array(); - - /** - * Tear down - */ - public function tearDown() { - foreach ($this->testNodesToDelete as $node) { - if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($node, PATH_site . 'typo3temp/')) { - \TYPO3\CMS\Core\Utility\GeneralUtility::rmdir($node, TRUE); - } - } - parent::tearDown(); - } - /** * @test * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException @@ -144,7 +127,7 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $targetFile = PATH_site . 'typo3temp/' . uniqid('test_'); $targetContent = uniqid('content_'); file_put_contents($targetFile, $targetContent); - $this->testNodesToDelete[] = $targetFile; + $this->testFilesToDelete[] = $targetFile; $structure = array( 'name' => 'foo', 'targetContentFile' => $targetFile, @@ -244,7 +227,7 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { ); $path = PATH_site . 'typo3temp/' . uniqid('dir_'); touch($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE)); $node->expects($this->any())->method('isFile')->will($this->returnValue(FALSE)); @@ -271,7 +254,7 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { ); $path = PATH_site . 'typo3temp/' . uniqid('dir_'); touch($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE)); $node->expects($this->any())->method('isFile')->will($this->returnValue(TRUE)); @@ -298,7 +281,7 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { ); $path = PATH_site . 'typo3temp/' . uniqid('dir_'); touch ($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE)); $node->expects($this->any())->method('isFile')->will($this->returnValue(TRUE)); @@ -325,7 +308,7 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { ); $path = PATH_site . 'typo3temp/' . uniqid('dir_'); touch($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE)); $node->expects($this->any())->method('isFile')->will($this->returnValue(TRUE)); @@ -352,7 +335,7 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { ); $path = PATH_site . 'typo3temp/' . uniqid('dir_'); touch($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE)); $node->expects($this->any())->method('isFile')->will($this->returnValue(TRUE)); @@ -548,7 +531,7 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { /** @var $node \TYPO3\CMS\Install\FolderStructure\FileNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('exists', 'getAbsolutePath'), array(), '', FALSE); $path = PATH_site . 'typo3temp/' . uniqid('file_'); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $this->assertInstanceOf('TYPO3\\CMS\Install\\Status\\StatusInterface', $node->_call('createFile')); @@ -561,7 +544,7 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { /** @var $node \TYPO3\CMS\Install\FolderStructure\FileNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('exists', 'getAbsolutePath'), array(), '', FALSE); $path = PATH_site . 'typo3temp/' . uniqid('file_'); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->_call('createFile'); @@ -581,7 +564,7 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { mkdir($path); chmod($path, 02550); $subPath = $path . '/' . uniqid('file_'); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->once())->method('exists')->will($this->returnValue(FALSE)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($subPath)); $this->assertInstanceOf('TYPO3\\CMS\Install\\Status\\StatusInterface', $node->_call('createFile')); @@ -596,7 +579,7 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('getAbsolutePath'), array(), '', FALSE); $path = PATH_site . 'typo3temp/' . uniqid('dir_'); mkdir($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->_call('isContentCorrect'); } @@ -609,7 +592,7 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('getAbsolutePath'), array(), '', FALSE); $path = PATH_site . 'typo3temp/' . uniqid('file_'); touch($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->_set('targetContent', NULL); $this->assertTrue($node->_call('isContentCorrect')); @@ -624,7 +607,7 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $path = PATH_site . 'typo3temp/' . uniqid('file_'); $content = uniqid('content_'); file_put_contents($path, $content); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->_set('targetContent', $content); $this->assertTrue($node->_call('isContentCorrect')); @@ -640,7 +623,7 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $content = uniqid('content1_'); $targetContent = uniqid('content2_'); file_put_contents($path, $content); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->_set('targetContent', $targetContent); $this->assertFalse($node->_call('isContentCorrect')); @@ -673,7 +656,7 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('getAbsolutePath'), array(), '', FALSE); $path = PATH_site . 'typo3temp/' . uniqid('dir_'); mkdir($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->_set('targetContent', 'foo'); $node->_call('setContent'); @@ -688,7 +671,7 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('getAbsolutePath'), array(), '', FALSE); $path = PATH_site . 'typo3temp/' . uniqid('file_'); touch($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->_set('targetContent', NULL); $node->_call('setContent'); @@ -702,7 +685,7 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('getAbsolutePath', 'getRelativePathBelowSiteRoot'), array(), '', FALSE); $path = PATH_site . 'typo3temp/' . uniqid('file_'); touch($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $targetContent = uniqid('content_'); $node->_set('targetContent', $targetContent); @@ -719,7 +702,7 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('getAbsolutePath', 'getRelativePathBelowSiteRoot'), array(), '', FALSE); $path = PATH_site . 'typo3temp/' . uniqid('file_'); touch($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $targetContent = uniqid('content_'); $node->_set('targetContent', $targetContent); @@ -743,7 +726,7 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $file = $dir . '/' . uniqid('file_'); touch($file); chmod($file, 0440); - $this->testNodesToDelete[] = $dir; + $this->testFilesToDelete[] = $dir; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($file)); $targetContent = uniqid('content_'); $node->_set('targetContent', $targetContent); @@ -758,7 +741,7 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('getAbsolutePath'), array(), '', FALSE); $path = PATH_site . 'typo3temp/' . uniqid('file_'); touch($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $this->assertTrue($node->_call('isFile')); } @@ -774,7 +757,7 @@ class FileNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\FileNode', array('getAbsolutePath'), array(), '', FALSE); $path = PATH_site . 'typo3temp/' . uniqid('root_'); \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $link = uniqid('link_'); $file = uniqid('file_'); touch($path . '/' . $file); diff --git a/typo3/sysext/install/Tests/Unit/FolderStructure/LinkNodeTest.php b/typo3/sysext/install/Tests/Unit/FolderStructure/LinkNodeTest.php index 3c7ffeab92a7..3c0e7f6b3d60 100644 --- a/typo3/sysext/install/Tests/Unit/FolderStructure/LinkNodeTest.php +++ b/typo3/sysext/install/Tests/Unit/FolderStructure/LinkNodeTest.php @@ -19,23 +19,6 @@ namespace TYPO3\CMS\Install\Tests\Unit\FolderStructure; */ class LinkNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { - /** - * @var array Directories or files in typo3temp/ created during tests to delete afterwards - */ - protected $testNodesToDelete = array(); - - /** - * Tear down - */ - public function tearDown() { - foreach ($this->testNodesToDelete as $node) { - if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($node, PATH_site . 'typo3temp/')) { - \TYPO3\CMS\Core\Utility\GeneralUtility::rmdir($node, TRUE); - } - } - parent::tearDown(); - } - /** * @test * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\InvalidArgumentException @@ -263,7 +246,7 @@ class LinkNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $path = PATH_site . 'typo3temp/' . uniqid('link_'); $target = PATH_site . uniqid('linkTarget_'); symlink($target, $path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $this->assertTrue($node->_call('isLink')); @@ -280,7 +263,7 @@ class LinkNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\LinkNode', array('exists', 'getAbsolutePath'), array(), '', FALSE); $path = PATH_site . 'typo3temp/' . uniqid('file_'); touch($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE)); $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $this->assertFalse($node->_call('isLink')); @@ -344,7 +327,7 @@ class LinkNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $path = PATH_site . 'typo3temp/' . uniqid('link_'); $target = uniqid('linkTarget_'); symlink($target, $path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\LinkNode', array('exists', 'isLink', 'getTarget', 'getAbsolutePath'), @@ -369,7 +352,7 @@ class LinkNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { $path = PATH_site . 'typo3temp/' . uniqid('link_'); $target = uniqid('linkTarget_'); symlink($target, $path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; /** @var $node \TYPO3\CMS\Install\FolderStructure\LinkNode|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */ $node = $this->getAccessibleMock('TYPO3\\CMS\\Install\\FolderStructure\\LinkNode', array('exists', 'isLink', 'getTarget', 'getAbsolutePath'), diff --git a/typo3/sysext/install/Tests/Unit/FolderStructure/RootNodeTest.php b/typo3/sysext/install/Tests/Unit/FolderStructure/RootNodeTest.php index 89c646a27fd0..10785a8f0f0a 100644 --- a/typo3/sysext/install/Tests/Unit/FolderStructure/RootNodeTest.php +++ b/typo3/sysext/install/Tests/Unit/FolderStructure/RootNodeTest.php @@ -19,23 +19,6 @@ namespace TYPO3\CMS\Install\Tests\Unit\FolderStructure; */ class RootNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { - /** - * @var array Directories or files in typo3temp/ created during tests to delete afterwards - */ - protected $testNodesToDelete = array(); - - /** - * Tear down - */ - public function tearDown() { - foreach ($this->testNodesToDelete as $node) { - if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($node, PATH_site . 'typo3temp/')) { - \TYPO3\CMS\Core\Utility\GeneralUtility::rmdir($node, TRUE); - } - } - parent::tearDown(); - } - /** * @test * @expectedException \TYPO3\CMS\Install\FolderStructure\Exception\RootNodeException @@ -193,7 +176,7 @@ class RootNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { ); $path = PATH_site . 'typo3temp/' . uniqid('dir_'); touch ($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->once())->method('exists')->will($this->returnValue(TRUE)); $node->expects($this->once())->method('isDirectory')->will($this->returnValue(TRUE)); @@ -219,7 +202,7 @@ class RootNodeTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { ); $path = PATH_site . 'typo3temp/' . uniqid('dir_'); touch ($path); - $this->testNodesToDelete[] = $path; + $this->testFilesToDelete[] = $path; $node->expects($this->any())->method('getAbsolutePath')->will($this->returnValue($path)); $node->expects($this->any())->method('exists')->will($this->returnValue(TRUE)); $node->expects($this->any())->method('isDirectory')->will($this->returnValue(TRUE)); -- GitLab