/**
  * Test that method only processes supported image formats.
  */
 public function testCreateThumbnailDoesNotProcessUnsupportedImageFormats()
 {
     $mockEntityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $mockFile = $this->getMockBuilder('Reskume\\FileBundle\\Entity\\File')->getMock();
     $mockFile->expects($this->once())->method('getMimeType')->willReturn('plain/text');
     $mockStorage = $this->getMockBuilder('Reskume\\FileBundle\\Storage\\FileStorageInterface')->disableOriginalConstructor()->getMock();
     $mockStorage->expects($this->once())->method('getFile')->with('/pathname')->willReturn($mockFile);
     $mockStorage->expects($this->once())->method('getContent')->willReturn('file content');
     $mockConfiguration = $this->getMockBuilder('Reskume\\FileBundle\\Storage\\FileStorageConfigurationInterface')->disableOriginalConstructor()->getMock();
     $mockConfiguration->expects($this->once())->method('createFileStorage')->with($mockEntityManager)->willReturn($mockStorage);
     $helper = new ThumbnailHelper($mockConfiguration, $mockEntityManager);
     $this->assertFalse($helper->createScaledThumb('/pathname', 50));
 }
 /**
  * Test that expected thumbnail is created.
  */
 public function testThumbnailCreation()
 {
     $container = static::$kernel->getContainer();
     $fileStorageConfiguration = $container->get('reskume_file.configuration.file_storage_configuration');
     $entityManager = $container->get('doctrine.orm.entity_manager');
     $thumbnailHelper = new ThumbnailHelper($fileStorageConfiguration, $entityManager);
     $thumb = $thumbnailHelper->createScaledThumb(TestPathProvider::getPath() . '/Fixtures/files/test_image.jpeg', 50);
     $this->assertFileExists($thumb->getPathname());
     $thumbBase64Value = $thumbnailHelper->getBase64Thumb($thumb);
     // get base64 value of fixture test thumbnail
     $testThumb = new File(TestPathProvider::getPath() . '/Fixtures/files/thumbs/thumb_test_image_50px.jpeg');
     $expectedThumbBase64Value = $thumbnailHelper->getBase64Thumb($thumb);
     $this->assertEquals($expectedThumbBase64Value, $thumbBase64Value);
 }
 /**
  * Creates either image url or a base64 encoded thumbnail for an uploaded image and returns the value.
  *
  * @param mixed  $value  expects a Reskume\FileBundle\Entity\File entity
  * @param string $output define the output type. May be 'base64' or 'url'. Defaults to 'base64'.
  *
  * @return string
  */
 public function createThumbnailFunction($value, $output = 'base64')
 {
     if (!$value instanceof File) {
         return null;
     }
     $thumbHelper = new ThumbnailHelper($this->configuration, $this->entityManager);
     $pathname = $value->isTmpFile() ? $value->getTmpPathname() : $value->getKey();
     $thumbFile = $thumbHelper->createScaledThumb($pathname, 50);
     switch ($output) {
         case 'url':
             $retVal = $thumbFile->getPathname();
             break;
         default:
         case 'base64':
             $retVal = ThumbnailHelper::getBase64Thumb($thumbFile);
             break;
     }
     // @codeCoverageIgnore
     return $retVal === null ? null : $retVal;
 }
 /**
  * @return string
  */
 private function renderResponseContent()
 {
     if (empty($this->uploadedFile) || $this->error) {
         return null;
     }
     $metaArr = array();
     $thumbHelper = new ThumbnailHelper($this->configuration, $this->entityManager);
     foreach ($this->uploadedFile as $file) {
         $basename = $file->getBaseName();
         $tmpPathname = $file->getPathname();
         $thumbFile = $thumbHelper->createScaledThumb($tmpPathname, 50);
         $base64Thumb = $thumbHelper->getBase64Thumb($thumbFile);
         $this->attachmentIndex++;
         // @important increment by one
         $metaArr[$basename] = array('key' => $this->attachmentIndex, 'tmpPathname' => $tmpPathname, 'origFilename' => $this->uploadedFile[$basename]->getClientOriginalName(), 'thumbnail' => $base64Thumb);
     }
     return $this->uploadRenderer->renderTemplate(array('formName' => $this->formName, 'formId' => $this->formId, 'metadata' => $metaArr));
 }