[HttpFoundation][File][UploadedFile] Fix guessClientExtension() method

This commit is contained in:
alexpods 2013-05-09 19:23:25 +04:00 committed by Fabien Potencier
parent 7fc0768b48
commit be42dbc82a
2 changed files with 28 additions and 1 deletions

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\HttpFoundation\File;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser;
/**
* A file uploaded through a form.
@ -170,7 +171,7 @@ class UploadedFile extends File
*/
public function guessClientExtension()
{
$type = $this->getMimeType();
$type = $this->getClientMimeType();
$guesser = ExtensionGuesser::getInstance();
return $guesser->guess($type);

View File

@ -63,6 +63,32 @@ class UploadedFileTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('application/octet-stream', $file->getClientMimeType());
}
public function testGuessClientExtension()
{
$file = new UploadedFile(
__DIR__.'/Fixtures/test.gif',
'original.gif',
'image/gif',
filesize(__DIR__.'/Fixtures/test.gif'),
null
);
$this->assertEquals('gif', $file->guessClientExtension());
}
public function testGuessClientExtensionWithIncorrectMimeType()
{
$file = new UploadedFile(
__DIR__.'/Fixtures/test.gif',
'original.gif',
'image/jpeg',
filesize(__DIR__.'/Fixtures/test.gif'),
null
);
$this->assertEquals('jpeg', $file->guessClientExtension());
}
public function testErrorIsOkByDefault()
{
$file = new UploadedFile(