/** * @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 * @dataProvider providePrefixes */ public function getPathVersionRespectsPrefixes($prefix) { $dc = $this->getMockBuilder(DirectoryCalculator::class)->disableOriginalConstructor()->getMock(); $dc->expects($this->any())->method('calculateDirectory')->will($this->returnValue('1/2/3')); $pc = new ImprovedPathCalculator($dc, $prefix); $resource = Resource::create(['id' => 'xooxoo']); $this->assertEquals(trim($prefix, '/') . '/resources/1/2/3/luslus/xooxoo', $pc->getPathVersion($resource, Version::get('luslus'))); }
/** * @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 deleteResourceReturnsFalseOnEntityNotFound() { $this->setUpEmptyDataSet(); $em = $this->createEntityManagerMock(); $em->expects($this->once())->method('find')->will($this->throwException(new EntityNotFoundException())); $backend = new DoctrineOrmBackendAdapter($em); $resource = Resource::create(array('id' => 1)); $this->assertFalse($backend->deleteResource($resource)); }
/** * @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 storeVersionFailsIfDirectoryNotCreatable() { $root = ROOT_TESTS . '/data/files'; $storage = new FilesystemStorageAdapter($root); chmod($root, 0400); $resource = Resource::create(['id' => 666, 'uuid' => Uuid::uuid4()]); $this->setExpectedException('Xi\\Filelib\\Storage\\FileIOException'); $storage->storeVersion($resource, Version::get('puupster'), $this->getSelfLussingManatee()); }
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(); }
/** * @test */ public function testForEquality() { $adapter = new LocalAdapter(ROOT_TESTS . '/data/files'); $pc = new ImprovedPathCalculator(); $filesystem = new Filesystem($adapter); $filelib = new FileLibrary(new MemoryStorageAdapter(), new MemoryBackendAdapter(), null, ROOT_TESTS . '/data/temp'); $storage1 = new FlysystemStorageAdapter($filesystem, $pc, false); $storage1->attachTo($filelib); $temp = $this->getSelfLussingManatee(); $storage2 = new FilesystemStorageAdapter(ROOT_TESTS . '/data/files', $pc); $storage2->attachTo($filelib); $resource = Resource::create(['id' => 'lubber', 'uuid' => Uuid::uuid4()]); $ret = $storage1->store($resource, $temp); $this->assertFileEquals($storage1->retrieve($resource)->getPath(), $storage2->retrieve($resource)->getPath()); }
/** * @test */ public function createProvidedVersionsShouldCreateVersions() { $retrievedPath = ROOT_TESTS . '/data/self-lussing-manatee.jpg'; $file = File::create(array('id' => 1, 'resource' => Resource::create())); $this->storage->expects($this->exactly(2))->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' => $this->storage, 'pm' => $pm, 'ed' => $ed)); $this->plugin->attachTo($filelib); $ret = $this->plugin->createAllTemporaryVersions($file); $this->assertInternalType('array', $ret); foreach ($ret as $version => $tmp) { $this->assertRegExp('#^' . ROOT_TESTS . '/data/temp#', $tmp); } }
/** * @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)); }
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 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'); }
/** * @test */ public function onInstantiateSaves() { $cache = $this->getMockBuilder('Xi\\Filelib\\Backend\\Cache\\Cache')->disableOriginalConstructor()->setMethods(array('delete', 'save'))->getMock(); $identifiable = Resource::create(); $event = new IdentifiableEvent($identifiable); $cache->expects($this->once())->method('save')->with($identifiable); $cache->onInstantiate($event); }
/** * @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()); }
/** * @param File $file * @param FileUpload $upload * @return Resource */ public function findResourceForUpload(File $file, FileUpload $upload) { $file = clone $file; $hash = sha1_file($upload->getRealPath()); $profileObj = $this->profiles->getProfile($file->getProfile()); $finder = new ResourceFinder(array('hash' => $hash)); $resources = $this->backend->findByFinder($finder); if ($resources) { foreach ($resources as $resource) { if (!$resource->isExclusive()) { $file->setResource($resource); if (!$profileObj->isSharedResourceAllowed($file)) { $file->unsetResource(); } break; } } } if (!$file->getResource()) { $resource = Resource::create(); $resource->setDateCreated(new DateTime()); $resource->setHash($hash); $resource->setSize($upload->getSize()); $resource->setMimetype($upload->getMimeType()); $file->setResource($resource); if (!$profileObj->isSharedResourceAllowed($file)) { $resource->setExclusive(true); } $this->create($resource, $upload->getRealPath()); $file->setResource($resource); } return $file->getResource(); }
/** * @test */ public function createShouldCreateNewInstance() { $this->assertInstanceOf('Xi\\Filelib\\Resource\\Resource', Resource::create(array())); }
public function exists(Resource $resource) { return isset($this->resources[$resource->getId()]); }
/** * @test */ public function toArrayShouldWorkAsExpected() { $dt = new \DateTime('1978-03-21'); $file = File::create(); $file->setId(1); $file->setFolderId(655); $file->setProfile('unknown'); $file->setName('kukkuu.png'); $file->setDateCreated($dt); $file->setStatus(54); $file->setUuid('tussi-poski'); $file->setResource(Resource::create()); $file->addVersion(Version::get('lussi')); $file->addVersion(Version::get('xussi')); $this->assertEquals($file->toArray(), array('id' => 1, 'folder_id' => 655, 'profile' => 'unknown', 'name' => 'kukkuu.png', 'date_created' => new \DateTime('1978-03-21'), 'status' => 54, 'uuid' => 'tussi-poski', 'resource' => Resource::create(), 'data' => array('versions' => array('lussi', 'xussi')))); }
/** * @param ArrayIterator $iter * @return ArrayIterator */ protected function exportResources(ArrayIterator $iter) { $date = new DateTime(); $ret = new ArrayIterator(array()); foreach ($iter as $resource) { $ret->append(Resource::create(array('id' => (string) $resource['id'], 'uuid' => $resource['uuid'], 'hash' => $resource['hash'], 'mimetype' => $resource['mimetype'], 'size' => $resource['size'], 'date_created' => DateTime::createFromFormat('Y-m-d H:i:s', $resource['date_created'])->setTimezone($date->getTimezone()), 'data' => $resource['data'], 'exclusive' => $resource['exclusive']))); } return $ret; }
public function delete(Resource $resource) { if (isset($this->retrieved[$resource->getId()])) { unset($this->retrieved[$resource->getId()]); } }
/** * @test */ public function unpublishExitsEarlyIfResource() { $this->publisher->expects($this->never())->method('unpublishVersion'); $vp = $this->getMockedVersionProvider(array('lusso', 'con-tusso')); $event = new VersionProviderEvent($vp, Resource::create(), array('lusso', 'con-tusso', 'loso')); $this->plugin->doUnpublish($event); }
/** * @test */ public function findByIdsFulfillsRequestWhenFound() { $request = new FindByIdsRequest(array('xoo'), 'Xi\\Filelib\\Resource\\Resource'); $resource = Resource::create(array('id' => 'xoo')); $this->im->add($resource); $ret = $this->im->findByIds($request); $this->assertTrue($ret->isFulfilled()); }
/** * @test */ public function retrieveVersionExitsEarlyWithCache() { $resource = Resource::create(); $version = Version::get('lusso'); $retrieved = new Retrieved('lus', false); $this->adapter->expects($this->never())->method('retrieveVersion'); $this->adapter->expects($this->never())->method('versionExists'); $this->cache->expects($this->at(0))->method('getVersion')->with($resource, $version)->will($this->returnValue($retrieved)); $this->assertEquals('lus', $this->storage->retrieveVersion($resource, $version)); }
/** * @test * @dataProvider provideDataForIsSharedResourceAllowed */ public function isSharedResourceAllowedShouldReturnCorrectResult($expected, $mimetype) { $this->addMockedVersionsToFileProfile(); $file = File::create(array('resource' => Resource::create(array('mimetype' => $mimetype)))); $this->assertEquals($expected, $this->fileProfile->isSharedResourceAllowed($file)); }
/** * @param Iterator $iter * @return ArrayIterator */ protected function exportResources(Iterator $iter) { $ret = new ArrayIterator(array()); foreach ($iter as $resource) { $ret->append(Resource::create(array('id' => $resource['id'], 'uuid' => $resource['uuid'], 'hash' => $resource['hash'], 'date_created' => new DateTime($resource['date_created']), 'data' => json_decode($resource['data'], true), 'mimetype' => $resource['mimetype'], 'size' => $resource['filesize'], 'exclusive' => (bool) $resource['exclusive']))); } return $ret; }
/** * @test * @dataProvider folderIdProvider * @param mixed $folderId */ public function fileCreateShouldCreateFile($folderId) { $this->setUpSimpleDataSet(); $fidata = array('profile' => 'versioned', 'name' => 'tohtori-tussi.png', 'link' => 'tohtori-tussi.png', 'date_created' => new DateTime('2011-01-01 16:16:16'), 'status' => 5, 'uuid' => 'uuid-lussid', 'resource' => Resource::create(array('id' => 1))); $fodata = array('id' => $folderId, 'parent_id' => null, 'url' => '', 'name' => ''); $file = File::create($fidata); $folder = Folder::create($fodata); $file = $this->backend->createFile($file, $folder); $this->assertInstanceOf('Xi\\Filelib\\File\\File', $file); $this->assertValidCreatedIdentifier($file->getId()); $this->assertEquals($fodata['id'], $file->getFolderId()); $this->assertEquals($fidata['profile'], $file->getProfile()); $this->assertEquals($fidata['date_created'], $file->getDateCreated()); $this->assertEquals($fidata['status'], $file->getStatus()); $this->assertEquals($fidata['uuid'], $file->getUuid()); $this->assertEquals($fidata['resource'], $file->getResource()); $this->assertEquals(array(), $file->getVersions()); }
/** * @test */ public function deleteResourceShouldDelegateToBackendAdapter() { $obj = Resource::create(array('id' => 1)); $this->platform->expects($this->once())->method('deleteResource')->with($obj)->will($this->returnArgument(0)); $backend = $this->getMockedBackend(); $ret = $backend->deleteResource($obj); $this->assertNull($ret); }
/** * @param Iterator $iter * @return ArrayIterator */ protected function exportResources(Iterator $iter) { $ret = new ArrayIterator(array()); foreach ($iter as $resource) { $ret->append(Resource::create(array('id' => $resource->getId(), 'uuid' => $resource->getUuid(), 'hash' => $resource->getHash(), 'date_created' => $resource->getDateCreated(), 'data' => $resource->getData(), 'mimetype' => $resource->getMimetype(), 'size' => $resource->getSize(), 'exclusive' => $resource->getExclusive()))); } return $ret; }
public function provideIdentifiables() { return array(array(File::create(array('id' => 1, 'data' => array('lus' => 'hof')))), array(Folder::create(array('id' => 'xooxooxoo'))), array(Resource::create(array('id' => 'xooxooxoo')))); }
/** * 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); } }