MediaWiki REL1_30
MimeAnalyzerTest.php
Go to the documentation of this file.
1<?php
2/*
3 * @group Media
4 * @covers MimeAnalyzer
5 */
6class MimeMagicTest extends PHPUnit_Framework_TestCase {
8 private $mimeAnalyzer;
9
10 function setUp() {
11 global $IP;
12
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?
22 ]
23 ] );
24 parent::setUp();
25 }
26
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 );
32 }
33
40 function testImproveTypeFromExtension( $ext, $oldMime, $expectedMime ) {
41 $actualMime = $this->mimeAnalyzer->improveTypeFromExtension( $oldMime, $ext );
42 $this->assertEquals( $expectedMime, $actualMime );
43 }
44
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' ],
61 ];
62 }
63
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 );
72 }
73
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 );
82 }
83
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 );
91 }
92
97 $file = __DIR__ . '/../../../data/media/say-test-with-id3.mp3';
98 $actualType = $this->doGuessMimeType( [ $file, 'mp3' ] );
99 $this->assertEquals( 'audio/mpeg', $actualType );
100 }
101
106 $file = __DIR__ . '/../../../data/media/say-test-mpeg1.mp3';
107 $actualType = $this->doGuessMimeType( [ $file, 'mp3' ] );
108 $this->assertEquals( 'audio/mpeg', $actualType );
109 }
110
115 $file = __DIR__ . '/../../../data/media/say-test-mpeg2.mp3';
116 $actualType = $this->doGuessMimeType( [ $file, 'mp3' ] );
117 $this->assertEquals( 'audio/mpeg', $actualType );
118 }
119
124 $file = __DIR__ . '/../../../data/media/say-test-mpeg2.5.mp3';
125 $actualType = $this->doGuessMimeType( [ $file, 'mp3' ] );
126 $this->assertEquals( 'audio/mpeg', $actualType );
127 }
128}
MimeAnalyzer $mimeAnalyzer
testMP3NoID3RecognizeMPEG2()
Test to make sure that MP3 without id3 tag is recognized (MPEG-2 sample rates)
doGuessMimeType(array $parameters=[])
testOggRecognize()
Test to make sure that encoder=ffmpeg2theora doesn't trigger MEDIATYPE_VIDEO (T65584)
testMP3NoID3RecognizeMPEG2_5()
Test to make sure that MP3 without id3 tag is recognized (MPEG-2.5 sample rates)
testMP3NoID3RecognizeMPEG1()
Test to make sure that MP3 without id3 tag is recognized (MPEG-1 sample rates)
testOpusRecognize()
Test to make sure that Opus audio files don't trigger MEDIATYPE_MULTIMEDIA (bug T151352)
testMP3AsAudio()
Test to make sure that mp3 files are detected as audio type.
testMP3WithID3Recognize()
Test to make sure that MP3 with id3 tag is recognized.
testImproveTypeFromExtension( $ext, $oldMime, $expectedMime)
providerImproveTypeFromExtension
$IP
Definition update.php:3
const MEDIATYPE_AUDIO
Definition defines.php:32