0199b5c70d
Didn't test for presence of mime_content_type function since it's obsolete (deprecated) in PHP5
83 lines
2.2 KiB
PHP
83 lines
2.2 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Symfony package.
|
|
*
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Symfony\Tests\Component\HttpFoundation\File;
|
|
|
|
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
|
|
|
class UploadedFileTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
protected function setUp()
|
|
{
|
|
if (!ini_get('file_uploads')) {
|
|
$this->markTestSkipped('file_uploads is disabled in php.ini');
|
|
}
|
|
}
|
|
|
|
public function testFileUploadsWithNoMimeType()
|
|
{
|
|
$file = new UploadedFile(
|
|
__DIR__.'/Fixtures/test.gif',
|
|
'original.gif',
|
|
null,
|
|
filesize(__DIR__.'/Fixtures/test.gif'),
|
|
UPLOAD_ERR_OK
|
|
);
|
|
|
|
$this->assertAttributeEquals('application/octet-stream', 'mimeType', $file);
|
|
if (extension_loaded('fileinfo')) {
|
|
$this->assertEquals('image/gif', $file->getMimeType());
|
|
} else {
|
|
$this->assertEquals('application/octet-stream', $file->getMimeType());
|
|
}
|
|
}
|
|
|
|
public function testFileUploadsWithUnknownMimeType()
|
|
{
|
|
$file = new UploadedFile(
|
|
__DIR__.'/Fixtures/.unknownextension',
|
|
'original.gif',
|
|
null,
|
|
filesize(__DIR__.'/Fixtures/.unknownextension'),
|
|
UPLOAD_ERR_OK
|
|
);
|
|
|
|
$this->assertAttributeEquals('application/octet-stream', 'mimeType', $file);
|
|
$this->assertEquals('application/octet-stream', $file->getMimeType());
|
|
}
|
|
|
|
public function testErrorIsOkByDefault()
|
|
{
|
|
$file = new UploadedFile(
|
|
__DIR__.'/Fixtures/test.gif',
|
|
'original.gif',
|
|
'image/gif',
|
|
filesize(__DIR__.'/Fixtures/test.gif'),
|
|
null
|
|
);
|
|
|
|
$this->assertEquals(UPLOAD_ERR_OK, $file->getError());
|
|
}
|
|
|
|
public function testGetOriginalName()
|
|
{
|
|
$file = new UploadedFile(
|
|
__DIR__.'/Fixtures/test.gif',
|
|
'original.gif',
|
|
'image/gif',
|
|
filesize(__DIR__.'/Fixtures/test.gif'),
|
|
null
|
|
);
|
|
|
|
$this->assertEquals('original.gif', $file->getName());
|
|
}
|
|
}
|