summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/MimeMagicTest.php
blob: 742d38277ac8fe0519af71ea80fcdff669f4126c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
class MimeMagicTest extends MediaWikiTestCase {

	/** @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( '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 );
	}
}