diff --git a/typo3/sysext/core/Classes/Resource/AbstractFile.php b/typo3/sysext/core/Classes/Resource/AbstractFile.php index 453a038547600c2cbfcd9e256dfc048e126a20a1..38fc36b0d471fd11be9068ba0fafe0c0a2428b4f 100644 --- a/typo3/sysext/core/Classes/Resource/AbstractFile.php +++ b/typo3/sysext/core/Classes/Resource/AbstractFile.php @@ -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'))); } /** diff --git a/typo3/sysext/core/Tests/Unit/Resource/AbstractFileTest.php b/typo3/sysext/core/Tests/Unit/Resource/AbstractFileTest.php index b79e01003c4c8c1521bb85ebfe0f909b90d7aef9..ea5c5de9ee5665f41b5dd41aa3711f0d263db41e 100644 --- a/typo3/sysext/core/Tests/Unit/Resource/AbstractFileTest.php +++ b/typo3/sysext/core/Tests/Unit/Resource/AbstractFileTest.php @@ -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()); + } + }