Skip to content
Snippets Groups Projects
Commit a14a54ef authored by Andreas Wolf's avatar Andreas Wolf Committed by Wouter Wolters
Browse files

[BUGFIX] File must use MIME type from index record

The MIME type is stored in a field "mimetype" in the drivers, while the
field is called "mime_type" in the database. As the file object deals
with both when retrieving the type, it must respect this mismatch.

Change-Id: I06882c4d77e38284a48f7f7d7527bfc1c535edf3
Resolves: #65335
Releases: master, 6.2
Reviewed-on: http://review.typo3.org/37214


Reviewed-by: default avatarMarkus Klein <klein.t3@reelworx.at>
Tested-by: default avatarMarkus Klein <klein.t3@reelworx.at>
Reviewed-by: default avatarWouter Wolters <typo3@wouterwolters.nl>
Tested-by: default avatarWouter Wolters <typo3@wouterwolters.nl>
parent da07ff81
Branches
Tags
No related merge requests found
......@@ -253,7 +253,7 @@ abstract class AbstractFile implements FileInterface {
* @return array file information
*/
public function getMimeType() {
return $this->properties['mimetype'] ?: array_pop($this->getStorage()->getFileInfoByIdentifier($this->getIdentifier(), array('mimetype')));
return $this->properties['mime_type'] ?: array_pop($this->getStorage()->getFileInfoByIdentifier($this->getIdentifier(), array('mimetype')));
}
/**
......
......@@ -14,6 +14,10 @@ namespace TYPO3\CMS\Core\Tests\Unit\Resource;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Resource\AbstractFile;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\ResourceStorage;
/**
* Testcase for the abstract file class of the TYPO3 FAL
*
......@@ -28,21 +32,40 @@ class AbstractFileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
$parentIdentifier = '/parent/';
$currentIdentifier = '/parent/current/';
$mockedStorageForParent = $this->getMock(\TYPO3\CMS\Core\Resource\ResourceStorage::class, array(), array(), '', FALSE);
/** @var ResourceStorage|\PHPUnit_Framework_MockObject_MockObject $mockedStorageForParent */
$mockedStorageForParent = $this->getMock(ResourceStorage::class, array(), array(), '', FALSE);
/** @var \TYPO3\CMS\Core\Resource\AbstractFile $parentFolderFixture */
$parentFolderFixture = $this->getMockForAbstractClass(\TYPO3\CMS\Core\Resource\AbstractFile::class);
/** @var AbstractFile $parentFolderFixture */
$parentFolderFixture = $this->getMockForAbstractClass(AbstractFile::class);
$parentFolderFixture->setIdentifier($parentIdentifier)->setStorage($mockedStorageForParent);
$mockedStorage = $this->getMock(\TYPO3\CMS\Core\Resource\ResourceStorage::class, array('getFolderIdentifierFromFileIdentifier', 'getFolder'), array(), '', FALSE);
/** @var ResourceStorage|\PHPUnit_Framework_MockObject_MockObject $mockedStorage */
$mockedStorage = $this->getMock(ResourceStorage::class, array('getFolderIdentifierFromFileIdentifier', 'getFolder'), array(), '', FALSE);
$mockedStorage->expects($this->once())->method('getFolderIdentifierFromFileIdentifier')->with($currentIdentifier)->will($this->returnValue($parentIdentifier));
$mockedStorage->expects($this->once())->method('getFolder')->with($parentIdentifier)->will($this->returnValue($parentFolderFixture));
/** @var \TYPO3\CMS\Core\Resource\AbstractFile $currentFolderFixture */
$currentFolderFixture = $this->getMockForAbstractClass(\TYPO3\CMS\Core\Resource\AbstractFile::class);
/** @var AbstractFile $currentFolderFixture */
$currentFolderFixture = $this->getMockForAbstractClass(AbstractFile::class);
$currentFolderFixture->setIdentifier($currentIdentifier)->setStorage($mockedStorage);
$this->assertSame($parentFolderFixture, $currentFolderFixture->getParentFolder());
}
/**
* This test accounts for an inconsistency in the Storage–Driver interface of FAL: The driver returns the MIME
* type in a field "mimetype", while the file object and the database table use mime_type.
* The test is placed in the test case for AbstractFile because the broken functionality resides there, though
* it is only triggered when constructing a File instance with an index record.
*
* @test
*/
public function storageIsNotAskedForMimeTypeForPersistedRecord() {
/** @var ResourceStorage|\PHPUnit_Framework_MockObject_MockObject $mockedStorage */
$mockedStorage = $this->getMockBuilder(ResourceStorage::class)->disableOriginalConstructor()->getMock();
$mockedStorage->expects($this->never())->method('getFileInfoByIdentifier')->with('/foo', 'mimetype');
$subject = new File(array('identifier' => '/foo', 'mime_type' => 'my/mime-type'), $mockedStorage);
$this->assertEquals('my/mime-type', $subject->getMimeType());
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment