aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/files/node/root.php
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2013-09-01 19:47:48 +0200
committerRobin Appelman <icewind@owncloud.com>2013-09-01 19:47:48 +0200
commita22f9ff301312bb24332edaacfb65c280cd8fcd8 (patch)
tree8c7f8793675a5ec7d7db4dd0cb50fc1b259efca0 /tests/lib/files/node/root.php
parent92e90c8eb995c886b3e9cd77c14e3f0b25b95cd7 (diff)
downloadnextcloud-server-a22f9ff301312bb24332edaacfb65c280cd8fcd8.tar.gz
nextcloud-server-a22f9ff301312bb24332edaacfb65c280cd8fcd8.zip
Provide an implementation of the fileapi for oc6 build on top of the old api
Diffstat (limited to 'tests/lib/files/node/root.php')
-rw-r--r--tests/lib/files/node/root.php106
1 files changed, 106 insertions, 0 deletions
diff --git a/tests/lib/files/node/root.php b/tests/lib/files/node/root.php
new file mode 100644
index 00000000000..0b356ec6d97
--- /dev/null
+++ b/tests/lib/files/node/root.php
@@ -0,0 +1,106 @@
+<?php
+/**
+ * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace Test\Files\Node;
+
+use OC\Files\Cache\Cache;
+use OC\Files\NotPermittedException;
+use OC\Files\Mount\Manager;
+
+class Root extends \PHPUnit_Framework_TestCase {
+ private $user;
+
+ public function setUp() {
+ $this->user = new \OC\User\User('', new \OC_User_Dummy);
+ }
+
+ public function testGet() {
+ $manager = new Manager();
+ /**
+ * @var \OC\Files\Storage\Storage $storage
+ */
+ $storage = $this->getMock('\OC\Files\Storage\Storage');
+ /**
+ * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
+ */
+ $view = $this->getMock('\OC\Files\View');
+ $root = new \OC\Files\Node\Root($manager, $view, $this->user);
+
+ $view->expects($this->once())
+ ->method('getFileInfo')
+ ->with('/bar/foo')
+ ->will($this->returnValue(array('fileid' => 10, 'path' => 'bar/foo', 'name', 'mimetype' => 'text/plain')));
+
+ $view->expects($this->once())
+ ->method('is_dir')
+ ->with('/bar/foo')
+ ->will($this->returnValue(false));
+
+ $view->expects($this->once())
+ ->method('file_exists')
+ ->with('/bar/foo')
+ ->will($this->returnValue(true));
+
+ $root->mount($storage, '');
+ $node = $root->get('/bar/foo');
+ $this->assertEquals(10, $node->getId());
+ $this->assertInstanceOf('\OC\Files\Node\File', $node);
+ }
+
+ /**
+ * @expectedException \OC\Files\NotFoundException
+ */
+ public function testGetNotFound() {
+ $manager = new Manager();
+ /**
+ * @var \OC\Files\Storage\Storage $storage
+ */
+ $storage = $this->getMock('\OC\Files\Storage\Storage');
+ /**
+ * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
+ */
+ $view = $this->getMock('\OC\Files\View');
+ $root = new \OC\Files\Node\Root($manager, $view, $this->user);
+
+ $view->expects($this->once())
+ ->method('file_exists')
+ ->with('/bar/foo')
+ ->will($this->returnValue(false));
+
+ $root->mount($storage, '');
+ $root->get('/bar/foo');
+ }
+
+ /**
+ * @expectedException \OC\Files\NotPermittedException
+ */
+ public function testGetInvalidPath() {
+ $manager = new Manager();
+ /**
+ * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
+ */
+ $view = $this->getMock('\OC\Files\View');
+ $root = new \OC\Files\Node\Root($manager, $view, $this->user);
+
+ $root->get('/../foo');
+ }
+
+ /**
+ * @expectedException \OC\Files\NotFoundException
+ */
+ public function testGetNoStorages() {
+ $manager = new Manager();
+ /**
+ * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view
+ */
+ $view = $this->getMock('\OC\Files\View');
+ $root = new \OC\Files\Node\Root($manager, $view, $this->user);
+
+ $root->get('/bar/foo');
+ }
+}