/** * Returns a link for a file * * @param File $file * @return string Link */ protected function getBaseLink(File $file) { $folder = $this->folderRepository->find($file->getFolderId()); $beautifurl = explode('/', $folder->getUrl()); $beautifurl = array_filter($beautifurl, function ($beautifurl) { return (bool) $beautifurl; }); $beautifurl = array_map(function ($fragment) { return $this->slugifier->slugify($fragment); }, $beautifurl); $beautifurl[] = $file->getName(); $beautifurl = implode(DIRECTORY_SEPARATOR, $beautifurl); return $beautifurl; }
/** * Handles impostor's resource * * @param File $file */ private function handleImpostorResource(File $file) { $oldResource = $file->getResource(); if ($oldResource->isExclusive()) { $retrieved = $this->storage->retrieve($oldResource); $resource = Resource::create(); $resource->setDateCreated(new DateTime()); $resource->setHash($oldResource->getHash()); $resource->setSize($oldResource->getSize()); $resource->setMimetype($oldResource->getMimetype()); $this->resourceRepository->create($resource, $retrieved); $file->setResource($resource); } }
public function setUp() { $this->publisher = $this->getMockedPublisher(); $this->adapter = $this->getMock('Xi\\Filelib\\Authorization\\AuthorizationAdapter'); $this->plugin = new AutomaticPublisherPlugin($this->publisher, $this->adapter); $this->file = File::create(['data' => ['versions' => ['tusso', 'lusso', 'xusso']]]); }
/** * @test */ public function deleteDelegates() { $identifiable = File::create(); $this->adapter->expects($this->once())->method('delete')->with($identifiable)->will($this->returnValue('xoo')); $ret = $this->cache->delete($identifiable); $this->assertEquals('xoo', $ret); }
/** * @test * @dataProvider provideAcceleratedOptions */ public function shouldSetupAcceleratedResponseCorrectly($download, $enableAcceleration, $canAccelerate, $serverSignature, $expectAccel, $expectedHeader = '', $stripPrefix = '', $addPrefix = '', $expectedPath = null) { $this->renderer->enableAcceleration($enableAcceleration); $this->renderer->stripPrefixFromPath($stripPrefix); $this->renderer->addPrefixToPath($addPrefix); $resource = Resource::create()->addVersion(Version::get('xooxer')); $file = File::create(array('resource' => $resource, 'name' => 'lussuti.pdf'))->addVersion(Version::get('xooxer')); $this->adapter->expects($this->any())->method('canAccelerate')->will($this->returnValue($canAccelerate)); $this->adapter->expects($this->any())->method('getServerSignature')->will($this->returnValue($serverSignature)); $this->ed->expects($this->at(0))->method('dispatch')->with(Events::RENDERER_BEFORE_RENDER, $this->isInstanceOf('Xi\\Filelib\\Event\\FileEvent')); $this->storage->expects($this->once())->method('retrieveVersion')->with($resource, Version::get('xooxer'))->will($this->returnValue(ROOT_TESTS . '/data/refcard.pdf')); $vp = $this->getMockedVersionProvider(); $vp->expects($this->any())->method('getApplicableVersionable')->will($this->returnValue($resource)); $vp->expects($this->any())->method('ensureValidVersion')->with($this->equalTo(Version::get('xooxer')))->will($this->returnArgument(0)); $this->pm->expects($this->any())->method('getVersionProvider')->with($file, Version::get('xooxer'))->will($this->returnValue($vp)); $ret = $this->renderer->render($file, Version::get('xooxer'), array('download' => $download)); $this->assertInstanceOf('Xi\\Filelib\\Renderer\\Response', $ret); $this->assertEquals(200, $ret->getStatusCode()); $expectedHeaders = array('Content-Type' => 'application/pdf'); if ($download) { $expectedHeaders['Content-disposition'] = "attachment; filename={$file->getName()}"; } if (!$expectAccel) { $this->assertNotEquals('', $ret->getContent()); } else { $this->assertEquals('', $ret->getContent()); $expectedHeaders[$expectedHeader] = $expectedPath . '/refcard.pdf'; } $this->assertEquals($expectedHeaders, $ret->getHeaders()); }
/** * @test */ public function linkerShouldExcludeRootProperly() { $extension = 'lus'; $file = File::create(array('name' => 'lamantiini.lus', 'folder_id' => 2, 'resource' => Resource::create(array('id' => 1)))); $linker = new BeautifurlLinker(); $linker->attachTo($this->filelib); $this->assertEquals('lussuttaja/lamantiini-loso.lus', $linker->getLink($file, Version::get('loso'), $extension)); }
/** * @test */ public function getsPathVersionForFile() { $dc = $this->getMockBuilder(DirectoryCalculator::class)->disableOriginalConstructor()->getMock(); $dc->expects($this->exactly(2))->method('calculateDirectory')->will($this->onConsecutiveCalls('1/2/3', '3/2/1')); $pc = new LegacyPathCalculator($dc); $resource = Resource::create(['id' => 'xooxoo']); $file = File::create(['resource' => $resource, 'id' => 'looloo']); $this->assertEquals('1/2/3/luslus/sub/xooxoo/3/2/1/looloo', $pc->getPathVersion($file, Version::get('luslus'))); }
/** * @test */ public function getsPathVersionForFile() { $dc = $this->getMockBuilder(DirectoryCalculator::class)->disableOriginalConstructor()->getMock(); $dc->expects($this->once())->method('calculateDirectory')->will($this->returnValue('3/2/1')); $pc = new ImprovedPathCalculator($dc); $resource = Resource::create(['id' => 'xooxoo']); $file = File::create(['resource' => $resource, 'id' => 'looloo']); $this->assertEquals('files/3/2/1/luslus/looloo', $pc->getPathVersion($file, Version::get('luslus'))); }
/** * @test */ public function eventShouldInitializeCorrectly() { $vp = $this->getMockedVersionProvider(); $file = File::create(); $versions = array('tussi', 'lussi'); $event = new VersionProviderEvent($vp, $file, $versions); $this->assertSame($file, $event->getVersionable()); $this->assertSame($vp, $event->getProvider()); $this->assertEquals(array(Version::get('tussi'), Version::get('lussi')), $event->getVersions()); }
/** * @test */ public function eventShouldInitializeCorrectly() { $file = File::create(); $versions = array('tussi', 'lussi'); $event = new PublisherEvent($file, $versions); $this->assertSame($file, $event->getFile()); $versions = $event->getVersions(); $this->assertCount(2, $versions); $this->assertEquals(array(Version::get('tussi'), Version::get('lussi')), $versions); }
/** * @test */ public function getVersionProviderShouldDelegateToProfile() { $vp = $this->getMockedVersionProvider(); $file = File::create(array('profile' => 'meisterlus')); $version = Version::get('kloo'); $profile = $this->getMockedFileProfile('meisterlus'); $profile->expects($this->once())->method('getVersionProvider')->with($file, $version)->will($this->returnValue($vp)); $this->manager->addProfile($profile); $ret = $this->manager->getVersionProvider($file, $version); $this->assertSame($vp, $ret); }
public function setUp() { $this->resource = Resource::create(['id' => 1, 'date_created' => new DateTime(), 'uuid' => Uuid::uuid4()]); $this->file = File::create(array('id' => 666, 'uuid' => Uuid::uuid4(), 'date_created' => new DateTime(), 'resource' => $this->resource)); $this->resourcePath = $this->getSelfLussingManatee(); $this->resourceVersionPath = $this->getSelfLussingManatee(); $this->fileSpecificVersionPath = $this->getSelfLussingManatee(); $this->version = Version::get('xoo'); list($this->storage, $this->retrievesTemporarily) = $this->getStorage(); $this->filelib = $this->getMockedFilelib(); }
public function setUp() { $this->adapter = $this->getMockedStorageAdapter(); $this->cache = $this->getMockBuilder('Xi\\Filelib\\Storage\\RetrievedCache')->disableOriginalConstructor()->getMock(); $this->storage = new Storage($this->adapter, $this->cache); $this->ed = $this->getMockedEventDispatcher(); $filelib = $this->getMockedFilelib(null, array('storage' => $this->storage, 'ed' => $this->ed)); $this->storage->attachTo($filelib); $this->exception = new \Exception('Throw you like an exception'); $this->resource = Resource::create(); $this->version = Version::get('version'); $this->file = File::create(array('created_at' => new DateTime())); }
/** * @test */ public function reversesLinks() { $fire = $this->getMockedFileRepository(); $filelib = $this->getMockedFilelib(null, array('fire' => $fire)); $linker = new ReversibleCreationTimeLinker(3, 100); $linker->attachTo($filelib); $file = File::create(array('uuid' => 'uuid-lusso-grande')); $fire->expects($this->once())->method('findByUuid')->with('uuid-lusso-grande')->will($this->returnValue($file)); $link = '2014/11/12/uuid-lusso-grande-xoo::lusso:tussi.jpg'; list($reversed, $version) = $linker->reverseLink($link); $this->assertInstanceOf('Xi\\Filelib\\Version', $version); $expectedVersion = new Version('xoo', array('lusso' => 'tussi')); $this->assertSame($file, $reversed); $this->assertEquals($expectedVersion, $version); }
/** * @test */ public function reversesLinks() { $fire = $this->getMockedFileRepository(); $filelib = $this->getMockedFilelib(null, array('fire' => $fire)); $linker = new ReversibleSequentialLinker(3, 100); $linker->attachTo($filelib); $file = File::create(array('uuid' => 'uuid-lusso-grande')); $fire->expects($this->once())->method('findByUuid')->with('uuid-lusso-grande')->will($this->returnValue($file)); $link = '1/9/58/1457/uuid-lusso-grande-xoo::narf:archive;year:1666.jpg'; list($reversed, $version) = $linker->reverseLink($link); $this->assertInstanceOf('Xi\\Filelib\\Version', $version); $expectedVersion = new Version('xoo', array('narf' => 'archive', 'year' => '1666')); $this->assertSame($file, $reversed); $this->assertEquals($expectedVersion, $version); }
/** * @test */ public function cachesVersions() { $id = 'tusso con lusso'; $version = Version::get('tenhunizer'); $versionable = File::create(array('id' => $id)); $versionable2 = Resource::create(array('id' => $id)); $this->assertFalse($this->cache->getVersion($versionable, $version)); $this->cache->setVersion($versionable, $version, $this->retrieved); $this->cache->setVersion($versionable2, $version, $this->retrieved2); $this->assertSame($this->retrieved, $this->cache->getVersion($versionable, $version)); $this->assertSame($this->retrieved2, $this->cache->getVersion($versionable2, $version)); $this->assertNotSame($this->cache->getVersion($versionable, $version), $this->cache->getVersion($versionable2, $version)); $this->cache->deleteVersion($versionable, $version); $this->assertFalse($this->cache->getVersion($versionable, $version)); $this->assertSame($this->retrieved2, $this->cache->getVersion($versionable2, $version)); }
/** * @test * @dataProvider provideFilenames */ public function beforeUploadShouldRandomizeUploadFilename($name, $expectedExtension) { $file = File::create(array('name' => $name, 'profile' => 'tussi')); $event = new FileEvent($file); $plugin = new RandomizeNamePlugin(); $plugin->setProfiles(array('tussi')); $plugin->beforeCreate($event); $this->assertNotEquals($name, $file->getName()); $pinfo = pathinfo($file->getName()); $this->assertUuid($pinfo['basename']); if ($expectedExtension) { $this->assertEquals($expectedExtension, $pinfo['extension']); } else { $this->assertArrayNotHasKey('extension', $pinfo); } $this->assertEquals($name, $file->getData()->get('plugin.randomize_name.original_name')); }
/** * @test */ public function createsAllTemporaryVersions() { $retrievedPath = ROOT_TESTS . '/data/self-lussing-manatee.jpg'; $file = File::create(array('id' => 1, 'resource' => Resource::create())); $storage = $this->getMockedStorage(); $storage->expects($this->exactly(1))->method('retrieve')->with($this->isInstanceOf('Xi\\Filelib\\Resource\\Resource'))->will($this->returnValue($retrievedPath)); $ed = $this->getMockedEventDispatcher(); $pm = $this->getMockedProfileManager(array('xooxer')); $filelib = $this->getMockedFilelib(null, array('storage' => $storage, 'pm' => $pm, 'ed' => $ed)); $plugin = new OriginalVersionPlugin(); $plugin->attachTo($filelib); $ret = $plugin->createAllTemporaryVersions($file); $this->assertInternalType('array', $ret); $this->assertCount(1, $ret); $this->assertArrayHasKey('original', $ret); foreach ($ret as $tmp) { $this->assertRegExp('#^' . ROOT_TESTS . '/data/temp#', $tmp); } }
public function setUp() { $this->version = Version::get('xooxer'); $path = ROOT_TESTS . '/data/publisher/public'; $this->filesystem = new Filesystem(new Local($path)); $this->adapter = new FlysystemPublisherAdapter($this->filesystem, '/files'); $this->storage = $this->getMockedStorage(); $filelib = $this->getMockedFilelib(null, array('storage' => $this->storage)); $this->linker = $this->getMockedLinker(); $this->adapter->attachTo($filelib); $this->vp = $this->getMockedVersionProvider(array('xooxer'), false); $this->resource = Resource::create(); $this->file = File::create(array('resource' => $this->resource)); $this->vp->expects($this->any())->method('getMimeType')->with($this->file, $this->version)->will($this->returnValue('image/jpeg')); $this->vp->expects($this->any())->method('getExtension')->with($this->file, $this->version)->will($this->returnValue('jpg')); $this->vp->expects($this->any())->method('getApplicableVersionable')->with($this->file)->will($this->returnValue($this->resource)); $this->storage->expects($this->any())->method('retrieveVersion')->with($this->resource, $this->version)->will($this->returnValue(ROOT_TESTS . '/data/self-lussing-manatee.jpg')); $this->path = 'lusso/grande/ankan-lipaisija.jpg'; $this->linker->expects($this->any())->method('getLink')->with($this->file, $this->version, 'jpg')->will($this->returnValue($this->path)); }
/** * @test */ public function deletes() { $file = File::create(['id' => 'xooxer']); $this->assertNull($this->cache->delete($file)); }
/** * @param File $file * @param Version $version * @return array */ protected function doCreateTemporaryVersion(File $file, Version $version) { $version = $this->ensureValidVersion($version); $retrieved = $this->storage->retrieve($file->getResource()); $commandDefinitions = call_user_func_array($this->commandDefinitionsGetter, array($file, $version, $this)); $helper = new ImageMagickHelper($retrieved, $this->tempFiles, $commandDefinitions); return array($version->toString(), $helper->execute()); }
/** * @test */ public function deleteFileShouldDelegateToBackendAdapter() { $obj = File::create(array('id' => 1)); $this->platform->expects($this->once())->method('deleteFile')->with($obj)->will($this->returnArgument(0)); $backend = $this->getMockedBackend(); $ret = $backend->deleteFile($obj); $this->assertSame($obj, $ret); }
/** * @test */ public function getExtensionShouldDelegateToParentToAutodetectExtension() { $storage = $this->getMockedStorage(); $filelib = $this->getMockedFilelib(null, array('storage' => $storage)); $plugin = new VersionPlugin(array('xooxoo' => array(array(), null))); $plugin->attachTo($filelib); $resource = $this->getMockedResource(); $file = File::create(array('resource' => $resource)); $storage->expects($this->once())->method('retrieveVersion')->with($resource, Version::get('xooxoo'))->will($this->returnValue(ROOT_TESTS . '/data/self-lussing-manatee.jpg')); $ret = $plugin->getExtension($file, Version::get('xooxoo')); $this->assertSame('jpg', $ret); }
/** * @param Iterator $iter * @return ArrayIterator */ protected function exportFiles(Iterator $iter) { $ret = new ArrayIterator(array()); foreach ($iter as $file) { $request = new FindByIdsRequest(array($file['resource_id']), 'Xi\\Filelib\\Resource\\Resource'); $resource = $this->findByIds($request)->getResult()->first(); $ret->append(File::create(array('id' => $file['id'], 'folder_id' => $file['folder_id'], 'profile' => $file['fileprofile'], 'name' => $file['filename'], 'date_created' => new DateTime($file['date_created']), 'status' => $file['status'], 'uuid' => $file['uuid'], 'resource' => $resource, 'data' => json_decode($file['data'], true)))); } return $ret; }
/** * @param File $file * @return string */ public function getFileName(File $file) { return $file->getName(); }
/** * Returns a file's folder * * @param File $file * @return Folder */ private function getFilesFolder(File $file) { return $this->folderRepository->find($file->getFolderId()); }
/** * @test */ public function providesAllVersions() { copy(ROOT_TESTS . '/data/self-lussing-manatee.jpg', ROOT_TESTS . '/data/temp/temporary-manatee.jpg'); copy(ROOT_TESTS . '/data/self-lussing-manatee.jpg', ROOT_TESTS . '/data/temp/temporary-manatee2.jpg'); $this->assertFileExists(ROOT_TESTS . '/data/temp/temporary-manatee.jpg'); $this->assertFileExists(ROOT_TESTS . '/data/temp/temporary-manatee2.jpg'); $file = File::create(array('resource' => Resource::create())); $this->plugin->attachTo($this->filelib); $this->plugin->expects($this->any())->method('getProvidedVersions')->will($this->returnValue(array('tooxer', 'mooxer'))); $this->plugin->expects($this->once())->method('doCreateAllTemporaryVersions')->will($this->returnValue(array('tooxer' => ROOT_TESTS . '/data/temp/temporary-manatee.jpg', 'mooxer' => ROOT_TESTS . '/data/temp/temporary-manatee2.jpg'))); $this->plugin->expects($this->exactly(1))->method('areSharedVersionsAllowed')->will($this->returnValue(false)); $this->storage->expects($this->exactly(2))->method('storeVersion')->with($this->isInstanceOf('Xi\\Filelib\\File\\File'), $this->isInstanceOf('Xi\\Filelib\\Version'), $this->isType('string')); $this->fire->expects($this->once())->method('update')->with($file); $this->ed->expects($this->once())->method('dispatch')->with(VPEvents::VERSIONS_PROVIDED, new VersionProviderEvent($this->plugin, $file, array(Version::get('tooxer'), Version::get('mooxer')))); $this->plugin->provideAllVersions($file); $this->assertFileNotExists(ROOT_TESTS . '/data/temp/temporary-manatee.jpg'); $this->assertFileNotExists(ROOT_TESTS . '/data/temp/temporary-manatee2.jpg'); }
/** * @param File $file * @return string */ protected function getFileName(File $file) { return $file->getUuid(); }
/** * @test */ public function failedProviderFails() { $resource = Resource::create(); $file = File::create(array('resource' => $resource, 'name' => 'lussuti.pdf')); $vp = $this->getMockedVersionProvider(array('xooxer'), true); $this->pm->expects($this->any())->method('getVersionProvider')->with($file, Version::get('xooxer'))->will($this->returnValue($vp)); $vp->expects($this->atLeastOnce())->method('getApplicableVersionable')->will($this->returnValue($resource)); $vp->expects($this->atLeastOnce())->method('ensureValidVersion')->will($this->returnArgument(0)); $vp->expects($this->once())->method('provideVersion')->with($file, Version::get('xooxer'))->will($this->throwException(new RuntimeException('Oh noes'))); $this->fiop->expects($this->never())->method('update'); $ret = $this->renderer->render($file, 'xooxer'); $this->assertInstanceOf('Xi\\Filelib\\Renderer\\Response', $ret); $this->assertEquals(404, $ret->getStatusCode()); }
/** * @return array */ public function provideData() { return array(array('checkFileAnonymousRead', 'isFileReadableByAnonymous', 'Anonymous read', File::create(array('id' => 'gran-lusso'))), array('checkFileRead', 'isFileReadable', 'Read', File::create(array('id' => 'gran-lusso'))), array('checkFolderWrite', 'isFolderWritable', 'Write', Folder::create(array('id' => 'gran-lusso'))), array('checkFileWrite', 'isFileWritable', 'Write', File::create(array('id' => 'gran-lusso'))), array('checkFolderRead', 'isFolderReadable', 'Read', Folder::create(array('id' => 'gran-lusso')))); }