public function testBasicFolder() { $folder = $this->root->newFolder('/foo'); $this->assertTrue($this->root->nodeExists('/foo')); $file = $folder->newFile('/bar'); $this->assertTrue($this->root->nodeExists('/foo/bar')); $file->putContent('qwerty'); $listing = $folder->getDirectoryListing(); $this->assertEquals(1, count($listing)); $this->assertEquals($file->getId(), $listing[0]->getId()); $this->assertEquals($file->getStorage(), $listing[0]->getStorage()); $rootListing = $this->root->getDirectoryListing(); $this->assertEquals(2, count($rootListing)); $folder->move('/asd'); /** * @var \OC\Files\Node\File $file */ $file = $folder->get('/bar'); $this->assertInstanceOf('\\OC\\Files\\Node\\File', $file); $this->assertFalse($this->root->nodeExists('/foo/bar')); $this->assertTrue($this->root->nodeExists('/asd/bar')); $this->assertEquals('qwerty', $file->getContent()); $folder->move('/substorage/foo'); /** * @var \OC\Files\Node\File $file */ $file = $folder->get('/bar'); $this->assertInstanceOf('\\OC\\Files\\Node\\File', $file); $this->assertTrue($this->root->nodeExists('/substorage/foo/bar')); $this->assertEquals('qwerty', $file->getContent()); }
public function testPostDeleteMeta() { $connector = new \OC\Files\Node\HookConnector($this->root, $this->view); $connector->viewToNode(); $hookCalled = false; /** @var Node $hookNode */ $hookNode = null; $this->root->listen('\\OC\\Files', 'postDelete', function ($node) use(&$hookNode, &$hookCalled) { $hookCalled = true; $hookNode = $node; }); Filesystem::file_put_contents('test.txt', 'asd'); $info = Filesystem::getFileInfo('test.txt'); Filesystem::unlink('test.txt'); $this->assertTrue($hookCalled); $this->assertEquals($hookNode->getId(), $info->getId()); }
/** * @param callable $operation * @param string $expectedHook * @dataProvider viewToNodeProviderCopyRename */ public function testViewToNodeCopyRename(callable $operation, $expectedHook) { $connector = new \OC\Files\Node\HookConnector($this->root, $this->view); $connector->viewToNode(); $hookCalled = false; /** @var Node $hookSourceNode */ $hookSourceNode = null; /** @var Node $hookTargetNode */ $hookTargetNode = null; $this->root->listen('\\OC\\Files', $expectedHook, function ($sourceNode, $targetNode) use(&$hookCalled, &$hookSourceNode, &$hookTargetNode) { $hookCalled = true; $hookSourceNode = $sourceNode; $hookTargetNode = $targetNode; }); $operation(); $this->assertTrue($hookCalled); $this->assertEquals('/' . $this->userId . '/files/source', $hookSourceNode->getPath()); $this->assertEquals('/' . $this->userId . '/files/target', $hookTargetNode->getPath()); }
/** * @return Node */ public function getParent() { return $this->root->get(dirname($this->path)); }
public function postCopy($arguments) { $source = $this->getNodeForPath($arguments['oldpath']); $target = $this->getNodeForPath($arguments['newpath']); $this->root->emit('\\OC\\Files', 'postCopy', [$source, $target]); }