[BUGFIX] File must use MIME type from index record 11/37211/2
authorAndreas Wolf <aw@foundata.net>
Wed, 25 Feb 2015 12:52:22 +0000 (13:52 +0100)
committerMarkus Klein <klein.t3@reelworx.at>
Sun, 1 Mar 2015 21:22:50 +0000 (22:22 +0100)
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/37211
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
typo3/sysext/core/Classes/Resource/AbstractFile.php
typo3/sysext/core/Tests/Unit/Resource/AbstractFileTest.php

index 468c950..0249902 100644 (file)
@@ -259,7 +259,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')));
        }
 
        /**
index a7481a0..e9a2e69 100644 (file)
@@ -13,6 +13,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Resource;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use TYPO3\CMS\Core\Resource\File;
 
 /**
  * Testcase for the abstract file class of the TYPO3 FAL
@@ -44,4 +45,22 @@ class AbstractFileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
                $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() {
+               $mockedStorage = $this->getMockBuilder('TYPO3\\CMS\\Core\\Resource\\ResourceStorage')
+                       ->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());
+       }
+
 }