[BUGFIX] Failing Resource\FactoryTest on Windows systems 12/22912/2
authorNicole Cordes <typo3@cordes.co>
Tue, 6 Aug 2013 20:00:25 +0000 (22:00 +0200)
committerNicole Cordes <typo3@cordes.co>
Wed, 7 Aug 2013 09:53:45 +0000 (11:53 +0200)
Two tests in class TYPO3\CMS\Core\Tests\Unit\Resource\FactoryTest fail
with warnings. This is because of two single issues.

First of all the test depends on a folder which (might) belong to an own
storage other than storage 0 (fileadmin). This patch changes fileadmin
to the typo3 folder as this one should be not included in any storage.

On the other hand on Windows systems a full path contains always a colon
which breaks any storage check. To solve this we have to fix any
absolute path beforehand as it is done in the sub functions as well.

Resolves: #50843
Releases: 6.2, 6.1, 6.0
Change-Id: I950a3c81222155da403ca1eb7b920e8682033450
Reviewed-on: https://review.typo3.org/22912
Reviewed-by: Nicole Cordes
Tested-by: Nicole Cordes
typo3/sysext/core/Classes/Resource/ResourceFactory.php
typo3/sysext/core/Tests/Unit/Resource/FactoryTest.php [deleted file]
typo3/sysext/core/Tests/Unit/Resource/ResourceFactoryTest.php [new file with mode: 0644]

index e60ed70..7f51a8b 100644 (file)
@@ -312,8 +312,10 @@ class ResourceFactory implements \TYPO3\CMS\Core\SingletonInterface {
         * @return FileInterface|Folder
         */
        public function retrieveFileOrFolderObject($input) {
-               // Easy function to deal with that, could be dropped in the future
-               // if we know where to use this function
+               // Remove PATH_site because absolute paths under Windows systems contain ':'
+               // This is done in all considered sub functions anyway
+               $input = str_replace(PATH_site, '', $input);
+
                if (\TYPO3\CMS\Core\Utility\GeneralUtility::isFirstPartOfStr($input, 'file:')) {
                        $input = substr($input, 5);
                        return $this->retrieveFileOrFolderObject($input);
diff --git a/typo3/sysext/core/Tests/Unit/Resource/FactoryTest.php b/typo3/sysext/core/Tests/Unit/Resource/FactoryTest.php
deleted file mode 100644 (file)
index 02316ca..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-<?php
-namespace TYPO3\CMS\Core\Tests\Unit\Resource;
-
-/***************************************************************
- * Copyright notice
- *
- * (c) 2011-2013 Andreas Wolf <andreas.wolf@ikt-werk.de>
- * All rights reserved
- *
- * This script is part of the TYPO3 project. The TYPO3 project is
- * free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * The GNU General Public License can be found at
- * http://www.gnu.org/copyleft/gpl.html.
- *
- * This script is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-
-/**
- * Testcase for the factory of FAL
- *
- * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
- */
-class FactoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
-
-       /**
-        * @var array A backup of registered singleton instances
-        */
-       protected $singletonInstances = array();
-
-       /**
-        * @var \TYPO3\CMS\Core\Resource\ResourceFactory
-        */
-       private $fixture;
-
-       /**
-        * @var boolean
-        */
-       private $objectCreated = FALSE;
-
-       /**
-        * @var array
-        */
-       private $filesCreated = array();
-
-       public function setUp() {
-               $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
-               $this->fixture = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', array('dummy'));
-       }
-
-       public function tearDown() {
-               \TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
-               foreach ($this->filesCreated as $file) {
-                       unlink($file);
-               }
-       }
-
-       /**********************************
-        * Storage Collections
-        **********************************/
-       /**
-        * @test
-        */
-       public function createStorageCollectionObjectCreatesCollectionWithCorrectArguments() {
-               $mockedMount = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
-               $path = uniqid();
-               $name = uniqid();
-               $storageCollection = $this->fixture->createFolderObject($mockedMount, $path, $name, 0);
-               $this->assertSame($mockedMount, $storageCollection->getStorage());
-               $this->assertEquals($path . '/', $storageCollection->getIdentifier());
-               $this->assertEquals($name, $storageCollection->getName());
-       }
-
-       /**********************************
-        * Drivers
-        **********************************/
-       /**
-        * @test
-        */
-       public function getDriverObjectAcceptsDriverClassName() {
-               $mockedDriver = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver', array(), array(), '', FALSE);
-               $driverFixtureClass = get_class($mockedDriver);
-               \TYPO3\CMS\Core\Utility\GeneralUtility::addInstance($driverFixtureClass, $mockedDriver);
-               $mockedMount = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
-               $mockedRegistry = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\DriverRegistry');
-               $mockedRegistry->expects($this->once())->method('getDriverClass')->with($this->equalTo($driverFixtureClass))->will($this->returnValue($driverFixtureClass));
-               \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\Driver\\DriverRegistry', $mockedRegistry);
-               $obj = $this->fixture->getDriverObject($driverFixtureClass, array());
-               $this->assertInstanceOf('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver', $obj);
-       }
-
-       /***********************************
-        *  File Handling
-        ***********************************/
-
-       public function directoryDataProviderValidFolderValues() {
-               return array(
-                       'relative path' => array('fileadmin'),
-                       'path with PATH_site' => array(PATH_site . 'fileadmin')
-               );
-       }
-
-       /**
-        * @test
-        * @dataProvider directoryDataProviderValidFolderValues
-        */
-       public function retrieveFileOrFolderObjectReturnsFolderIfPathIsGiven($source) {
-               $storage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array('getFile', 'getFolder'), array(), '', FALSE);
-               $storage->expects($this->once())
-                       ->method('getFolder')
-                       ->with('fileadmin');
-               $this->fixture->_set('storageInstances', array(0 => $storage));
-               $this->fixture->retrieveFileOrFolderObject($source);
-       }
-
-       /**
-        * @test
-        */
-       public function retrieveFileOrFolderObjectReturnsFileIfPathIsGiven() {
-               $filename = 'typo3temp/4711.txt';
-               $storage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array('getFile', 'getFolder'), array(), '', FALSE);
-               $storage->expects($this->once())
-                       ->method('getFile')
-                       ->with($filename);
-               $this->fixture->_set('storageInstances', array(0 => $storage));
-               // Create and prepare test file
-               \TYPO3\CMS\Core\Utility\GeneralUtility::writeFileToTypo3tempDir(PATH_site . $filename, '42');
-               $this->filesCreated[] = PATH_site . $filename;
-               $this->fixture->retrieveFileOrFolderObject($filename);
-       }
-}
-
-?>
diff --git a/typo3/sysext/core/Tests/Unit/Resource/ResourceFactoryTest.php b/typo3/sysext/core/Tests/Unit/Resource/ResourceFactoryTest.php
new file mode 100644 (file)
index 0000000..a16e3e2
--- /dev/null
@@ -0,0 +1,141 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Resource;
+
+/***************************************************************
+ * Copyright notice
+ *
+ * (c) 2011-2013 Andreas Wolf <andreas.wolf@ikt-werk.de>
+ * All rights reserved
+ *
+ * This script is part of the TYPO3 project. The TYPO3 project is
+ * free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The GNU General Public License can be found at
+ * http://www.gnu.org/copyleft/gpl.html.
+ *
+ * This script is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Testcase for the factory of FAL
+ *
+ * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
+ */
+class FactoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * @var array A backup of registered singleton instances
+        */
+       protected $singletonInstances = array();
+
+       /**
+        * @var \TYPO3\CMS\Core\Resource\ResourceFactory
+        */
+       private $fixture;
+
+       /**
+        * @var boolean
+        */
+       private $objectCreated = FALSE;
+
+       /**
+        * @var array
+        */
+       private $filesCreated = array();
+
+       public function setUp() {
+               $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
+               $this->fixture = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', array('dummy'));
+       }
+
+       public function tearDown() {
+               \TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
+               foreach ($this->filesCreated as $file) {
+                       unlink($file);
+               }
+       }
+
+       /**********************************
+        * Storage Collections
+        **********************************/
+       /**
+        * @test
+        */
+       public function createStorageCollectionObjectCreatesCollectionWithCorrectArguments() {
+               $mockedMount = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
+               $path = uniqid();
+               $name = uniqid();
+               $storageCollection = $this->fixture->createFolderObject($mockedMount, $path, $name, 0);
+               $this->assertSame($mockedMount, $storageCollection->getStorage());
+               $this->assertEquals($path . '/', $storageCollection->getIdentifier());
+               $this->assertEquals($name, $storageCollection->getName());
+       }
+
+       /**********************************
+        * Drivers
+        **********************************/
+       /**
+        * @test
+        */
+       public function getDriverObjectAcceptsDriverClassName() {
+               $mockedDriver = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver', array(), array(), '', FALSE);
+               $driverFixtureClass = get_class($mockedDriver);
+               \TYPO3\CMS\Core\Utility\GeneralUtility::addInstance($driverFixtureClass, $mockedDriver);
+               $mockedMount = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
+               $mockedRegistry = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\DriverRegistry');
+               $mockedRegistry->expects($this->once())->method('getDriverClass')->with($this->equalTo($driverFixtureClass))->will($this->returnValue($driverFixtureClass));
+               \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\Driver\\DriverRegistry', $mockedRegistry);
+               $obj = $this->fixture->getDriverObject($driverFixtureClass, array());
+               $this->assertInstanceOf('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver', $obj);
+       }
+
+       /***********************************
+        *  File Handling
+        ***********************************/
+
+       public function directoryDataProviderValidFolderValues() {
+               return array(
+                       'relative path' => array('typo3'),
+                       'path with PATH_site' => array(PATH_site . 'typo3')
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider directoryDataProviderValidFolderValues
+        */
+       public function retrieveFileOrFolderObjectReturnsFolderIfPathIsGiven($source) {
+               $storage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array('getFile', 'getFolder'), array(), '', FALSE);
+               $storage->expects($this->once())
+                       ->method('getFolder')
+                       ->with('typo3');
+               $this->fixture->_set('storageInstances', array(0 => $storage));
+               $this->fixture->retrieveFileOrFolderObject($source);
+       }
+
+       /**
+        * @test
+        */
+       public function retrieveFileOrFolderObjectReturnsFileIfPathIsGiven() {
+               $filename = 'typo3temp/4711.txt';
+               $storage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array('getFile', 'getFolder'), array(), '', FALSE);
+               $storage->expects($this->once())
+                       ->method('getFile')
+                       ->with($filename);
+               $this->fixture->_set('storageInstances', array(0 => $storage));
+               // Create and prepare test file
+               \TYPO3\CMS\Core\Utility\GeneralUtility::writeFileToTypo3tempDir(PATH_site . $filename, '42');
+               $this->filesCreated[] = PATH_site . $filename;
+               $this->fixture->retrieveFileOrFolderObject($filename);
+       }
+}
+
+?>