[HttpFoundation][File][UploadedFile] Fix guessClientExtension() method
This commit is contained in:
parent
7fc0768b48
commit
be42dbc82a
|
@ -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);
|
||||
|
|
|
@ -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(
|
||||
|
|
Reference in New Issue