diff --git a/src/Helpers/MimeHelper.php b/src/Helpers/MimeHelper.php index 5c538bdc..c1eaa4ed 100644 --- a/src/Helpers/MimeHelper.php +++ b/src/Helpers/MimeHelper.php @@ -17,17 +17,17 @@ class MimeHelper public static function isFlash($mime) { - return $mime === 'application/x-shockwave-flash'; + return strtolower($mime) === 'application/x-shockwave-flash'; } public static function isVideo($mime) { - return $mime === 'application/ogg' or preg_match('/video\//', $mime); + return strtolower($mime) === 'application/ogg' or preg_match('/video\//i', $mime); } public static function isImage($mime) { - return in_array($mime, ['image/jpeg', 'image/png', 'image/gif']); + return in_array(strtolower($mime), ['image/jpeg', 'image/png', 'image/gif']); } private static function stripCharset($mime) diff --git a/tests/Helpers/MimeHelperTest.php b/tests/Helpers/MimeHelperTest.php new file mode 100644 index 00000000..17285705 --- /dev/null +++ b/tests/Helpers/MimeHelperTest.php @@ -0,0 +1,39 @@ +getTestFile('image.jpg')); + $this->assertEquals($expected, $actual); + } + + public function testIsFlash() + { + $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isFlash('application/x-shockwave-flash')); + $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isFlash('APPLICATION/X-SHOCKWAVE-FLASH')); + $this->assertFalse(\Szurubooru\Helpers\MimeHelper::isFlash('something else')); + } + + public function testIsImage() + { + $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isImage('IMAGE/JPEG')); + $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isImage('IMAGE/PNG')); + $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isImage('IMAGE/GIF')); + $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isImage('image/jpeg')); + $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isImage('image/png')); + $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isImage('image/gif')); + $this->assertFalse(\Szurubooru\Helpers\MimeHelper::isImage('something else')); + } + + public function testIsVideo() + { + $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isVideo('VIDEO/MP4')); + $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isVideo('video/mp4')); + $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isVideo('APPLICATION/OGG')); + $this->assertTrue(\Szurubooru\Helpers\MimeHelper::isVideo('application/ogg')); + $this->assertFalse(\Szurubooru\Helpers\MimeHelper::isVideo('something else')); + } +}