Merge "RCFilters: Clean up focus handling in capsule widget"
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / mime / MimeAnalyzerTest.php
1 <?php
2 class MimeMagicTest extends PHPUnit_Framework_TestCase {
3 /** @var MimeAnalyzer */
4 private $mimeAnalyzer;
5
6 function setUp() {
7 global $IP;
8
9 $this->mimeAnalyzer = new MimeAnalyzer( [
10 'infoFile' => $IP . "/includes/libs/mime/mime.info",
11 'typeFile' => $IP . "/includes/libs/mime/mime.types",
12 'xmlTypes' => [
13 'http://www.w3.org/2000/svg:svg' => 'image/svg+xml',
14 'svg' => 'image/svg+xml',
15 'http://www.lysator.liu.se/~alla/dia/:diagram' => 'application/x-dia-diagram',
16 'http://www.w3.org/1999/xhtml:html' => 'text/html', // application/xhtml+xml?
17 'html' => 'text/html', // application/xhtml+xml?
18 ]
19 ] );
20 parent::setUp();
21 }
22
23 /**
24 * @dataProvider providerImproveTypeFromExtension
25 * @param string $ext File extension (no leading dot)
26 * @param string $oldMime Initially detected MIME
27 * @param string $expectedMime MIME type after taking extension into account
28 */
29 function testImproveTypeFromExtension( $ext, $oldMime, $expectedMime ) {
30 $actualMime = $this->mimeAnalyzer->improveTypeFromExtension( $oldMime, $ext );
31 $this->assertEquals( $expectedMime, $actualMime );
32 }
33
34 function providerImproveTypeFromExtension() {
35 return [
36 [ 'gif', 'image/gif', 'image/gif' ],
37 [ 'gif', 'unknown/unknown', 'unknown/unknown' ],
38 [ 'wrl', 'unknown/unknown', 'model/vrml' ],
39 [ 'txt', 'text/plain', 'text/plain' ],
40 [ 'csv', 'text/plain', 'text/csv' ],
41 [ 'tsv', 'text/plain', 'text/tab-separated-values' ],
42 [ 'js', 'text/javascript', 'application/javascript' ],
43 [ 'js', 'application/x-javascript', 'application/javascript' ],
44 [ 'json', 'text/plain', 'application/json' ],
45 [ 'foo', 'application/x-opc+zip', 'application/zip' ],
46 [ 'docx', 'application/x-opc+zip',
47 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' ],
48 [ 'djvu', 'image/x-djvu', 'image/vnd.djvu' ],
49 [ 'wav', 'audio/wav', 'audio/wav' ],
50 ];
51 }
52
53 /**
54 * Test to make sure that encoder=ffmpeg2theora doesn't trigger
55 * MEDIATYPE_VIDEO (bug 63584)
56 */
57 function testOggRecognize() {
58 $oggFile = __DIR__ . '/../../../data/media/say-test.ogg';
59 $actualType = $this->mimeAnalyzer->getMediaType( $oggFile, 'application/ogg' );
60 $this->assertEquals( $actualType, MEDIATYPE_AUDIO );
61 }
62
63 /**
64 * Test to make sure that Opus audio files don't trigger
65 * MEDIATYPE_MULTIMEDIA (bug T151352)
66 */
67 function testOpusRecognize() {
68 $oggFile = __DIR__ . '/../../../data/media/say-test.opus';
69 $actualType = $this->mimeAnalyzer->getMediaType( $oggFile, 'application/ogg' );
70 $this->assertEquals( $actualType, MEDIATYPE_AUDIO );
71 }
72 }