partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit dfbaa4a8e301faec2a22b01e2ad6cca6b0124866
parent 01dece36f7b2ec27d2122a089c5674973a96ea67
Author: Felicitus <felicitus@felicitus.org>
Date:   Sun, 13 Sep 2015 16:49:51 +0200

Added functional tests for retrieving the file contents and the mimetype icon

Diffstat:
Msrc/PartKeepr/UploadedFileBundle/Controller/FileController.php | 2+-
Asrc/PartKeepr/UploadedFileBundle/Tests/FileControllerTest.php | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 81 insertions(+), 1 deletion(-)

diff --git a/src/PartKeepr/UploadedFileBundle/Controller/FileController.php b/src/PartKeepr/UploadedFileBundle/Controller/FileController.php @@ -15,7 +15,7 @@ abstract class FileController extends Controller * * @return string */ - public function getFilename(UploadedFile $file) + protected function getFilename(UploadedFile $file) { $storageDirectory = $this->get("partkeepr_uploadedfile_service")->getStorageDirectory($file); diff --git a/src/PartKeepr/UploadedFileBundle/Tests/FileControllerTest.php b/src/PartKeepr/UploadedFileBundle/Tests/FileControllerTest.php @@ -0,0 +1,80 @@ +<?php +namespace PartKeepr\UploadedFileBundle\Tests; + + +use Liip\FunctionalTestBundle\Test\WebTestCase; +use Symfony\Component\HttpFoundation\File\UploadedFile; + +class FileControllerTest extends WebTestCase +{ + public function testMimeType () { + $client = static::createClient(); + + $file = __DIR__."/Fixtures/files/uploadtest.png"; + $originalFilename = 'uploadtest.png'; + $mimeType = "image/png"; + + $image = new UploadedFile( + $file, + $originalFilename, + $mimeType, + filesize($file) + ); + + $client->request( + 'POST', + '/api/temp_uploaded_files/upload', + array(), + array('userfile' => $image) + ); + + $response = json_decode($client->getResponse()->getContent()); + + $property = "@id"; + $uri = $response->image->$property; + $uri .= "/getMimeTypeIcon"; + + $client->request( + 'GET', + $uri + ); + + $this->assertEquals("image/svg+xml", $client->getResponse()->headers->get("Content-Type")); + } + + public function testGetFile () { + $client = static::createClient(); + + $file = __DIR__."/Fixtures/files/uploadtest.png"; + $originalFilename = 'uploadtest.png'; + $mimeType = "image/png"; + + $image = new UploadedFile( + $file, + $originalFilename, + $mimeType, + filesize($file) + ); + + $client->request( + 'POST', + '/api/temp_uploaded_files/upload', + array(), + array('userfile' => $image) + ); + + $response = json_decode($client->getResponse()->getContent()); + + $property = "@id"; + $uri = $response->image->$property; + $uri .= "/getFile"; + + $client->request( + 'GET', + $uri + ); + + $this->assertEquals("image/png", $client->getResponse()->headers->get("Content-Type")); + $this->assertEquals(file_get_contents($file), $client->getResponse()->getContent()); + } +}