[BUGFIX] Follow up: Moving files and folders doesn't update hashes 77/26477/7
authorStefan Neufeind <typo3.neufeind@speedpartner.de>
Wed, 18 Dec 2013 20:12:01 +0000 (21:12 +0100)
committerMarkus Klein <klein.t3@mfc-linz.at>
Wed, 18 Dec 2013 22:11:53 +0000 (23:11 +0100)
Since #53655, reviewed at https://review.typo3.org/25481 the indexer
takes care of updating file objects and index records if a file or
folder is moved.

The unit tests have not been adapted to that change accordingly.
This changeset fixes the tests for LocalDriver and ResourceStorage.

Change-Id: Id17b01b8e47dd63750d1c11c2d4e24313b053695
Resolves: #54499
Releases: 6.2
Reviewed-on: https://review.typo3.org/26477
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php
typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php

index 6e0f458..6dbb70e 100644 (file)
@@ -434,7 +434,8 @@ class LocalDriverTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase {
                        array('getMimeTypeOfFile')
                );
                $mockedFile = $this->getSimpleFileMock('/targetFolder/file', array('updateProperties'));
-               $mockedFile->expects($this->once())->method('updateProperties');
+               // does not update properties itself but leaves that to the indexer
+               $mockedFile->expects($this->never())->method('updateProperties');
                $fixture->replaceFile($mockedFile, $this->getUrl('sourceFolder/file'));
        }
 
index 2336187..273b40f 100644 (file)
@@ -440,9 +440,13 @@ class ResourceStorageTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCa
                $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($fileInfo['identifier']));
-               $mockedFile->expects($this->at(1))->method('updateProperties')->with($this->equalTo(array('sha1' => $hash)));
-               $mockedFile->expects($this->at(4))->method('updateProperties')->with($this->equalTo($newProperties));
-               $indexFileRepositoryMock->expects($this->once())->method('update')->with($mockedFile);
+               // called by indexer because the properties are updated
+               $this->fixture->expects($this->any())->method('getFileInfoByIdentifier')->will($this->returnValue($newProperties));
+               $mockedFile->expects($this->any())->method('getStorage')->will($this->returnValue($this->fixture));
+               $mockedFile->expects($this->any())->method('getProperties')->will($this->returnValue(array_keys($fileInfo)));
+               $mockedFile->expects($this->any())->method('getUpdatedProperties')->will($this->returnValue(array_keys($newProperties)));
+               // do not update directly; that's up to the indexer
+               $indexFileRepositoryMock->expects($this->never())->method('update');
                $this->fixture->setFileContents($mockedFile, uniqid());
        }
 
@@ -453,6 +457,15 @@ class ResourceStorageTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCa
        public function moveFileCallsDriversRawMethodsWithCorrectArguments() {
                $localFilePath = '/path/to/localFile';
                $sourceFileIdentifier = '/sourceFile.ext';
+               $fileInfoDummy = array(
+                       'storage' => 'A',
+                       'identifier' => 'B',
+                       'mtime' => 'C',
+                       'ctime' => 'D',
+                       'mimetype' => 'E',
+                       'size' => 'F',
+                       'name' => 'G',
+               );
                $this->addToMount(array(
                        'targetFolder' => array()
                ));
@@ -465,12 +478,14 @@ class ResourceStorageTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCa
                $sourceFile = $this->getSimpleFileMock($sourceFileIdentifier);
                $sourceFile->expects($this->once())->method('getForLocalProcessing')->will($this->returnValue($localFilePath));
                $sourceFile->expects($this->any())->method('getStorage')->will($this->returnValue($sourceStorage));
+               $sourceFile->expects($this->once())->method('getUpdatedProperties')->will($this->returnValue(array_keys($fileInfoDummy)));
+               $sourceFile->expects($this->once())->method('getProperties')->will($this->returnValue($fileInfoDummy));
                /** @var $driver \TYPO3\CMS\Core\Resource\Driver\LocalDriver */
                $driver = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Driver\\LocalDriver', array(), array(array('basePath' => $this->getMountRootUrl())));
+               $driver->expects($this->once())->method('getFileInfoByIdentifier')->will($this->returnValue($fileInfoDummy));
                $driver->expects($this->once())->method('addFileRaw')->with($localFilePath, $targetFolder, $this->equalTo('file.ext'))->will($this->returnValue('/targetFolder/file.ext'));
                /** @var $fixture \TYPO3\CMS\Core\Resource\ResourceStorage */
-               $fixture = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array('assureFileMovePermissions', 'updateFile'), array($driver, array('configuration' => $configuration)));
-               $fixture->expects($this->once())->method('updateFile')->with($this->equalTo($sourceFile), $this->equalTo('/targetFolder/file.ext'));
+               $fixture = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array('assureFileMovePermissions'), array($driver, array('configuration' => $configuration)));
                $fixture->moveFile($sourceFile, $targetFolder, 'file.ext');
        }