Merge "LinkBatch::addObj can also work with TitleValue objs"
[lhc/web/wiklou.git] / tests / phpunit / includes / MimeMagicTest.php
1 <?php
2 class MimeMagicTest extends PHPUnit_Framework_TestCase {
3
4 /** @var MimeMagic */
5 private $mimeMagic;
6
7 function setUp() {
8 $this->mimeMagic = MimeMagic::singleton();
9 parent::setUp();
10 }
11
12 /**
13 * @dataProvider providerImproveTypeFromExtension
14 * @param string $ext File extension (no leading dot)
15 * @param string $oldMime Initially detected MIME
16 * @param string $expectedMime MIME type after taking extension into account
17 */
18 function testImproveTypeFromExtension( $ext, $oldMime, $expectedMime ) {
19 $actualMime = $this->mimeMagic->improveTypeFromExtension( $oldMime, $ext );
20 $this->assertEquals( $expectedMime, $actualMime );
21 }
22
23 function providerImproveTypeFromExtension() {
24 return array(
25 array( 'gif', 'image/gif', 'image/gif' ),
26 array( 'gif', 'unknown/unknown', 'unknown/unknown' ),
27 array( 'wrl', 'unknown/unknown', 'model/vrml' ),
28 array( 'txt', 'text/plain', 'text/plain' ),
29 array( 'csv', 'text/plain', 'text/csv' ),
30 array( 'tsv', 'text/plain', 'text/tab-separated-values' ),
31 array( 'js', 'text/javascript', 'application/javascript' ),
32 array( 'js', 'application/x-javascript', 'application/javascript' ),
33 array( 'json', 'text/plain', 'application/json' ),
34 array( 'foo', 'application/x-opc+zip', 'application/zip' ),
35 array( 'docx', 'application/x-opc+zip',
36 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' ),
37 array( 'djvu', 'image/x-djvu', 'image/vnd.djvu' ),
38 array( 'wav', 'audio/wav', 'audio/wav' ),
39 );
40 }
41
42 /**
43 * Test to make sure that encoder=ffmpeg2theora doesn't trigger
44 * MEDIATYPE_VIDEO (bug 63584)
45 */
46 function testOggRecognize() {
47 $oggFile = __DIR__ . '/../data/media/say-test.ogg';
48 $actualType = $this->mimeMagic->getMediaType( $oggFile, 'application/ogg' );
49 $this->assertEquals( $actualType, MEDIATYPE_AUDIO );
50 }
51 }