public function SophronGuesserTest::testFileMimeTypeDetection in Sophron 8
Test mapping of mimetypes from filenames.
Mostly a copy of the equivalent method at \Drupal\KernelTests\Core\File\MimeTypeTest::testFileMimeTypeDetection.
File
- tests/
src/ Kernel/ SophronGuesserTest.php, line 66
Class
- SophronGuesserTest
- Tests for Sophron guesser.
Namespace
Drupal\Tests\sophron\KernelCode
public function testFileMimeTypeDetection() : void {
$prefixes = [
'public://',
'private://',
'temporary://',
'dummy-remote://',
];
$test_case = [
'test.jar' => 'application/java-archive',
'test.jpeg' => 'image/jpeg',
'test.JPEG' => 'image/jpeg',
'test.jpg' => 'image/jpeg',
'test.jar.jpg' => 'image/jpeg',
'test.jpg.jar' => 'application/java-archive',
'test.pcf.Z' => 'application/x-font',
'pcf.z' => 'application/octet-stream',
'jar' => 'application/octet-stream',
'some.junk' => 'application/octet-stream',
];
$guesser = $this->container
->get('file.mime_type.guesser');
// Test using default mappings.
foreach ($test_case as $input => $expected) {
// Test stream [URI].
foreach ($prefixes as $prefix) {
$output = $guesser
->guess($prefix . $input);
$this
->assertIdentical($output, $expected, sprintf("Mimetype for '%s' is '%s' (expected: '%s').", $prefix . $input, $output, $expected));
}
// Test normal path equivalent.
$output = $guesser
->guess($input);
$this
->assertIdentical($output, $expected, sprintf("Mimetype (using default mappings) for '%s' is '%s' (expected: '%s').", $input, $output, $expected));
}
}