1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?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->getOriginalName());
- }
-
- public function testGetOriginalNameSanitizeFilename()
- {
- $file = new UploadedFile(
- __DIR__.'/Fixtures/test.gif',
- '../../original.gif',
- 'image/gif',
- filesize(__DIR__.'/Fixtures/test.gif'),
- null
- );
- $this->assertEquals('original.gif', $file->getOriginalName());
- }
- }
|