[BUGFIX] Clean-up responsibilities of FAL classes 23/24623/4
authorSteffen Ritter <info@rs-websystems.de>
Sat, 12 Oct 2013 11:04:49 +0000 (13:04 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 12 Oct 2013 14:51:36 +0000 (16:51 +0200)
This is a followup for the patch
I6ceeb8db4dd4e470e7c72dcfbc2121093411da75.

The latest change sets missed to adapt
the unit-tests accordingly.

Furthermore due to this change it came to light,
that the active loading option of storages in the file object
may create a recursion issue, if the file is not indexed.
This architectural problem has been removed by making
the constructor argument mandatory and extend the
ResourceFactory to always inject the correct storage.

Releases: 6.2
Resolves: #51528
Change-Id: Ic1561b83f49783e3af1b8f3403e1b8eab84a1380
Reviewed-on: https://review.typo3.org/24623
Reviewed-by: Frans Saris
Tested-by: Frans Saris
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
13 files changed:
typo3/sysext/core/Classes/Resource/AbstractFile.php
typo3/sysext/core/Classes/Resource/Driver/AbstractDriver.php
typo3/sysext/core/Classes/Resource/File.php
typo3/sysext/core/Classes/Resource/Folder.php
typo3/sysext/core/Classes/Resource/Index/FileIndexRepository.php
typo3/sysext/core/Classes/Resource/ResourceFactory.php
typo3/sysext/core/Classes/Resource/Service/IndexerService.php
typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php
typo3/sysext/core/Tests/Unit/Resource/FileTest.php
typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php
typo3/sysext/core/Tests/Unit/Resource/Utility/FileExtensionFilterTest.php
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php
typo3/sysext/scheduler/Classes/Task/FileIndexingTask.php

index 9b5ba7f..c61caf0 100644 (file)
@@ -356,26 +356,12 @@ abstract class AbstractFile implements FileInterface {
         */
        public function getStorage() {
                if ($this->storage === NULL) {
-                       $this->loadStorage();
+                       throw new \RuntimeException('You\'re using fileObjects without a storage.', 1381570091);
                }
                return $this->storage;
        }
 
        /**
-        * Loads the storage object of this file object.
-        *
-        * @return void
-        */
-       protected function loadStorage() {
-               $storageUid = $this->getProperty('storage');
-               if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($storageUid)) {
-                       /** @var $fileFactory ResourceFactory */
-                       $fileFactory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
-                       $this->storage = $fileFactory->getStorageObject($storageUid);
-               }
-       }
-
-       /**
         * Checks if this file exists. This should normally always return TRUE;
         * it might only return FALSE when this object has been created from an
         * index record without checking for.
@@ -394,18 +380,12 @@ abstract class AbstractFile implements FileInterface {
         * \TYPO3\CMS\Core\Resource-internal usage; don't use it to move files.
         *
         * @internal Should only be used by other parts of the File API (e.g. drivers after moving a file)
-        * @param integer|ResourceStorage $storage
+        * @param ResourceStorage $storage
         * @return File
         */
-       public function setStorage($storage) {
-               // Do not check for deleted file here as we might need this method for the recycler later on
-               if (is_object($storage) && $storage instanceof ResourceStorage) {
-                       $this->storage = $storage;
-                       $this->properties['storage'] = $storage->getUid();
-               } else {
-                       $this->properties['storage'] = $storage;
-                       $this->storage = NULL;
-               }
+       public function setStorage(ResourceStorage $storage) {
+               $this->storage = $storage;
+               $this->properties['storage'] = $storage->getUid();
                return $this;
        }
 
@@ -414,10 +394,11 @@ abstract class AbstractFile implements FileInterface {
         *
         * @internal Should only be used by other parts of the File API (e.g. drivers after moving a file)
         * @param string $identifier
-        * @return string
+        * @return File
         */
        public function setIdentifier($identifier) {
                $this->identifier = $identifier;
+               return $this;
        }
 
        /**
index 62819e1..9c41d27 100644 (file)
@@ -428,7 +428,7 @@ abstract class AbstractDriver {
         * @return \TYPO3\CMS\Core\Resource\File
         */
        protected function getFileObject(array $fileData) {
-               $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->createFileObject($fileData);
+               $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->createFileObject($fileData, $this->storage);
                return $fileObject;
        }
 
index da3f392..e803b1a 100644 (file)
@@ -81,18 +81,14 @@ class File extends AbstractFile {
         * @param array $fileData
         * @param ResourceStorage $storage
         */
-       public function __construct(array $fileData, $storage = NULL) {
+       public function __construct(array $fileData, ResourceStorage $storage) {
                if (isset($fileData['uid']) && intval($fileData['uid']) > 0) {
                        $this->indexed = TRUE;
                }
                $this->identifier = $fileData['identifier'];
                $this->name = $fileData['name'];
                $this->properties = $fileData;
-               if (is_object($storage)) {
-                       $this->storage = $storage;
-               } elseif (isset($fileData['storage']) && is_object($fileData['storage'])) {
-                       $this->storage = $fileData['storage'];
-               }
+               $this->storage = $storage;
        }
 
        /*******************************
@@ -171,8 +167,6 @@ class File extends AbstractFile {
                if ($this->indexed !== NULL || !$this->indexable) {
                        return;
                }
-               /** @var $repo FileRepository */
-               $repo = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
 
                $indexRecord = Index\FileIndexRepository::getInstance()->findOneByFileObject($this);
                if ($indexRecord === FALSE && $indexIfNotIndexed) {
@@ -246,8 +240,8 @@ class File extends AbstractFile {
                if (isset($properties['uid']) && intval($properties['uid']) > 0) {
                        $this->indexed = TRUE;
                }
-               if (isset($properties['storage'])) {
-                       $this->loadStorage();
+               if (array_key_exists('storage', $properties) && in_array('storage', $this->updatedProperties)) {
+                       $this->storage = ResourceFactory::getInstance()->getStorageObject($properties['storage']);
                }
        }
 
@@ -326,7 +320,7 @@ class File extends AbstractFile {
                foreach ($this->properties as $key => $value) {
                        $array[$key] = $value;
                }
-               $stat = $this->storage->getFileInfo($this);
+               $stat = $this->getStorage()->getFileInfo($this);
                foreach ($stat as $key => $value) {
                        $array[$key] = $value;
                }
index 34f3a47..d2f0845 100644 (file)
@@ -198,7 +198,7 @@ class Folder implements FolderInterface {
                $fileArray = $this->storage->getFileList($this->identifier, $start, $numberOfItems, $useFilters, TRUE, $recursive);
                $fileObjects = array();
                foreach ($fileArray as $fileInfo) {
-                       $fileObject = $factory->createFileObject($fileInfo);
+                       $fileObject = $factory->createFileObject($fileInfo, $this->storage);
 
                        // we might have duplicate filenames when fetching a recursive list, so don't use the filename as array key
                        if ($recursive == TRUE) {
index d61cc97..0245956 100644 (file)
@@ -59,12 +59,6 @@ class FileIndexRepository implements SingletonInterface {
        );
 
        /**
-        * @var FileIndexRepository
-        */
-       protected static $instance = NULL;
-
-
-       /**
         * Gets database instance
         *
         * @return \TYPO3\CMS\Core\Database\DatabaseConnection
@@ -79,10 +73,7 @@ class FileIndexRepository implements SingletonInterface {
         * @return FileIndexRepository
         */
        public static function getInstance() {
-               if (static::$instance === NULL) {
-                       static::$instance = GeneralUtility::makeInstance('TYPO3\CMS\Core\Resource\Index\FileIndexRepository');
-               }
-               return static::$instance;
+               return GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository');
        }
 
        /**
index 840f466..a0c9bb5 100644 (file)
@@ -29,6 +29,7 @@ namespace TYPO3\CMS\Core\Resource;
 
 use TYPO3\CMS\Core\Resource\Index\FileIndexRepository;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\MathUtility;
 use TYPO3\CMS\Core\Utility\PathUtility;
 
 // TODO implement constructor-level caching
@@ -387,7 +388,7 @@ class ResourceFactory implements \TYPO3\CMS\Core\SingletonInterface {
                        $fileObject = $this->getFileObject($fileData['uid'], $fileData);
                } else {
                        $fileData = $storage->getFileInfoByIdentifier($fileIdentifier);
-                       $fileObject = $this->createFileObject($fileData);
+                       $fileObject = $this->createFileObject($fileData, $storage);
                        if (!array_key_exists('uid', $fileData)) {
                                $this->getFileIndexRepository()->add($fileObject);
                        }
@@ -512,15 +513,20 @@ class ResourceFactory implements \TYPO3\CMS\Core\SingletonInterface {
         * row to be fetched.
         *
         * @param array $fileData
+        * @param ResourceStorage $storage
         * @return File
         */
-       public function createFileObject(array $fileData) {
+       public function createFileObject(array $fileData, ResourceStorage $storage = NULL) {
                /** @var File $fileObject */
-               $fileObject = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\File', $fileData);
-               if (is_numeric($fileData['storage'])) {
-                       $storageObject = $this->getStorageObject($fileData['storage']);
-                       $fileObject->setStorage($storageObject);
+               if (array_key_exists('storage', $fileData) && MathUtility::canBeInterpretedAsInteger($fileData['storage'])) {
+                       $storageObject = $this->getStorageObject(intval($fileData['storage']));
+               } elseif ($storage !== NULL) {
+                       $storageObject = $storage;
+                       $fileData['storage'] = $storage->getUid();
+               } else {
+                       throw new \RuntimeException('A file needs to reside in a Storage', 1381570997);
                }
+               $fileObject = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\File', $fileData, $storageObject);
                return $fileObject;
        }
 
index b5a9a19..5c00073 100644 (file)
@@ -28,6 +28,7 @@ namespace TYPO3\CMS\Core\Resource\Service;
  ***************************************************************/
 use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Resource\Index\FileIndexRepository;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Indexer for the virtual file system
@@ -43,11 +44,6 @@ class IndexerService implements \TYPO3\CMS\Core\SingletonInterface {
        protected $repository;
 
        /**
-        * @var \TYPO3\CMS\Core\Resource\ResourceFactory
-        */
-       protected $factory;
-
-       /**
         * empty constructor, nothing to do here yet
         */
        public function __construct() {
@@ -62,7 +58,7 @@ class IndexerService implements \TYPO3\CMS\Core\SingletonInterface {
         */
        protected function getRepository() {
                if ($this->repository === NULL) {
-                       $this->repository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
+                       $this->repository = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository');
                }
                return $this->repository;
        }
@@ -71,20 +67,17 @@ class IndexerService implements \TYPO3\CMS\Core\SingletonInterface {
         * @return \TYPO3\CMS\Core\Resource\Index\FileIndexRepository
         */
        protected function getFileIndexRepository() {
-               return FileIndexRepository::getInstance();
+               return GeneralUtility::makeInstance('TYPO3\CMS\Core\Resource\Index\FileIndexRepository');
        }
 
 
        /**
-        * Setter function for the fileFactory
-        * returns the object itself for chaining purposes
+        * Getter function for the fileFactory
         *
-        * @param \TYPO3\CMS\Core\Resource\ResourceFactory $factory
-        * @return \TYPO3\CMS\Core\Resource\Service\IndexerService
+        * @return \TYPO3\CMS\Core\Resource\ResourceFactory
         */
-       public function setFactory(\TYPO3\CMS\Core\Resource\ResourceFactory $factory) {
-               $this->factory = $factory;
-               return $this;
+       public function getFactory() {
+               return GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
        }
 
        /**
@@ -117,7 +110,7 @@ class IndexerService implements \TYPO3\CMS\Core\SingletonInterface {
                        $resultRows = $this->getFileIndexRepository()->findByContentHash($fileInfo['sha1']);
                        $otherFiles = array();
                        foreach ($resultRows as $row) {
-                               $otherFiles[] = $this->factory->getFileObject($row['uid'], $row);
+                               $otherFiles[] = $this->getFactory()->getFileObject($row['uid'], $row);
                        }
 
                        $movedFile = FALSE;
index e1787fc..f1b3bf7 100644 (file)
@@ -1140,7 +1140,7 @@ class LocalDriverTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase {
                if (!$storage) {
                        $storage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
                }
-               $fileObject = new \TYPO3\CMS\Core\Resource\File(array('identifier' => $identifier, 'name' => basename($identifier), 'storage' => $storage));
+               $fileObject = new \TYPO3\CMS\Core\Resource\File(array('identifier' => $identifier, 'name' => basename($identifier), 'storage' => $storage), $storage);
                return $fileObject;
        }
 
index 58d2fd8..e3a8eeb 100644 (file)
@@ -23,6 +23,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Resource;
  *
  * This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+use TYPO3\CMS\Core\Resource\ResourceStorage;
 
 /**
  * Testcase for the file class of the TYPO3 FAL
@@ -37,8 +38,16 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         */
        protected $singletonInstances = array();
 
+       /**
+        * @var ResourceStorage
+        */
+       protected $storageMock;
+
        public function setUp() {
                $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
+               $this->storageMock = $this->getMock('TYPO3\CMS\Core\Resource\ResourceStorage', array(), array(), '', FALSE);
+               $this->storageMock->expects($this->any())->method('getUid')->will($this->returnValue(5));
+
                \TYPO3\CMS\Core\Utility\GeneralUtility::purgeInstances();
        }
 
@@ -50,7 +59,7 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @return \TYPO3\CMS\Core\Resource\File
         */
        protected function prepareFixture() {
-               $fixture = new \TYPO3\CMS\Core\Resource\File('testfile');
+               $fixture = new \TYPO3\CMS\Core\Resource\File(array('testfile'), $this->storageMock);
                return $fixture;
        }
 
@@ -65,7 +74,7 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        uniqid() => uniqid(),
                        'uid' => 1
                );
-               $fixture = new \TYPO3\CMS\Core\Resource\File($properties);
+               $fixture = new \TYPO3\CMS\Core\Resource\File($properties, $this->storageMock);
                $availablePropertiesBackup = \TYPO3\CMS\Core\Resource\File::getAvailableProperties();
                \TYPO3\CMS\Core\Resource\File::setAvailableProperties(array_keys($properties));
                foreach ($properties as $key => $value) {
@@ -84,10 +93,10 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        public function commonPropertiesAreAvailableWithOwnGetters() {
                $properties = array(
                        'name' => uniqid(),
-                       'storage' => $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE),
+                       'storage' => $this->storageMock,
                        'size' => 1024
                );
-               $fixture = new \TYPO3\CMS\Core\Resource\File($properties);
+               $fixture = new \TYPO3\CMS\Core\Resource\File($properties, $this->storageMock);
                foreach ($properties as $key => $value) {
                        $this->assertEquals($value, call_user_func(array($fixture, 'get' . $key)));
                }
@@ -97,10 +106,10 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function fileAsksRepositoryForIndexStatus() {
-               $mockedRepository = $this->getMock('TYPO3\\CMS\\Core\\Resource\\FileRepository');
-               $mockedRepository->expects($this->once())->method('getFileIndexRecord')->will($this->returnValue(array()));
-               \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository', $mockedRepository);
-               $fixture = new \TYPO3\CMS\Core\Resource\File(array());
+               $mockedRepository = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository');
+               $mockedRepository->expects($this->once())->method('findOneByFileObject')->will($this->returnValue(array()));
+               \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository', $mockedRepository);
+               $fixture = new \TYPO3\CMS\Core\Resource\File(array(), $this->storageMock);
                $this->assertTrue($fixture->isIndexed());
        }
 
@@ -110,7 +119,7 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function fileIndexStatusIsTrueIfUidIsSet() {
-               $fixture = new \TYPO3\CMS\Core\Resource\File(array('uid' => 1));
+               $fixture = new \TYPO3\CMS\Core\Resource\File(array('uid' => 1), $this->storageMock);
                $this->assertTrue($fixture->isIndexed());
        }
 
@@ -119,7 +128,7 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         */
        public function updatePropertiesUpdatesFileProperties() {
                $identifier = '/' . uniqid();
-               $fixture = new \TYPO3\CMS\Core\Resource\File(array('uid' => 1, 'identifier' => '/test'));
+               $fixture = new \TYPO3\CMS\Core\Resource\File(array('uid' => 1, 'identifier' => '/test'), $this->storageMock);
                $fixture->updateProperties(array('identifier' => $identifier));
                $this->assertEquals($identifier, $fixture->getIdentifier());
        }
@@ -128,7 +137,7 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function updatePropertiesLeavesPropertiesUntouchedIfNotSetInNewProperties() {
-               $fixture = new \TYPO3\CMS\Core\Resource\File(array('uid' => 1, 'foo' => 'asdf', 'identifier' => '/test'));
+               $fixture = new \TYPO3\CMS\Core\Resource\File(array('uid' => 1, 'foo' => 'asdf', 'identifier' => '/test'), $this->storageMock);
                $fixture->updateProperties(array('foo' => 'foobar'));
                $this->assertEquals('/test', $fixture->getIdentifier());
                $this->assertEquals('/test', $fixture->getProperty('identifier'));
@@ -138,7 +147,7 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function updatePropertiesDiscardsUidIfAlreadySet() {
-               $fixture = new \TYPO3\CMS\Core\Resource\File(array('uid' => 1, 'identifier' => '/test'));
+               $fixture = new \TYPO3\CMS\Core\Resource\File(array('uid' => 1, 'identifier' => '/test'), $this->storageMock);
                $fixture->updateProperties(array('uid' => 3));
                $this->assertEquals(1, $fixture->getUid());
        }
@@ -147,7 +156,7 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function updatePropertiesRecordsNamesOfChangedProperties() {
-               $fixture = new \TYPO3\CMS\Core\Resource\File(array('uid' => 1, 'foo' => 'asdf', 'baz' => 'fdsw', 'identifier' => '/test'));
+               $fixture = new \TYPO3\CMS\Core\Resource\File(array('uid' => 1, 'foo' => 'asdf', 'baz' => 'fdsw', 'identifier' => '/test'), $this->storageMock);
                $fixture->updateProperties(array('foo' => 'foobar', 'baz' => 'foobaz'));
                $this->assertEquals(array('foo', 'baz'), $fixture->getUpdatedProperties());
        }
@@ -156,7 +165,7 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function updatePropertiesDoesNotRecordPropertyNameIfSameValueIsProvided() {
-               $fixture = new \TYPO3\CMS\Core\Resource\File(array('uid' => 1, 'foo' => 'asdf', 'identifier' => '/test'));
+               $fixture = new \TYPO3\CMS\Core\Resource\File(array('uid' => 1, 'foo' => 'asdf', 'identifier' => '/test'), $this->storageMock);
                $fixture->updateProperties(array('foo' => 'asdf'));
                $this->assertEmpty($fixture->getUpdatedProperties());
        }
@@ -165,7 +174,7 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function updatePropertiesMarksPropertyAsChangedOnlyOnce() {
-               $fixture = new \TYPO3\CMS\Core\Resource\File(array('uid' => 1, 'foo' => 'asdf', 'baz' => 'fdsw', 'identifier' => '/test'));
+               $fixture = new \TYPO3\CMS\Core\Resource\File(array('uid' => 1, 'foo' => 'asdf', 'baz' => 'fdsw', 'identifier' => '/test'), $this->storageMock);
                $fixture->updateProperties(array('foo' => 'foobar', 'baz' => 'foobaz'));
                $fixture->updateProperties(array('foo' => 'fdsw', 'baz' => 'asdf'));
                $this->assertEquals(array('foo', 'baz'), $fixture->getUpdatedProperties());
@@ -177,10 +186,11 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        public function updatePropertiesReloadsStorageObjectIfStorageChanges() {
                $mockedNewStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
                $mockedOldStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
-               $fixture = new \TYPO3\CMS\Core\Resource\File(array('uid' => 1, 'foo' => 'asdf', 'baz' => 'fdsw', 'identifier' => '/test', 'storage' => $mockedOldStorage));
-               $mockedRepository = $this->getMock('TYPO3\\CMS\\Core\\Resource\\StorageRepository');
-               $mockedRepository->expects($this->once())->method('findByUid')->with(2)->will($this->returnValue($mockedNewStorage));
-               \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository', $mockedRepository);
+               $mockedOldStorage->expects($this->any())->method('getUid')->will($this->returnValue(1));
+               $fixture = new \TYPO3\CMS\Core\Resource\File(array('uid' => 1, 'foo' => 'asdf', 'baz' => 'fdsw', 'identifier' => '/test', 'storage' => 1), $mockedOldStorage);
+               $mockedResourceFactory = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
+               $mockedResourceFactory->expects($this->once())->method('getStorageObject')->with(2)->will($this->returnValue($mockedNewStorage));
+               \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', $mockedResourceFactory);
                $fixture->updateProperties(array('storage' => 2));
                $this->assertSame($mockedNewStorage, $fixture->getStorage());
        }
@@ -189,10 +199,11 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function fetchingIndexedPropertyCausesFileObjectToLoadIndexRecord() {
-               $fixture = new \TYPO3\CMS\Core\Resource\File(array('identifier' => '/test', 'storage' => 1));
-               $mockedRepository = $this->getMock('TYPO3\\CMS\\Core\\Resource\\FileRepository');
-               $mockedRepository->expects($this->once())->method('getFileIndexRecord')->will($this->returnValue(array('uid' => 10)));
-               \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository', $mockedRepository);
+               $mockedRepository = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository');
+               $mockedRepository->expects($this->once())->method('findOneByFileObject')->will($this->returnValue(array('uid' => 10)));
+               \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository', $mockedRepository);
+
+               $fixture = new \TYPO3\CMS\Core\Resource\File(array('identifier' => '/test', 'storage' => 5), $this->storageMock);
                $this->assertEquals(10, $fixture->getProperty('uid'));
        }
 
@@ -200,11 +211,16 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function isIndexedTriggersIndexingIfFileIsNotIndexedAlready() {
-               $fixture = new \TYPO3\CMS\Core\Resource\File(array('identifier' => '/test', 'storage' => 1));
-               $mockedRepository = $this->getMock('TYPO3\\CMS\\Core\\Resource\\FileRepository');
-               $mockedRepository->expects($this->once())->method('getFileIndexRecord')->will($this->returnValue(FALSE));
-               $mockedRepository->expects($this->once())->method('addToIndex')->will($this->returnValue(array('uid' => 10)));
-               \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository', $mockedRepository);
+               $fixture = new \TYPO3\CMS\Core\Resource\File(array('identifier' => '/test', 'storage' => 5), $this->storageMock);
+               $mockedRepository = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository');
+               $mockedRepository->expects($this->once())->method('findOneByFileObject')->will($this->returnValue(FALSE));
+               \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository', $mockedRepository);
+
+               $indexerMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Service\\IndexerService', array(), array(), '', FALSE);
+               $indexerMock->expects($this->once())->method('indexFile')->will($this->returnValue(array()));
+               \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\Service\\IndexerService', $indexerMock);
+
+
                $fixture->isIndexed();
        }
 
@@ -212,11 +228,16 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function fileIsAutomaticallyIndexedOnPropertyAccessIfNotAlreadyIndexed() {
-               $fixture = new \TYPO3\CMS\Core\Resource\File(array('identifier' => '/test', 'storage' => 1));
-               $mockedRepository = $this->getMock('TYPO3\\CMS\\Core\\Resource\\FileRepository');
-               $mockedRepository->expects($this->once())->method('getFileIndexRecord')->will($this->returnValue(FALSE));
-               $mockedRepository->expects($this->once())->method('addToIndex')->will($this->returnValue(array('uid' => 10)));
-               \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\FileRepository', $mockedRepository);
+               $fixture = new \TYPO3\CMS\Core\Resource\File(array('identifier' => '/test', 'storage' => 5), $this->storageMock);
+               $mockedRepository = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository');
+               $mockedRepository->expects($this->once())->method('findOneByFileObject')->will($this->returnValue(FALSE));
+               \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository', $mockedRepository);
+
+               $indexerMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Service\\IndexerService', array(), array(), '', FALSE);
+               $indexerMock->expects($this->once())->method('indexFile')->will($this->returnValue(array('uid' => 10)));
+               \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\Service\\IndexerService', $indexerMock);
+
+
                $this->assertEquals(10, $fixture->getProperty('uid'));
        }
 
@@ -227,7 +248,7 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $targetStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
                $targetFolder = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Folder', array(), array(), '', FALSE);
                $targetFolder->expects($this->any())->method('getStorage')->will($this->returnValue($targetStorage));
-               $fixture = new \TYPO3\CMS\Core\Resource\File(array());
+               $fixture = new \TYPO3\CMS\Core\Resource\File(array(), $this->storageMock);
                $targetStorage->expects($this->once())->method('copyFile')->with($this->equalTo($fixture), $this->equalTo($targetFolder));
                $fixture->copyTo($targetFolder);
        }
@@ -239,7 +260,7 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $targetStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
                $targetFolder = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Folder', array(), array(), '', FALSE);
                $targetFolder->expects($this->any())->method('getStorage')->will($this->returnValue($targetStorage));
-               $fixture = new \TYPO3\CMS\Core\Resource\File(array());
+               $fixture = new \TYPO3\CMS\Core\Resource\File(array(), $this->storageMock);
                $targetStorage->expects($this->once())->method('moveFile')->with($this->equalTo($fixture), $this->equalTo($targetFolder));
                $fixture->moveTo($targetFolder);
        }
@@ -374,7 +395,8 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $fixture = new \TYPO3\CMS\Core\Resource\File(array(
                        'name' => $originalFilename,
                        'identifier' => '/' . $originalFilename
-               ));
+               ),
+               $this->storageMock);
                $this->assertSame($expectedBasename, $fixture->getNameWithoutExtension());
        }
 
@@ -386,7 +408,7 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $fixture = new \TYPO3\CMS\Core\Resource\File(array(
                        'name' => $originalFilename,
                        'identifier' => '/' . $originalFilename
-               ));
+               ), $this->storageMock);
                $this->assertSame($expectedExtension, $fixture->getExtension());
        }
 
@@ -394,7 +416,7 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function indexablePropertyIsByDefaultTrue() {
-               $fixture = new \TYPO3\CMS\Core\Resource\File(array());
+               $fixture = new \TYPO3\CMS\Core\Resource\File(array(), $this->storageMock);
                $this->assertAttributeEquals(TRUE, 'indexable', $fixture);
        }
 
@@ -402,7 +424,7 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function indexablePropertyCanBeSetAndGet() {
-               $fixture = new \TYPO3\CMS\Core\Resource\File(array());
+               $fixture = new \TYPO3\CMS\Core\Resource\File(array(), $this->storageMock);
                foreach (array(FALSE, TRUE) as $value) {
                        $fixture->setIndexable($value);
                        $this->assertSame($value, $fixture->isIndexable());
@@ -418,7 +440,7 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                );
                $method->setAccessible(TRUE);
 
-               $fixture = new \TYPO3\CMS\Core\Resource\File(array());
+               $fixture = new \TYPO3\CMS\Core\Resource\File(array(), $this->storageMock);
                $fixture->setIndexable(FALSE);
                $method->invoke($fixture);
                $this->assertNull($fixture->isIndexed());
index 293a135..9305118 100644 (file)
@@ -410,7 +410,9 @@ class ResourceStorageTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCa
         */
        public function setFileContentsUpdatesObjectProperties() {
                $this->initializeVfs();
-               $this->prepareFixture(array(), TRUE);
+               $driverObject = $this->getMockForAbstractClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver', array(), '', FALSE);
+               $this->fixture = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array('getFileIndexRepository', 'checkFileActionPermission'), array($driverObject, array()));
+               $this->fixture->expects($this->any())->method('checkFileActionPermission')->will($this->returnValue(TRUE));
                $fileInfo = array(
                        'storage' => 'A',
                        'identifier' => 'B',
@@ -434,10 +436,12 @@ class ResourceStorageTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCa
                $driver->expects($this->once())->method('getFileInfoByIdentifier')->will($this->returnValue($fileInfo));
                $driver->expects($this->once())->method('hash')->will($this->returnValue($hash));
                $this->fixture->setDriver($driver);
+               $indexFileRepositoryMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Index\\FileIndexRepository');
+               $this->fixture->expects($this->any())->method('getFileIndexRepository')->will($this->returnValue($indexFileRepositoryMock));
                $mockedFile = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array(), array(), '', FALSE);
-               $mockedFile->expects($this->any())->method('getIdentifier')->will($this->returnValue('/file.ext'));
                $mockedFile->expects($this->at(1))->method('updateProperties')->with($this->equalTo(array('sha1' => $hash)));
                $mockedFile->expects($this->at(3))->method('updateProperties')->with($this->equalTo($newProperties));
+               $indexFileRepositoryMock->expects($this->once())->method('update')->with($mockedFile);
                $this->fixture->setFileContents($mockedFile, uniqid());
        }
 
index 40ad2ba..f5ec443 100644 (file)
@@ -144,7 +144,9 @@ class FileExtensionFilterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        public function extensionFilterIgnoresCaseInAllowedExtensionCheck($fileExtension, $allowedExtensions, $disallowedExtensions, $isAllowed) {
 
                /** @var \TYPO3\CMS\Core\Resource\File $file */
-               $file = new \TYPO3\CMS\Core\Resource\File(array('name' => 'file.' . $fileExtension));
+               $file = new \TYPO3\CMS\Core\Resource\File(array('name' => 'file.' . $fileExtension),
+                       $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE)
+               );
 
                /** @var \TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter $filter */
                $filter = $this->getAccessibleMock('\TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter', array('dummy'));
index 4fb0f12..1e24f0f 100644 (file)
@@ -1552,7 +1552,9 @@ class ContentObjectRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        uniqid() => uniqid(),
                        'uid' => $uid
                );
-               $file = new \TYPO3\CMS\Core\Resource\File($properties);
+               $file = new \TYPO3\CMS\Core\Resource\File($properties,
+                       $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE)
+               );
                $this->cObj->setCurrentFile($file);
 
                $this->assertEquals($uid, $this->cObj->getData('file:current:uid'));
index e168146..8485a04 100644 (file)
@@ -85,11 +85,12 @@ class FileIndexingTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
         */
        public function execute() {
                $successfullyExecuted = TRUE;
+
                /** @var $fileFactory \TYPO3\CMS\Core\Resource\ResourceFactory */
                $fileFactory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
                /** @var $indexerService \TYPO3\CMS\Core\Resource\Service\IndexerService */
                $indexerService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Service\\IndexerService');
-               $indexerService->setFactory($fileFactory);
+
                // run indexing of every storage
                $storageRecords = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_file_storage', 'deleted = 0');
                foreach ($storageRecords as $storageRecord) {