rdbms: Rename "memCache" to "memStash" in LBFactory
[mediawiki.git] / tests / phpunit / includes / libs / mime / MimeAnalyzerTest.php
blob64f496049b1f4735bcb0e81a06c24121bf9d0660
1 <?php
2 /*
3 * @group Media
4 * @covers MimeAnalyzer
5 */
6 class MimeMagicTest extends PHPUnit_Framework_TestCase {
7 /** @var MimeAnalyzer */
8 private $mimeAnalyzer;
10 function setUp() {
11 global $IP;
13 $this->mimeAnalyzer = new MimeAnalyzer( [
14 'infoFile' => $IP . "/includes/libs/mime/mime.info",
15 'typeFile' => $IP . "/includes/libs/mime/mime.types",
16 'xmlTypes' => [
17 'http://www.w3.org/2000/svg:svg' => 'image/svg+xml',
18 'svg' => 'image/svg+xml',
19 'http://www.lysator.liu.se/~alla/dia/:diagram' => 'application/x-dia-diagram',
20 'http://www.w3.org/1999/xhtml:html' => 'text/html', // application/xhtml+xml?
21 'html' => 'text/html', // application/xhtml+xml?
23 ] );
24 parent::setUp();
27 function doGuessMimeType( array $parameters = [] ) {
28 $class = new ReflectionClass( get_class( $this->mimeAnalyzer ) );
29 $method = $class->getMethod( 'doGuessMimeType' );
30 $method->setAccessible( true );
31 return $method->invokeArgs( $this->mimeAnalyzer, $parameters );
34 /**
35 * @dataProvider providerImproveTypeFromExtension
36 * @param string $ext File extension (no leading dot)
37 * @param string $oldMime Initially detected MIME
38 * @param string $expectedMime MIME type after taking extension into account
40 function testImproveTypeFromExtension( $ext, $oldMime, $expectedMime ) {
41 $actualMime = $this->mimeAnalyzer->improveTypeFromExtension( $oldMime, $ext );
42 $this->assertEquals( $expectedMime, $actualMime );
45 function providerImproveTypeFromExtension() {
46 return [
47 [ 'gif', 'image/gif', 'image/gif' ],
48 [ 'gif', 'unknown/unknown', 'unknown/unknown' ],
49 [ 'wrl', 'unknown/unknown', 'model/vrml' ],
50 [ 'txt', 'text/plain', 'text/plain' ],
51 [ 'csv', 'text/plain', 'text/csv' ],
52 [ 'tsv', 'text/plain', 'text/tab-separated-values' ],
53 [ 'js', 'text/javascript', 'application/javascript' ],
54 [ 'js', 'application/x-javascript', 'application/javascript' ],
55 [ 'json', 'text/plain', 'application/json' ],
56 [ 'foo', 'application/x-opc+zip', 'application/zip' ],
57 [ 'docx', 'application/x-opc+zip',
58 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' ],
59 [ 'djvu', 'image/x-djvu', 'image/vnd.djvu' ],
60 [ 'wav', 'audio/wav', 'audio/wav' ],
64 /**
65 * Test to make sure that encoder=ffmpeg2theora doesn't trigger
66 * MEDIATYPE_VIDEO (T65584)
68 function testOggRecognize() {
69 $oggFile = __DIR__ . '/../../../data/media/say-test.ogg';
70 $actualType = $this->mimeAnalyzer->getMediaType( $oggFile, 'application/ogg' );
71 $this->assertEquals( MEDIATYPE_AUDIO, $actualType );
74 /**
75 * Test to make sure that Opus audio files don't trigger
76 * MEDIATYPE_MULTIMEDIA (bug T151352)
78 function testOpusRecognize() {
79 $oggFile = __DIR__ . '/../../../data/media/say-test.opus';
80 $actualType = $this->mimeAnalyzer->getMediaType( $oggFile, 'application/ogg' );
81 $this->assertEquals( MEDIATYPE_AUDIO, $actualType );
84 /**
85 * Test to make sure that mp3 files are detected as audio type
87 function testMP3AsAudio() {
88 $file = __DIR__ . '/../../../data/media/say-test-with-id3.mp3';
89 $actualType = $this->mimeAnalyzer->getMediaType( $file );
90 $this->assertEquals( MEDIATYPE_AUDIO, $actualType );
93 /**
94 * Test to make sure that MP3 with id3 tag is recognized
96 function testMP3WithID3Recognize() {
97 $file = __DIR__ . '/../../../data/media/say-test-with-id3.mp3';
98 $actualType = $this->doGuessMimeType( [ $file, 'mp3' ] );
99 $this->assertEquals( 'audio/mpeg', $actualType );
103 * Test to make sure that MP3 without id3 tag is recognized (MPEG-1 sample rates)
105 function testMP3NoID3RecognizeMPEG1() {
106 $file = __DIR__ . '/../../../data/media/say-test-mpeg1.mp3';
107 $actualType = $this->doGuessMimeType( [ $file, 'mp3' ] );
108 $this->assertEquals( 'audio/mpeg', $actualType );
112 * Test to make sure that MP3 without id3 tag is recognized (MPEG-2 sample rates)
114 function testMP3NoID3RecognizeMPEG2() {
115 $file = __DIR__ . '/../../../data/media/say-test-mpeg2.mp3';
116 $actualType = $this->doGuessMimeType( [ $file, 'mp3' ] );
117 $this->assertEquals( 'audio/mpeg', $actualType );
121 * Test to make sure that MP3 without id3 tag is recognized (MPEG-2.5 sample rates)
123 function testMP3NoID3RecognizeMPEG2_5() {
124 $file = __DIR__ . '/../../../data/media/say-test-mpeg2.5.mp3';
125 $actualType = $this->doGuessMimeType( [ $file, 'mp3' ] );
126 $this->assertEquals( 'audio/mpeg', $actualType );