Commit 60d287c3 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

MimeTypeIcon: ajout de tests.

Showing with 42 additions and 1 deletion
+42 -1
<?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'],
];
}
}
......@@ -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];
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment