From f23f4acde565b461323bd1f41908d83af2826667 Mon Sep 17 00:00:00 2001
From: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Date: Wed, 18 Dec 2013 21:12:01 +0100
Subject: [PATCH] [BUGFIX] Follow up: Moving files and folders doesn't update
 hashes

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
---
 .../Unit/Resource/Driver/LocalDriverTest.php  |  3 ++-
 .../Unit/Resource/ResourceStorageTest.php     | 25 +++++++++++++++----
 2 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php b/typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php
index 6e0f4583ad1b..6dbb70e599a3 100644
--- a/typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php
+++ b/typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php
@@ -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'));
 	}
 
diff --git a/typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php b/typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php
index 2336187b5da1..273b40f0739c 100644
--- a/typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php
+++ b/typo3/sysext/core/Tests/Unit/Resource/ResourceStorageTest.php
@@ -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');
 	}
 
-- 
GitLab