From 60d287c3de0e14082549edf91b312c079abff346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20Perr=C3=A9al?= <guillaume.perreal@irstea.fr> Date: Wed, 4 Feb 2015 16:31:48 +0100 Subject: [PATCH] MimeTypeIcon: ajout de tests. --- Tests/Utils/MimeTypeIconTest.php | 38 ++++++++++++++++++++++++++++++++ Utils/MimeTypeIcon.php | 5 ++++- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 Tests/Utils/MimeTypeIconTest.php diff --git a/Tests/Utils/MimeTypeIconTest.php b/Tests/Utils/MimeTypeIconTest.php new file mode 100644 index 00000000..6b3f9bdd --- /dev/null +++ b/Tests/Utils/MimeTypeIconTest.php @@ -0,0 +1,38 @@ +<?php + +namespace Irstea\FileUploadBundle\Tests\Utils; + +use Irstea\FileUploadBundle\Utils\MimeTypeIcon; +use PHPUnit_Framework_TestCase; + +/** + * Generated by PHPUnit_SkeletonGenerator on 2015-02-04 at 11:13:27. + */ +class MimeTypeIconTest extends PHPUnit_Framework_TestCase +{ + /** + * @covers Irstea\FileUploadBundle\Utils\MimeTypeIcon::getMimeTypeIcon + * @dataProvider getTestValues + */ + public function testGetMimeTypeIcon($expected, $input) + { + $this->assertEquals($expected, MimeTypeIcon::getMimeTypeIcon($input)); + } + + public function getTestValues() + { + return [ + [null, ''], + [null, []], + ['audio', 'audio/mpeg'], + ['text', 'text/plain'], + ['video', 'video/mpeg'], + ['image', 'image/png'], + ['pdf', 'application/pdf'], + ['archive', 'application/zip'], + ['text', 'text/plain; charset=UTF-8'], + ['archive', 'application/zip; format=lzh'], + ]; + } + +} diff --git a/Utils/MimeTypeIcon.php b/Utils/MimeTypeIcon.php index e14a824a..716889a6 100644 --- a/Utils/MimeTypeIcon.php +++ b/Utils/MimeTypeIcon.php @@ -15,7 +15,6 @@ namespace Irstea\FileUploadBundle\Utils; final class MimeTypeIcon { private static $icons = [ - 'application/x-gzip' => 'zip', 'application/vnd.oasis.opendocument.text' => 'word', 'application/vnd.oasis.opendocument.spreadsheet' => 'excel', 'application/vnd.oasis.opendocument.presentation' => 'powerpoint', @@ -45,6 +44,10 @@ final class MimeTypeIcon return null; } + if(false !== $sep = strpos($mimeType, ';')) { + $mimeType = trim(substr($mimeType, 0, $sep)); + } + if(isset(self::$icons[$mimeType])) { return self::$icons[$mimeType]; } -- GitLab