Merge "Improve MIME detection in FileBackend"
[lhc/web/wiklou.git] / tests / phpunit / includes / filebackend / FileBackendTest.php
index e7d092f..95c6092 100644 (file)
@@ -2397,6 +2397,42 @@ class FileBackendTest extends MediaWikiTestCase {
                        "Scoped unlocking of files succeeded with OK status ($backendName)." );
        }
 
+       /**
+        * @dataProvider provider_testGetContentType
+        */
+       public function testGetContentType( $mimeCallback, $mimeFromString ) {
+               global $IP;
+
+               $be = TestingAccessWrapper::newFromObject( new MemoryFileBackend(
+                       array(
+                               'name' => 'testing',
+                               'class' => 'MemoryFileBackend',
+                               'wikiId' => 'meow',
+                               'mimeCallback' => $mimeCallback
+                       )
+               ) );
+
+               $dst = 'mwstore://testing/container/path/to/file_no_ext';
+               $src = "$IP/tests/phpunit/data/media/srgb.jpg";
+               $this->assertEquals( 'image/jpeg', $be->getContentType( $dst, null, $src ) );
+               $this->assertEquals(
+                       $mimeFromString ? 'image/jpeg' : 'unknown/unknown',
+                       $be->getContentType( $dst, file_get_contents( $src ), null ) );
+
+               $src = "$IP/tests/phpunit/data/media/Png-native-test.png";
+               $this->assertEquals( 'image/png', $be->getContentType( $dst, null, $src ) );
+               $this->assertEquals(
+                       $mimeFromString ? 'image/png' : 'unknown/unknown',
+                       $be->getContentType( $dst, file_get_contents( $src ), null ) );
+       }
+
+       public static function provider_testGetContentType() {
+               return array(
+                       array( null, false ),
+                       array( array( FileBackendGroup::singleton(), 'guessMimeInternal' ), true )
+               );
+       }
+
        public function testReadAffinity() {
                $be = TestingAccessWrapper::newFromObject(
                        new FileBackendMultiWrite( array(