[BUGFIX] Failing tests in Resource\Driver\LocalDriverTest on Windows 95/22895/2
authorNicole Cordes <typo3@cordes.co>
Tue, 6 Aug 2013 20:22:06 +0000 (22:22 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 7 Aug 2013 03:35:19 +0000 (05:35 +0200)
The test createdFilesAreEmpty depends on another test which returns a
mocked object. In the mock two returnValues for getIdentifier() and
getName() were set. But due to PHPUnit architecture mocked functions
belong to the test there were defined and cannot be shared. This is why
the mock has to be initialized within the test itself. The test only
works because on unix system you can open a folder which returns an
empty string.

Furthermore if you use any php function to get a folder path we have to
fix the containing backslashes.

Finally due to some errors we have to rewind any iterator of class
RecursiveIteratorIterator as otherwise a wrong index is returned.

Resolves: #50844
Releases: 6.2, 6.1, 6.0
Change-Id: I13f9efbd1618056fcd66220e3de5e12af79e4dc6
Reviewed-on: https://review.typo3.org/22895
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php

index e5eb48d..22bc6b8 100644 (file)
@@ -350,7 +350,7 @@ class LocalDriver extends \TYPO3\CMS\Core\Resource\Driver\AbstractDriver {
                        }
 
                        // dirname returns "/" when called with "/" as the argument, so strip trailing slashes here to be sure
-                       $path = rtrim(dirname($identifier), '/') . '/';
+                       $path = rtrim(GeneralUtility::fixWindowsFilePath(dirname($identifier)), '/') . '/';
                        if (isset($itemRows[$identifier])) {
                                list($key, $item) = $this->{$itemHandlerMethod}($iteratorItem['name'], $path, $itemRows[$identifier]);
                        } else {
@@ -888,11 +888,13 @@ class LocalDriver extends \TYPO3\CMS\Core\Resource\Driver\AbstractDriver {
                $sourceFolderPath = $this->getAbsolutePath($folderToCopy);
                /** @var $iterator \RecursiveDirectoryIterator */
                $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($sourceFolderPath), \RecursiveIteratorIterator::SELF_FIRST);
+               // Rewind the iterator as this is important for some systems e.g. Windows
+               $iterator->rewind();
                while ($iterator->valid()) {
                        /** @var $current \RecursiveDirectoryIterator */
                        $current = $iterator->current();
                        $fileName = $current->getFilename();
-                       $itemSubPath = $iterator->getSubPathname();
+                       $itemSubPath = GeneralUtility::fixWindowsFilePath($iterator->getSubPathname());
                        if ($current->isDir() && !($fileName === '..' || $fileName === '.')) {
                                mkdir($targetFolderPath . $itemSubPath);
                        } elseif ($current->isFile()) {
index 5a1ddba..7e52433 100644 (file)
@@ -623,7 +623,7 @@ class LocalDriverTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase {
        /**
         * @test
         * @depends existenceChecksWorkForFilesAndFolders
-        * @return array The driver fixture, the mocked file
+        * @return \TYPO3\CMS\Core\Resource\Driver\LocalDriver The driver fixture
         */
        public function newFilesCanBeCreated() {
                $this->addToMount(array(
@@ -633,18 +633,16 @@ class LocalDriverTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase {
                list($basedir, $fixture) = $this->prepareRealTestEnvironment();
                mkdir($basedir . '/someDir');
                $fixture->createFile('testfile.txt', $fixture->getFolder('someDir'));
-               $mockedFile = $this->getSimpleFileMock('/someDir/testfile.txt');
                $this->assertTrue($fixture->fileExists('/someDir/testfile.txt'));
-               return array($fixture, $mockedFile);
+               return $fixture;
        }
 
        /**
         * @test
         * @depends newFilesCanBeCreated
         */
-       public function createdFilesAreEmpty(array $arguments) {
-               /** @var $fixture \TYPO3\CMS\Core\Resource\Driver\LocalDriver */
-               list($fixture, $mockedFile) = $arguments;
+       public function createdFilesAreEmpty(\TYPO3\CMS\Core\Resource\Driver\LocalDriver $fixture) {
+               $mockedFile = $this->getSimpleFileMock('/someDir/testfile.txt');
                $fileData = $fixture->getFileContents($mockedFile);
                $this->assertEquals(0, strlen($fileData));
        }