From: Thiemo Mättig Date: Sun, 26 Mar 2017 16:08:06 +0000 (+0200) Subject: Add tests for CSSMin::getMimeType X-Git-Tag: 1.31.0-rc.0~3687^2 X-Git-Url: http://git.cyclocoop.org/%22.%20generer_url_ecrire%28%22sites_tous%22%2C%22%22%29.%20%22?a=commitdiff_plain;h=549c1f6dd79617663cfa04c500964f911cce23e7;p=lhc%2Fweb%2Fwiklou.git Add tests for CSSMin::getMimeType Direct follow up for I1768646. The tests are copied from my patch If985f33, with one important difference: Now the file extension always wins. Mismatches are not fixed any more by this code. This is intended. See the discussion at I1768646. Change-Id: I06b873a808d58ae7e53272765b156ac0fa293c2c --- diff --git a/tests/phpunit/includes/libs/CSSMinTest.php b/tests/phpunit/includes/libs/CSSMinTest.php index 2e5c0bb429..42f08cc0a0 100644 --- a/tests/phpunit/includes/libs/CSSMinTest.php +++ b/tests/phpunit/includes/libs/CSSMinTest.php @@ -18,6 +18,81 @@ class CSSMinTest extends MediaWikiTestCase { ] ); } + /** + * @dataProvider mimeTypeProvider + */ + public function testGetMimeType( $fileContents, $fileExtension, $expected ) { + $fileName = wfTempDir() . DIRECTORY_SEPARATOR . uniqid( 'MW_PHPUnit_CSSMinTest_' ) . '.' + . $fileExtension; + $this->addTmpFiles( $fileName ); + file_put_contents( $fileName, $fileContents ); + $this->assertSame( $expected, CSSMin::getMimeType( $fileName ) ); + } + + public function mimeTypeProvider() { + return [ + 'JPEG with short extension' => [ + "\xFF\xD8\xFF", + 'jpg', + 'image/jpeg' + ], + 'JPEG with long extension' => [ + "\xFF\xD8\xFF", + 'jpeg', + 'image/jpeg' + ], + 'PNG' => [ + "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A", + 'png', + 'image/png' + ], + + 'PNG extension but JPEG content' => [ + "\xFF\xD8\xFF", + 'png', + 'image/png' + ], + 'JPEG extension but PNG content' => [ + "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A", + 'jpg', + 'image/jpeg' + ], + 'PNG extension but SVG content' => [ + '', + 'png', + 'image/png' + ], + 'SVG extension but PNG content' => [ + "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A", + 'svg', + 'image/svg+xml' + ], + + 'SVG with all headers' => [ + '', + 'svg', + 'image/svg+xml' + ], + 'SVG with XML header only' => [ + '', + 'svg', + 'image/svg+xml' + ], + 'SVG with DOCTYPE only' => [ + '', + 'svg', + 'image/svg+xml' + ], + 'SVG without any header' => [ + '', + 'svg', + 'image/svg+xml' + ], + ]; + } + /** * @dataProvider provideMinifyCases * @covers CSSMin::minify