Changed mime detection to be case insensitive

This commit is contained in:
Marcin Kurczewski 2014-09-20 15:10:16 +02:00
parent a3f9382671
commit fbdb4e5128
2 changed files with 42 additions and 3 deletions

View file

@ -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)

View file

@ -0,0 +1,39 @@
<?php
namespace Szurubooru\Tests\Helpers;
class MimeHelperTest extends \Szurubooru\Tests\AbstractTestCase
{
public function testGettingMime()
{
$expected = 'image/jpeg';
$actual = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromBuffer($this->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'));
}
}