/** * 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()); }
/** * Renders a HTML Block with file information * * @param File $file * @return string */ protected function renderFileInformationContent(File $file = null) { /** @var LanguageService $lang */ $lang = $GLOBALS['LANG']; if ($file !== null) { $processedFile = $file->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, ['width' => 150, 'height' => 150]); $previewImage = $processedFile->getPublicUrl(true); $content = ''; if ($file->isMissing()) { $content .= '<span class="label label-danger label-space-right">' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.file_missing')) . '</span>'; } if ($previewImage) { $content .= '<img src="' . htmlspecialchars($previewImage) . '" ' . 'width="' . $processedFile->getProperty('width') . '" ' . 'height="' . $processedFile->getProperty('height') . '" ' . 'alt="" class="t3-tceforms-sysfile-imagepreview" />'; } $content .= '<strong>' . htmlspecialchars($file->getName()) . '</strong>'; $content .= ' (' . htmlspecialchars(GeneralUtility::formatSize($file->getSize())) . 'bytes)<br />'; $content .= BackendUtility::getProcessedValue('sys_file', 'type', $file->getType()) . ' (' . $file->getMimeType() . ')<br />'; $content .= htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:fileMetaDataLocation')) . ': '; $content .= htmlspecialchars($file->getStorage()->getName()) . ' - ' . htmlspecialchars($file->getIdentifier()) . '<br />'; $content .= '<br />'; } else { $content = '<h2>' . htmlspecialchars($lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_misc.xlf:fileMetaErrorInvalidRecord')) . '</h2>'; } return $content; }
/** * 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()); }
/** * Get the MIME type of this file * * @return string mime type */ public function getMimeType() { return $this->originalFile->getMimeType(); }