Inheritance: implements Sulu\Component\Persistence\Model\AuditableInterface
Beispiel #1
0
 public function testReturnImage()
 {
     $mediaRepository = $this->prophesize('Sulu\\Bundle\\MediaBundle\\Entity\\MediaRepository');
     $originalStorage = $this->prophesize('Sulu\\Bundle\\MediaBundle\\Media\\Storage\\StorageInterface');
     $formatCache = $this->prophesize('Sulu\\Bundle\\MediaBundle\\Media\\FormatCache\\FormatCacheInterface');
     $converter = $this->prophesize('Sulu\\Bundle\\MediaBundle\\Media\\ImageConverter\\ImageConverterInterface');
     $videoThumbnailService = $this->prophesize('Sulu\\Bundle\\MediaBundle\\Media\\Video\\VideoThumbnailServiceInterface');
     $ghostScriptPath = '';
     $saveImage = true;
     $previewMimeTypes = ['gif'];
     $responseHeaders = [];
     $formats = ['640x480' => ['name' => '640x480', 'commands' => [['action' => 'resize', 'parameters' => ['x' => 640, 'y' => 480]]], 'options' => ['jpeg_quality' => 70, 'png_compression_level' => 6]]];
     $image = $this->prophesize('Imagine\\Image\\ImageInterface');
     $image->strip()->willReturn(null);
     $image->layers()->willReturn(null);
     $image->interlace(ImageInterface::INTERLACE_PLANE)->willReturn(null);
     $image->get('gif', $formats['640x480']['options'])->willReturn('Image-Content');
     $media = new Media();
     $reflection = new \ReflectionClass(get_class($media));
     $property = $reflection->getProperty('id');
     $property->setAccessible(true);
     $property->setValue($media, 1);
     $file = new File();
     $file->setVersion(1);
     $fileVersion = new FileVersion();
     $fileVersion->setVersion(1);
     $fileVersion->setName('dummy.gif');
     $fileVersion->setMimeType('gif');
     $fileVersion->setStorageOptions(['a' => 'b']);
     $file->addFileVersion($fileVersion);
     $media->addFile($file);
     $mediaRepository->findMediaById(1)->willReturn($media);
     $originalStorage->load('dummy.gif', 1, ['a' => 'b'])->willReturn(dirname(__DIR__) . '/../../Fixtures/image/data/dummy.gif');
     $converter->convert(Argument::type('string'), $formats['640x480'])->willReturn($image->reveal());
     $formatCache->save(Argument::type('string'), 1, 'dummy.gif', ['a' => 'b'], '640x480')->willReturn(null);
     $formatManager = new FormatManager($mediaRepository->reveal(), $originalStorage->reveal(), $formatCache->reveal(), $converter->reveal(), $videoThumbnailService->reveal(), $ghostScriptPath, $saveImage, $previewMimeTypes, $responseHeaders, $formats);
     $result = $formatManager->returnImage(1, '640x480');
     $this->assertEquals('Image-Content', $result->getContent());
     $this->assertEquals(200, $result->getStatusCode());
 }
 public function setUpMediaEntities($contact)
 {
     $mediaType = new MediaType();
     $mediaType->setName('document');
     $mediaType->setDescription('This is a document');
     $imageType = new MediaType();
     $imageType->setName('image');
     $imageType->setDescription('This is an image');
     $videoType = new MediaType();
     $videoType->setName('video');
     $videoType->setDescription('This is a video');
     $audioType = new MediaType();
     $audioType->setName('audio');
     $audioType->setDescription('This is an audio');
     $media = new Media();
     $media->setType($imageType);
     $this->media = $media;
     $media2 = new Media();
     $media2->setType($imageType);
     $this->media2 = $media2;
     $contact->addMedia($media2);
     // create file
     $file = new File();
     $file->setVersion(1);
     $file->setMedia($media);
     $file2 = new File();
     $file2->setVersion(1);
     $file2->setMedia($media2);
     // create file version
     $fileVersion = new FileVersion();
     $fileVersion->setVersion(1);
     $fileVersion->setName('photo.jpeg');
     $fileVersion->setMimeType('image/jpg');
     $fileVersion->setFile($file);
     $fileVersion->setSize(1124214);
     $fileVersion->setDownloadCounter(2);
     $fileVersion->setStorageOptions('{"segment":"1","fileName":"photo.jpeg"}');
     $file->addFileVersion($fileVersion);
     // create file version
     $fileVersion = new FileVersion();
     $fileVersion->setVersion(1);
     $fileVersion->setName('photo.jpeg');
     $fileVersion->setMimeType('image/jpg');
     $fileVersion->setFile($file2);
     $fileVersion->setSize(1124214);
     $fileVersion->setDownloadCounter(2);
     $fileVersion->setStorageOptions('{"segment":"1","fileName":"photo.jpeg"}');
     $file2->addFileVersion($fileVersion);
     $collection = new Collection();
     $this->setUpCollection($collection);
     $media->setCollection($collection);
     $media2->setCollection($collection);
     $this->em->persist($media);
     $this->em->persist($media2);
     $this->em->persist($collection);
     $this->em->persist($file);
     $this->em->persist($file2);
     $this->em->persist($videoType);
     $this->em->persist($imageType);
     $this->em->persist($audioType);
     $this->em->persist($mediaType);
 }
 public function initLogo()
 {
     $collectionType = new CollectionType();
     $collectionType->setName('My collection type');
     $this->em->persist($collectionType);
     $collection = new Collection();
     $collection->setType($collectionType);
     $this->em->persist($collection);
     $imageType = new MediaType();
     $imageType->setName('image');
     $imageType->setDescription('This is an image');
     $this->em->persist($imageType);
     $file = new File();
     $file->setVersion(1);
     $fileVersion = new FileVersion();
     $fileVersion->setVersion(1);
     $fileVersion->setName('logo.jpeg');
     $fileVersion->setMimeType('image/jpg');
     $fileVersion->setFile($file);
     $fileVersion->setSize(1124214);
     $fileVersion->setDownloadCounter(2);
     $fileVersion->setChanged(new \DateTime('1937-04-20'));
     $fileVersion->setCreated(new \DateTime('1937-04-20'));
     $file->addFileVersion($fileVersion);
     $this->em->persist($fileVersion);
     $this->logo = new Media();
     $this->logo->setType($imageType);
     $this->logo->setCollection($collection);
     $this->logo->addFile($file);
     $file->setMedia($this->logo);
     $this->em->persist($this->logo);
     $this->em->persist($file);
 }
Beispiel #4
0
 /**
  * Create a new media.
  *
  * @param $data
  * @param $user
  *
  * @return Media
  */
 protected function createMedia($data, $user)
 {
     $mediaEntity = new MediaEntity();
     $mediaEntity->setCreator($user);
     $mediaEntity->setChanger($user);
     $file = new File();
     $file->setCreator($user);
     $file->setChanger($user);
     $file->setVersion(1);
     $file->setMedia($mediaEntity);
     $fileVersion = new FileVersion();
     $fileVersion->setCreator($user);
     $fileVersion->setChanger($user);
     $fileVersion->setVersion(1);
     $fileVersion->setFile($file);
     $file->addFileVersion($fileVersion);
     $mediaEntity->addFile($file);
     $media = new Media($mediaEntity, $data['locale'], null);
     $media = $this->setDataToMedia($media, $data, $user);
     $fileVersion->setDefaultMeta($fileVersion->getMeta()->first());
     $mediaEntity = $media->getEntity();
     $this->em->persist($mediaEntity);
     $this->em->flush();
     return $media;
 }
Beispiel #5
0
 protected function createMedia($id)
 {
     $mediaIdReflection = new \ReflectionProperty(Media::class, 'id');
     $mediaIdReflection->setAccessible(true);
     $media = new Media();
     $mediaIdReflection->setValue($media, $id);
     $file = new File();
     $fileVersion = new FileVersion();
     $fileVersion->setName('Media' . $id);
     $file->addFileVersion($fileVersion);
     $media->addFile($file);
     return $media;
 }
Beispiel #6
0
 protected function createMedia($name)
 {
     $media = new Media();
     $media->setType($this->imageType);
     // create file
     $file = new File();
     $file->setVersion(1);
     $file->setMedia($media);
     // create file version
     $fileVersion = new FileVersion();
     $fileVersion->setVersion(1);
     $fileVersion->setName($name . '.jpeg');
     $fileVersion->setMimeType('image/jpg');
     $fileVersion->setFile($file);
     $fileVersion->setSize(1124214);
     $fileVersion->setDownloadCounter(2);
     $fileVersion->setChanged(new \DateTime('1937-04-20'));
     $fileVersion->setCreated(new \DateTime('1937-04-20'));
     $fileVersion->setStorageOptions('{"segment":"1","fileName":"' . $name . '.jpeg"}');
     if (!file_exists(__DIR__ . '/../../uploads/media/1')) {
         mkdir(__DIR__ . '/../../uploads/media/1', 0777, true);
     }
     copy($this->getImagePath(), __DIR__ . '/../../uploads/media/1/' . $name . '.jpeg');
     // create meta
     $fileVersionMeta = new FileVersionMeta();
     $fileVersionMeta->setLocale('en-gb');
     $fileVersionMeta->setTitle($name);
     $fileVersionMeta->setDescription($this->mediaDefaultDescription);
     $fileVersionMeta->setFileVersion($fileVersion);
     $fileVersion->addMeta($fileVersionMeta);
     $fileVersion->setDefaultMeta($fileVersionMeta);
     $file->addFileVersion($fileVersion);
     $media->addFile($file);
     $media->setCollection($this->collection);
     $this->em->persist($media);
     $this->em->persist($file);
     $this->em->persist($fileVersionMeta);
     $this->em->persist($fileVersion);
     $this->em->flush();
     return $media;
 }
 private function createFile($oldTitle, $newTitle, $collection = null)
 {
     $media = new Media();
     $media->setType($this->mediaType);
     $media->setCollection($collection ?: $this->collection);
     $file = new File();
     $file->setVersion(2);
     $file->setMedia($media);
     $this->createFileVersion($file, $oldTitle, 1);
     $this->createFileVersion($file, $newTitle, 2);
     $this->em->persist($file);
     $this->em->persist($media);
 }