Inheritance: implements Sulu\Bundle\MediaBundle\Media\Manager\MediaManagerInterface
Example #1
0
 /**
  * @dataProvider provideGetByIds
  */
 public function testGetByIds($ids, $media, $result)
 {
     $this->mediaRepository->findMedia(Argument::any())->willReturn($media);
     $this->formatManager->getFormats(Argument::cetera())->willReturn(null);
     $medias = $this->mediaManager->getByIds($ids, 'en');
     for ($i = 0; $i < count($medias); ++$i) {
         $this->assertEquals($result[$i]->getId(), $medias[$i]->getId());
     }
 }
Example #2
0
 /**
  * @{inheritdoc}
  */
 public function handle(FormInterface $form, $attributes = array())
 {
     if (!$form->isValid()) {
         return false;
     }
     $mediaIds = [];
     if ($form->has('files')) {
         $files = $form['files']->getData();
         if (count($files)) {
             $type = $this->formExtension->getType($form->getName());
             $collectionId = $type->getCollectionId();
             $ids = [];
             /** @var UploadedFile $file */
             foreach ($form['files']->getData() as $file) {
                 if ($file instanceof UploadedFile) {
                     $media = $this->mediaManager->save($file, ['collection' => $collectionId, 'locale' => $form->get('locale')->getData(), 'title' => $file->getClientOriginalName()], null);
                     $ids[] = $media->getId();
                 }
             }
             $mediaIds['files'] = $ids;
         }
     }
     $attributes['form'] = $form;
     $this->saveForm($form, $attributes, $mediaIds);
     $type = $this->formExtension->getType($form->getName());
     if ($type instanceof TypeInterface) {
         $this->sendMails($type, $attributes, $form);
     }
     return true;
 }
 /**
  * @param Event $event
  * @param $mediaData
  * @param $locale
  * @return bool
  * @throws EventDependencyNotFoundException
  * @throws \Sulu\Bundle\MediaBundle\Media\Exception\MediaNotFoundException
  */
 protected function addMedia(Event $event, $mediaData, $locale)
 {
     $media = $this->mediaManager->getById($mediaData, $locale);
     if (!$media) {
         throw new EventDependencyNotFoundException(MediaManager::ENTITY_NAME_MEDIA, $mediaData);
     }
     $media = $media->getEntity();
     $event->addMedia($media);
     $this->entityManager->persist($media);
     return true;
 }
Example #4
0
 /**
  * @dataProvider provideSpecialCharacterFileName
  */
 public function testSpecialCharacterFileName($fileName, $cleanUpArgument)
 {
     /** @var UploadedFile $uploadedFile */
     $uploadedFile = $this->prophesize(UploadedFile::class)->willBeConstructedWith(['', 1, null, null, 1, true]);
     $uploadedFile->getClientOriginalName()->willReturn($fileName);
     $uploadedFile->getPathname()->willReturn('');
     $uploadedFile->getSize()->willReturn('123');
     $uploadedFile->getMimeType()->willReturn('img');
     $user = $this->prophesize(User::class)->willImplement(UserInterface::class);
     $this->userRepository->findUserById(1)->willReturn($user);
     $this->pathCleaner->cleanup(Argument::exact($cleanUpArgument))->shouldBeCalled();
     $this->mediaManager->save($uploadedFile->reveal(), ['locale' => 'en', 'title' => 'my title'], 1);
 }