コード例 #1
0
 /**
  * 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);
 }
コード例 #2
0
 /**
  * Test that a base64 encoded string is returned for the specified pathname.
  */
 public function testCreateUploadThumbnailReturnBase64EncodedString()
 {
     $mockEntityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $configuration = new TestFileStorageConfiguration();
     $twigExtension = new ReskumeFileBundleExtension($configuration, $mockEntityManager);
     $file = new File();
     $file->setTmpPathname(TestPathProvider::getPath() . '/Fixtures/files/test_image.jpeg');
     $this->assertEquals(ThumbnailHelper::getBase64Thumb(new HttpFile(TestPathProvider::getPath() . '/Fixtures/files/thumbs/thumb_test_image.jpeg')), $twigExtension->createThumbnailFunction($file));
     $this->assertEquals(ThumbnailHelper::getBase64Thumb(new HttpFile(TestPathProvider::getPath() . '/Fixtures/files/thumbs/thumb_test_image.jpeg')), $twigExtension->createThumbnailFunction($file, 'base64'));
 }
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
0
 /**
  * @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));
 }
コード例 #5
0
 /**
  * Test that method returns a base64 encoded string of the requested thumbnail.
  */
 public function testGetBase64ThumbReturnsBaseEncodedString()
 {
     $mockEntityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $configuration = new TestFileStorageConfiguration();
     $helper = new ThumbnailHelper($configuration, $mockEntityManager);
     $thumbFile = $helper->findThumbnail('test_image.jpeg');
     $this->assertSame(base64_encode(file_get_contents($thumbFile->getPathname())), $helper->getBase64Thumb($thumbFile));
 }