Example #1
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);
 }
Example #2
0
 /**
  * Returns file name without special characters and preserves file extension.
  *
  * @param $originalFileName
  *
  * @return string
  */
 private function getNormalizedFileName($originalFileName)
 {
     if (strpos($originalFileName, '.') !== false) {
         $pathParts = pathinfo($originalFileName);
         $fileName = $this->pathCleaner->cleanup($pathParts['filename']);
         $fileName .= '.' . $pathParts['extension'];
     } else {
         $fileName = $this->pathCleaner->cleanup($originalFileName);
     }
     return $fileName;
 }
Example #3
0
 /**
  * checks if path is valid.
  *
  * @param string $path         path of route
  * @param string $webspaceKey  key of portal
  * @param string $languageCode
  * @param string $segmentKey
  *
  * @return bool
  */
 public function isValid($path, $webspaceKey, $languageCode, $segmentKey = null)
 {
     return $this->cleaner->validate($path) && $this->mapper->unique($path, $webspaceKey, $languageCode, $segmentKey);
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function isValid($path, $webspaceKey, $languageCode, $segmentKey = null)
 {
     return $path !== '/' && $this->cleaner->validate($path);
 }