public function testGetFileUrl() { $this->attachment->setId(1); $this->attachment->setExtension('txt'); $fieldName = 'testField'; $parentEntity = new TestClass(); $expectsString = 'T3JvXEJ1bmRsZVxBdHRhY2htZW50QnVuZGxlXFRlc3RzXFVuaXRcRml4dHVyZXNcVGVzdENsYXNzfHRlc3RGaW' . 'VsZHwxfGRvd25sb2FkfHRlc3RGaWxlLnR4dA=='; $this->router->expects($this->once())->method('generate')->with('oro_attachment_file', ['codedString' => $expectsString, 'extension' => 'txt'], true); $this->attachmentManager->getFileUrl($parentEntity, $fieldName, $this->attachment, 'download', true); }
public function testGetFileUrl() { $this->attachment->setId(1); $this->attachment->setExtension('txt'); $this->attachment->setOriginalFilename('testFile.withForwardSlash?.txt'); $fieldName = 'testField'; $parentEntity = new TestClass(); $expectsString = 'T3JvXEJ1bmRsZVxBdHRhY2htZW50QnVuZGxlXFRlc3RzXFVuaXRcRml4dHVyZXNcVGVzdENsYXNzfHRlc3RG' . 'aWVsZHwxfGRvd25sb2FkfHRlc3RGaWxlLndpdGhGb3J3YXJkU2xhc2g_LnR4dA=='; //Underscore should replace / character $this->router->expects($this->once())->method('generate')->with('oro_attachment_file', ['codedString' => $expectsString, 'extension' => 'txt'], true); $this->attachmentManager->getFileUrl($parentEntity, $fieldName, $this->attachment, 'download', true); }
/** * Get Image html block * * @param \Twig_Environment $environment * @param object $parentEntity * @param mixed $attachment * @param string|object $entityClass * @param string $fieldName * @return string */ public function getImageView(\Twig_Environment $environment, $parentEntity, $attachment = null, $entityClass = null, $fieldName = '') { /** * @todo: should be refactored in BAP-5637 */ if (is_int($attachment)) { $attachment = $this->getFileById($attachment); } if ($attachment && $attachment->getFilename()) { $width = self::DEFAULT_THUMB_SIZE; $height = self::DEFAULT_THUMB_SIZE; if ($entityClass && $fieldName) { if (is_object($entityClass)) { $entityClass = ClassUtils::getRealClass($entityClass); } $config = $this->attachmentConfigProvider->getConfig($entityClass, $fieldName); $width = $config->get('width'); $height = $config->get('height'); } return $environment->loadTemplate(self::IMAGES_TEMPLATE)->render(['imagePath' => $this->manager->getResizedImageUrl($attachment, $width, $height), 'url' => $this->manager->getFileUrl($parentEntity, $fieldName, $attachment, 'download', true), 'fileName' => $attachment->getOriginalFilename()]); } return ''; }
/** * @param Comment $entity * @param File $attachment * * @return string */ protected function getAttachmentURL($entity, $attachment) { return $this->attachmentManager->getFileUrl($entity, 'attachment', $attachment, 'download', true); }