wiki.techinc.nl/tests/phpunit/includes/MimeMagicTest.php
Timo Tijhof 2459925e4a MimeMagic: Set mime-type for .js to application/javascript
The previous "application/x-javascript" was non-standard. It was used as
unregistered mime type by various vendors after stakeholders agreed it
shouldn't be text/javascript anymore, but "application/javascript" was
still pending approval. That was settled in 2006 with RFC 4329.
http://www.iana.org/assignments/media-types/media-types.xhtml
https://tools.ietf.org/html/rfc4329

It also previously inconsistently returned "application/x-javascript" or
"text/javascript" depending on whether you call MimeMagic with or without
the flag that asks for "improved" mime magic (in the latter mode, it picks
the first one from the mime-info list as override).

This makes MimeMagic match the behaviour of HHVM-static server, NGINX,
and Apache 2.4; with regards to Content-Type for .js files.

Change-Id: Idfe0a80c60c548fe28283c62ee9803bff7bdb2d6
2016-01-26 01:52:36 +00:00

51 lines
1.8 KiB
PHP

<?php
class MimeMagicTest extends PHPUnit_Framework_TestCase {
/** @var MimeMagic */
private $mimeMagic;
function setUp() {
$this->mimeMagic = MimeMagic::singleton();
parent::setUp();
}
/**
* @dataProvider providerImproveTypeFromExtension
* @param string $ext File extension (no leading dot)
* @param string $oldMime Initially detected MIME
* @param string $expectedMime MIME type after taking extension into account
*/
function testImproveTypeFromExtension( $ext, $oldMime, $expectedMime ) {
$actualMime = $this->mimeMagic->improveTypeFromExtension( $oldMime, $ext );
$this->assertEquals( $expectedMime, $actualMime );
}
function providerImproveTypeFromExtension() {
return array(
array( 'gif', 'image/gif', 'image/gif' ),
array( 'gif', 'unknown/unknown', 'unknown/unknown' ),
array( 'wrl', 'unknown/unknown', 'model/vrml' ),
array( 'txt', 'text/plain', 'text/plain' ),
array( 'csv', 'text/plain', 'text/csv' ),
array( 'tsv', 'text/plain', 'text/tab-separated-values' ),
array( 'js', 'text/javascript', 'application/javascript' ),
array( 'js', 'application/x-javascript', 'application/javascript' ),
array( 'json', 'text/plain', 'application/json' ),
array( 'foo', 'application/x-opc+zip', 'application/zip' ),
array( 'docx', 'application/x-opc+zip',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' ),
array( 'djvu', 'image/x-djvu', 'image/vnd.djvu' ),
array( 'wav', 'audio/wav', 'audio/wav' ),
);
}
/**
* Test to make sure that encoder=ffmpeg2theora doesn't trigger
* MEDIATYPE_VIDEO (bug 63584)
*/
function testOggRecognize() {
$oggFile = __DIR__ . '/../data/media/say-test.ogg';
$actualType = $this->mimeMagic->getMediaType( $oggFile, 'application/ogg' );
$this->assertEquals( $actualType, MEDIATYPE_AUDIO );
}
}