public function testGetByIdMultipleStorages() { $manager = $this->getMock('\\OC\\Files\\Mount\\Manager'); /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->getMock('\\OC\\Files\\View'); $root = $this->getMock('\\OC\\Files\\Node\\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user)); $root->expects($this->any())->method('getUser')->will($this->returnValue($this->user)); $storage = $this->getMock('\\OC\\Files\\Storage\\Storage'); $mount1 = new Mount($storage, '/bar'); $mount2 = new Mount($storage, '/bar/foo/asd'); $cache = $this->getMock('\\OC\\Files\\Cache\\Cache', array(), array('')); $view->expects($this->any())->method('file_exists')->will($this->returnValue(true)); $storage->expects($this->any())->method('getCache')->will($this->returnValue($cache)); $cache->expects($this->any())->method('getPathById')->with('1')->will($this->returnValue('foo/qwerty')); $root->expects($this->any())->method('getMountsIn')->with('/bar/foo')->will($this->returnValue(array($mount2))); $root->expects($this->once())->method('getMount')->with('/bar/foo')->will($this->returnValue($mount1)); $node = new \OC\Files\Node\Folder($root, $view, '/bar/foo'); $result = $node->getById(1); $this->assertEquals(2, count($result)); $this->assertEquals('/bar/foo/qwerty', $result[0]->getPath()); $this->assertEquals('/bar/foo/asd/foo/qwerty', $result[1]->getPath()); }
/** * @dataProvider uniqueNameProvider */ public function testGetUniqueName($name, $existingFiles, $expected) { $manager = $this->getMock('\\OC\\Files\\Mount\\Manager'); $folderPath = '/bar/foo'; /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ $view = $this->getMock('\\OC\\Files\\View'); $root = $this->getMock('\\OC\\Files\\Node\\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user)); $view->expects($this->any())->method('file_exists')->will($this->returnCallback(function ($path) use($existingFiles, $folderPath) { foreach ($existingFiles as $existing) { if ($folderPath . '/' . $existing === $path) { return true; } } return false; })); $node = new \OC\Files\Node\Folder($root, $view, $folderPath); $this->assertEquals($expected, $node->getNonExistingName($name)); }
public function testIsSubNode() { $file = new Node(null, null, '/foo/bar'); $folder = new \OC\Files\Node\Folder(null, null, '/foo'); $this->assertTrue($folder->isSubNode($file)); $this->assertFalse($folder->isSubNode($folder)); $file = new Node(null, null, '/foobar'); $this->assertFalse($folder->isSubNode($file)); }