12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?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('test.gif', $file->getName());
- }
- }
|