/**
  * Test that file content is returned.
  */
 public function testFileNoDownload()
 {
     $container = static::$kernel->getContainer();
     $repoAttachment = $this->em->getRepository('Reskume\\FileBundle\\Tests\\App\\Entity\\TestAttachment');
     $attachmentFactory = new AttachmentFactory();
     $attachment = $attachmentFactory->create();
     $this->em->persist($attachment);
     $this->em->flush();
     $this->em->clear();
     $result = $repoAttachment->findAll();
     $result = $result[0];
     $file = $result->getFile();
     $key = $file->getKey();
     $fileController = new FileController();
     $fileController->setContainer($container);
     $request = new Request(array(), array('download' => 'false'), array(), array(), array(), array(), $content = null);
     $response = $fileController->downloadAction($request, $key);
     // test that HTTP code is 200
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertSame("test\n", $response->getContent());
     // check headers
     $headers = $response->headers;
     $this->assertSame('text/plain', $headers->get('content-type'));
     $this->assertNull($headers->get('content-disposition'));
 }
 /**
  *  Test if entity persistence and removal is handled correctly.
  */
 public function testPersistenceAndRemoval()
 {
     $repoFile = $this->em->getRepository('ReskumeFileBundle:File');
     $repoAttachment = $this->em->getRepository('Reskume\\FileBundle\\Tests\\App\\Entity\\TestAttachment');
     $attachmentFactory = new AttachmentFactory();
     $attachment = $attachmentFactory->create();
     // test only one entry in database table
     $this->em->persist($attachment);
     $this->em->flush();
     $result = $repoAttachment->findAll();
     $this->assertCount(1, $result);
     $result = $repoFile->findAll();
     $this->assertCount(1, $result);
     // @important clear em and refetch entity to suppress foreign key mapping errors
     $this->em->clear();
     $result = $repoAttachment->findAll();
     $result = $result[0];
     // test correct removal
     $this->em->remove($result);
     $this->em->flush();
     $result = $repoAttachment->findAll();
     $this->assertEmpty($result);
     $result = $repoFile->findAll();
     $this->assertEmpty($result);
 }