UploadedFileTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\HttpFoundation\File;
  11. use Symfony\Component\HttpFoundation\File\UploadedFile;
  12. class UploadedFileTest extends \PHPUnit_Framework_TestCase
  13. {
  14. protected function setUp()
  15. {
  16. if (!ini_get('file_uploads')) {
  17. $this->markTestSkipped('file_uploads is disabled in php.ini');
  18. }
  19. }
  20. public function testFileUploadsWithNoMimeType()
  21. {
  22. $file = new UploadedFile(
  23. __DIR__.'/Fixtures/test.gif',
  24. 'original.gif',
  25. null,
  26. filesize(__DIR__.'/Fixtures/test.gif'),
  27. UPLOAD_ERR_OK
  28. );
  29. $this->assertAttributeEquals('application/octet-stream', 'mimeType', $file);
  30. $this->assertEquals('image/gif', $file->getMimeType());
  31. }
  32. public function testFileUploadsWithUnknownMimeType()
  33. {
  34. $file = new UploadedFile(
  35. __DIR__.'/Fixtures/.unknownextension',
  36. 'original.gif',
  37. null,
  38. filesize(__DIR__.'/Fixtures/.unknownextension'),
  39. UPLOAD_ERR_OK
  40. );
  41. $this->assertAttributeEquals('application/octet-stream', 'mimeType', $file);
  42. $this->assertEquals('application/octet-stream', $file->getMimeType());
  43. }
  44. public function testErrorIsOkByDefault()
  45. {
  46. $file = new UploadedFile(
  47. __DIR__.'/Fixtures/test.gif',
  48. 'original.gif',
  49. 'image/gif',
  50. filesize(__DIR__.'/Fixtures/test.gif'),
  51. null
  52. );
  53. $this->assertEquals(UPLOAD_ERR_OK, $file->getError());
  54. }
  55. public function testGetOriginalName()
  56. {
  57. $file = new UploadedFile(
  58. __DIR__.'/Fixtures/test.gif',
  59. 'original.gif',
  60. 'image/gif',
  61. filesize(__DIR__.'/Fixtures/test.gif'),
  62. null
  63. );
  64. $this->assertEquals('original.gif', $file->getName());
  65. }
  66. }