/** * @param \FSi\DoctrineExtensions\Uploadable\File $file * @param null|string $prefix * @throws \RuntimeException * @return string */ public function filePath(File $file, $prefix = null) { if ($file->getFilesystem()->getAdapter() instanceof Local || $file->getFilesystem()->getAdapter() instanceof Cache) { return '/' . $this->generatePath($file, $prefix); } $this->writeFileToLocalAdapter($file); return '/' . $this->generatePath($file, $prefix); }
function it_generate_url_for_fsi_file_with_base_url_set(File $file, UploadableFilesystem $filesystem, Local $adapter) { $file->getKey()->willReturn('TestFolder/File/file name.jpg'); $file->getFilesystem()->willReturn($filesystem); $filesystem->getBaseUrl()->willReturn("http://domain.com/basepath/"); $this->fileUrl($file)->shouldReturn('http://domain.com/basepath/TestFolder/File/file name.jpg'); }
/** * @param File $file * @return string */ public function fileUrl(File $file) { $filesystem = $file->getFilesystem(); if (!$filesystem instanceof Filesystem) { throw new InvalidFilesystemException(sprintf('Expected instance of \\FSi\\Bundle\\DoctrineExtensionsBundle\\Listener\\Uploadable\\Filesystem got %s', is_object($filesystem) ? get_class($filesystem) : gettype($filesystem))); } return $filesystem->getBaseUrl() . $file->getKey(); }
function it_generate_url_with_passed_prefix_even_if_there_is_a_prefix_in_globals(Twig_Environment $environment, File $file, Filesystem $filesystem, Local $adapter) { $environment->getGlobals()->willReturn(array('fsi_file_prefix' => 'uploaded')); $this->initRuntime($environment); $file->getKey()->shouldBeCalled()->willReturn('TestFolder/File/file.jpg'); $file->getFilesystem()->shouldBeCalled()->willReturn($filesystem); $filesystem->getAdapter()->willReturn($adapter); $this->fileAsset($file, 'my_prefix')->shouldReturn('/my_prefix/TestFolder/File/file.jpg'); $this->filePath($file, 'my_prefix')->shouldReturn('/my_prefix/TestFolder/File/file.jpg'); }
public function testFileIsAbleToReturnItsFilesystem() { $filesystem = $this->getFilesystemMock(); $file = new File('key', $filesystem); $this->assertSame($filesystem, $file->getFilesystem()); }