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']]]);
 }
Beispiel #2
0
 /**
  * @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);
 }
Beispiel #10
0
 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();
 }
Beispiel #11
0
 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));
 }
Beispiel #18
0
 /**
  * @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);
 }
Beispiel #19
0
 /**
  * @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;
 }
 /**
  * @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');
 }
Beispiel #22
0
 /**
  * @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());
 }
 /**
  * @test
  */
 public function updates()
 {
     $file = File::create();
     $this->repo->update($file)->shouldBeCalled()->willReturn('jippikaijea');
     $ret = $this->filelib->getFileRepository()->update($file);
     $this->assertEquals('jippikaijea', $ret);
 }
 /**
  * @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'))));
 }
 /**
  * @test
  */
 public function clears()
 {
     $obj = File::create(['id' => 'xooooooooxers']);
     $this->cache->save($obj);
     $cached = $this->cache->findById($obj->getId(), get_class($obj));
     $this->assertEquals($obj, $cached);
     $this->cache->clear();
     $this->assertFalse($this->cache->findById($obj->getId(), get_class($obj)));
 }
 /**
  * @param  Iterator      $iter
  * @return ArrayIterator
  */
 protected function exportFiles(Iterator $iter)
 {
     $ret = new ArrayIterator(array());
     foreach ($iter as $file) {
         $resources = new ArrayIterator(array($file->getResource()));
         $ret->append(File::create(array('id' => $file->getId(), 'folder_id' => $file->getFolder() ? $file->getFolder()->getId() : null, 'profile' => $file->getProfile(), 'name' => $file->getName(), 'date_created' => $file->getDateCreated(), 'status' => $file->getStatus(), 'uuid' => $file->getUuid(), 'resource' => $this->exportResources($resources)->current(), 'data' => $file->getData())));
     }
     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());
 }
Beispiel #28
0
 /**
  * @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));
 }
 /**
  * @test
  */
 public function deletes()
 {
     $file = File::create(['id' => 'xooxer']);
     $this->assertNull($this->cache->delete($file));
 }
 /**
  * @test
  */
 public function anonymousAclQueryShouldDelegateToIsGrantedWhenAclIsFound()
 {
     $file = File::create(array('id' => 1));
     $acl = $this->getMockForAbstractClass('Symfony\\Component\\Security\\Acl\\Model\\AclInterface');
     $acl->expects($this->once())->method('isGranted')->with($this->equalTo(array(MaskBuilder::MASK_VIEW)));
     $this->aclProvider->expects($this->once())->method('findAcl')->with($this->isInstanceOf('Symfony\\Component\\Security\\Acl\\Domain\\ObjectIdentity'))->will($this->returnValue($acl));
     $acl = new SymfonyAuthorizationAdapter($this->context, $this->aclProvider, false);
     $acl->attachTo($this->filelib);
     $ret = $acl->anonymousAclQueryWith($file);
 }