/**
  * @test
  */
 public function deleteFolderReturnsFalseOnEntityNotFound()
 {
     $this->setUpEmptyDataSet();
     $em = $this->createEntityManagerMock();
     $em->expects($this->once())->method('find')->will($this->throwException(new EntityNotFoundException()));
     $backend = new DoctrineOrmBackendAdapter($em);
     $resource = Folder::create(array('id' => 666, 'parent_id' => null, 'name' => 'foo'));
     $this->assertFalse($backend->deleteFolder($resource));
 }
Example #2
0
 /**
  * @test
  */
 public function toArrayShouldWorkAsExpected()
 {
     $folder = Folder::create();
     $folder->setId(1);
     $folder->setParentId(655);
     $folder->setName('klussutusta');
     $folder->setUrl('/lussen/hofen');
     $folder->setUuid('luss3r');
     $folder->setData(array('tenhusta-suurempi' => 'on vain tenhunen'));
     $this->assertEquals($folder->toArray(), array('id' => 1, 'parent_id' => 655, 'name' => 'klussutusta', 'url' => '/lussen/hofen', 'uuid' => 'luss3r', 'data' => array('tenhusta-suurempi' => 'on vain tenhunen')));
     $folder = Folder::create();
     $this->assertEquals($folder->toArray(), array('id' => null, 'parent_id' => null, 'name' => null, 'url' => null, 'uuid' => null, 'data' => array()));
 }
 /**
  * @test
  */
 public function beforeUploadShouldReturnNewUploadWhenImage()
 {
     $upload = new FileUpload(ROOT_TESTS . '/data/self-lussing-manatee.jpg');
     $this->plugin->setProfiles(array('tussi'));
     $folder = Folder::create();
     $profile = new FileProfile('tussi');
     $event = new FileUploadEvent($upload, $folder, $profile);
     $this->plugin->beforeUpload($event);
     $xupload = $event->getFileUpload();
     $this->assertInstanceOf('Xi\\Filelib\\File\\Upload\\FileUpload', $xupload);
     $this->assertNotSame($upload, $xupload);
     $this->assertEquals('self-lussing-manatee.jpg', $xupload->getUploadFilename());
 }
 public function setUp()
 {
     $this->version = Version::get('xoo');
     $foop = $this->getMockedFolderRepository();
     $foop->expects($this->any())->method('find')->will($this->returnCallback(function ($id) {
         if ($id == 1) {
             return Folder::create(array('id' => 1, 'name' => 'root', 'parent_id' => null, 'url' => ''));
         } elseif ($id == 2) {
             return Folder::create(array('id' => 2, 'name' => 'lussuttaja', 'parent_id' => 1, 'url' => '/lussuttaja'));
         } elseif ($id == 3) {
             return Folder::create(array('id' => 2, 'name' => 'tussin', 'parent_id' => 2, 'url' => '/lussuttaja/tussin'));
         } elseif ($id == 4) {
             return Folder::create(array('id' => 2, 'name' => 'banaanin', 'parent_id' => 2, 'url' => '/lussuttaja/banaanin'));
         } elseif ($id == 5) {
             return Folder::create(array('id' => 5, 'name' => 'sûürën ÜGRÎLÄISÊN KÄNSÄN Sïëlú', 'parent_id' => 4, 'url' => '/lussuttaja/banaanin/sûürën-ÜGRÎLÄISÊN-KÄNSÄN-Sïëlú'));
         }
         return null;
     }));
     $this->filelib = $this->getMockedFilelib(null, null, $foop);
 }
 public function setUp()
 {
     $this->version = Version::get('xoo');
     $fo = $this->getMockBuilder('\\Xi\\Filelib\\Folder\\FolderRepository')->disableOriginalConstructor()->getMock();
     $fo->expects($this->any())->method('find')->will($this->returnCallback(function ($id) {
         if ($id == 1) {
             return Folder::create(array('id' => 1, 'name' => 'root', 'parent_id' => null, 'url' => ''));
         } elseif ($id == 2) {
             return Folder::create(array('id' => 2, 'name' => 'lussuttaja', 'parent_id' => 1, 'url' => '/lussuttaja'));
         } elseif ($id == 3) {
             return Folder::create(array('id' => 2, 'name' => 'tussin', 'parent_id' => 2, 'url' => '/lussuttaja/tussin'));
         } elseif ($id == 4) {
             return Folder::create(array('id' => 2, 'name' => 'banaanin', 'parent_id' => 2, 'url' => '/lussuttaja/banaanin'));
         }
         return null;
     }));
     $this->fo = $fo;
     $vp = $this->getMockedVersionProvider();
     $vp->expects($this->any())->method('getExtension')->with($this->isInstanceOf('Xi\\Filelib\\File\\File'), $this->version)->will($this->returnValue('xoo'));
     $this->versionProvider = $vp;
 }
 /**
  * @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'))));
 }
 /**
  * @param  Iterator      $iter
  * @return ArrayIterator
  */
 protected function exportFolders(Iterator $iter)
 {
     $ret = new ArrayIterator(array());
     foreach ($iter as $folder) {
         $ret->append(Folder::create(array('id' => $folder->getId(), 'parent_id' => $folder->getParent() ? $folder->getParent()->getId() : null, 'name' => $folder->getName(), 'url' => $folder->getUrl(), 'uuid' => $folder->getUuid(), 'data' => $folder->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());
 }
Example #9
0
 /**
  * @test
  */
 public function findByFilenameDelegates()
 {
     $param1 = Folder::create();
     $param2 = 'xooxox';
     $expected = 'tus';
     $this->repo->findByFilename($param1, $param2)->shouldBeCalled()->willReturn($expected);
     $ret = $this->filelib->getFileRepository()->findByFilename($param1, $param2);
     $this->assertEquals($expected, $ret);
 }
 /**
  * @xtest
  */
 public function isFolderReadableByAnonymousShouldReturnFalse()
 {
     $folder = Folder::create(array('id' => 1));
     $acl = new SymfonyAuthorizationAdapter($this->context, $this->aclProvider, false);
     $acl->attachTo($this->filelib);
     $ret = $acl->isFolderReadableByAnonymous($folder);
     $this->assertFalse($ret);
 }
Example #11
0
 /**
  * @test
  */
 public function deleteFolderShouldThrowExceptionWhenFolderContainsFiles()
 {
     $this->setExpectedException('Xi\\Filelib\\Backend\\FolderNotEmptyException');
     $files = array(File::create(array('id' => 1)), File::create(array('id' => 2)));
     $obj = Folder::create(array('id' => 1, 'parent_id' => 66));
     $this->platform->expects($this->never())->method('deleteFolder');
     $this->im->expects($this->never())->method('remove');
     $backend = $this->getMockBuilder('Xi\\Filelib\\Backend\\Backend')->setConstructorArgs(array($this->ed, $this->platform, $this->im))->setMethods(array('findByFinder'))->getMock();
     $self = $this;
     $backend->expects($this->once())->method('findByFinder')->with($this->isInstanceOf('Xi\\Filelib\\Backend\\Finder\\FileFinder'))->will($this->returnCallback(function (FileFinder $finder) use($self, $files) {
         $expectedParams = array('folder_id' => 1);
         $self->assertEquals($expectedParams, $finder->getParameters());
         return ArrayCollection::create($files);
     }));
     $ret = $backend->deleteFolder($obj);
     $this->assertNull($ret);
 }
Example #12
0
 /**
  * Finds file by filename in a folder
  *
  * @param Folder $folder
  * @param $filename
  * @return File
  */
 public function findByFilename(Folder $folder, $filename)
 {
     return $this->backend->findByFinder(new FileFinder(array('folder_id' => $folder->getId(), 'name' => $filename)))->first();
 }
Example #13
0
 /**
  * @test
  */
 public function removeManyDeletesAllObjectsAndRewindsIterator()
 {
     $first = File::create(array('id' => 6));
     $array = array($first, Folder::create(array('id' => 6)), File::create(array('id' => 6)));
     $iter = ArrayCollection::create($array);
     $im = $this->getMockBuilder('Xi\\Filelib\\Backend\\IdentityMap\\IdentityMap')->setMethods(array('remove'))->disableOriginalConstructor()->getMock();
     $im->expects($this->exactly(3))->method('remove')->with($this->isInstanceOf('Xi\\Filelib\\Identifiable'));
     $im->removeMany($iter);
     $this->assertSame($first, $iter->first());
 }
Example #14
0
 /**
  * Deletes a folder
  *
  * @param  Folder           $folder
  * @throws FilelibException If folder could not be deleted.
  */
 public function deleteFolder(Folder $folder)
 {
     if ($this->findByFinder(new FileFinder(array('folder_id' => $folder->getId())))->count()) {
         throw new FolderNotEmptyException('Can not delete folder with files');
     }
     return $this->resolveAdapter()->deleteFolder($folder);
 }
Example #15
0
 /**
  * @param  ArrayIterator $iter
  * @return ArrayIterator
  */
 protected function exportFolders(ArrayIterator $iter)
 {
     $ret = new ArrayIterator(array());
     foreach ($iter as $folder) {
         $ret->append(Folder::create(array('id' => (string) $folder['id'], 'parent_id' => isset($folder['parent_id']) ? $folder['parent_id'] : null, 'name' => $folder['name'], 'url' => $folder['url'], 'uuid' => $folder['uuid'], 'data' => $folder['data'])));
     }
     return $ret;
 }
 /**
  * @param  Iterator      $iter
  * @return ArrayIterator
  */
 protected function exportFolders(Iterator $iter)
 {
     $ret = new ArrayIterator(array());
     foreach ($iter as $folder) {
         $ret->append(Folder::create(array('id' => $folder['id'], 'parent_id' => $folder['parent_id'], 'name' => $folder['foldername'], 'url' => $folder['folderurl'], 'uuid' => $folder['uuid'], 'data' => json_decode($folder['data'], true))));
     }
     return $ret;
 }
Example #17
0
 /**
  * @param  Folder        $folder Folder
  * @return ArrayCollection
  */
 public function findFiles(Folder $folder)
 {
     $files = $this->backend->findByFinder(new FileFinder(array('folder_id' => $folder->getId())));
     return $files;
 }
 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'))));
 }
 /**
  * @test
  */
 public function updatesRecursively()
 {
     $filelib = $this->getFilelib(false);
     $op = $filelib->getFolderRepository();
     $root = $op->findRoot();
     $folder = Folder::create(['name' => 'tussi', 'parent_id' => $root->getId()]);
     $folder2 = $op->create($folder);
     $folder3 = $op->create(Folder::create(['name' => 'watussi', 'parent_id' => $folder2->getId()]));
     $this->assertEquals('tussi/watussi', $folder3->getUrl());
     $file = $filelib->uploadFile(ROOT_TESTS . '/data/self-lussing-manatee.jpg', $folder3);
     $folder->setName('xooxer');
     $op->update($folder);
     $this->assertEquals('xooxer/watussi', $folder3->getUrl());
 }