summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/connector/sabre/filesplugin.php
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-08-30 19:13:01 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2015-10-16 13:17:12 +0200
commitf2889dc6e4aa701f36081b314f38f620cbb1fc88 (patch)
tree8969d61c3dc2a71cd8eb1b745d88fc10782e1d75 /apps/dav/tests/unit/connector/sabre/filesplugin.php
parent4b9ec49285081137195c5852682b127a37ea8bfe (diff)
downloadnextcloud-server-f2889dc6e4aa701f36081b314f38f620cbb1fc88.tar.gz
nextcloud-server-f2889dc6e4aa701f36081b314f38f620cbb1fc88.zip
Consolidate webdav code - move all to one app
Diffstat (limited to 'apps/dav/tests/unit/connector/sabre/filesplugin.php')
-rw-r--r--apps/dav/tests/unit/connector/sabre/filesplugin.php254
1 files changed, 254 insertions, 0 deletions
diff --git a/apps/dav/tests/unit/connector/sabre/filesplugin.php b/apps/dav/tests/unit/connector/sabre/filesplugin.php
new file mode 100644
index 00000000000..a91ca7a4ff7
--- /dev/null
+++ b/apps/dav/tests/unit/connector/sabre/filesplugin.php
@@ -0,0 +1,254 @@
+<?php
+
+namespace Tests\Connector\Sabre;
+
+/**
+ * Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+class FilesPlugin extends \Test\TestCase {
+ const GETETAG_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::GETETAG_PROPERTYNAME;
+ const FILEID_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::FILEID_PROPERTYNAME;
+ const SIZE_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::SIZE_PROPERTYNAME;
+ const PERMISSIONS_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::PERMISSIONS_PROPERTYNAME;
+ const LASTMODIFIED_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::LASTMODIFIED_PROPERTYNAME;
+ const DOWNLOADURL_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::DOWNLOADURL_PROPERTYNAME;
+
+ /**
+ * @var \Sabre\DAV\Server
+ */
+ private $server;
+
+ /**
+ * @var \Sabre\DAV\Tree
+ */
+ private $tree;
+
+ /**
+ * @var \OCA\DAV\Connector\Sabre\FilesPlugin
+ */
+ private $plugin;
+
+ /**
+ * @var \OC\Files\View
+ */
+ private $view;
+
+ public function setUp() {
+ parent::setUp();
+ $this->server = $this->getMockBuilder('\Sabre\DAV\Server')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->tree = $this->getMockBuilder('\Sabre\DAV\Tree')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->view = $this->getMockBuilder('\OC\Files\View')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->plugin = new \OCA\DAV\Connector\Sabre\FilesPlugin($this->tree, $this->view);
+ $this->plugin->initialize($this->server);
+ }
+
+ private function createTestNode($class) {
+ $node = $this->getMockBuilder($class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $node->expects($this->any())
+ ->method('getId')
+ ->will($this->returnValue(123));
+
+ $this->tree->expects($this->any())
+ ->method('getNodeForPath')
+ ->with('/dummypath')
+ ->will($this->returnValue($node));
+
+ $node->expects($this->any())
+ ->method('getFileId')
+ ->will($this->returnValue(123));
+ $node->expects($this->any())
+ ->method('getEtag')
+ ->will($this->returnValue('"abc"'));
+ $node->expects($this->any())
+ ->method('getDavPermissions')
+ ->will($this->returnValue('DWCKMSR'));
+
+ return $node;
+ }
+
+ /**
+ */
+ public function testGetPropertiesForFile() {
+ $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
+
+ $propFind = new \Sabre\DAV\PropFind(
+ '/dummyPath',
+ array(
+ self::GETETAG_PROPERTYNAME,
+ self::FILEID_PROPERTYNAME,
+ self::SIZE_PROPERTYNAME,
+ self::PERMISSIONS_PROPERTYNAME,
+ self::DOWNLOADURL_PROPERTYNAME,
+ ),
+ 0
+ );
+
+ $node->expects($this->once())
+ ->method('getDirectDownload')
+ ->will($this->returnValue(array('url' => 'http://example.com/')));
+ $node->expects($this->never())
+ ->method('getSize');
+
+ $this->plugin->handleGetProperties(
+ $propFind,
+ $node
+ );
+
+ $this->assertEquals('"abc"', $propFind->get(self::GETETAG_PROPERTYNAME));
+ $this->assertEquals(123, $propFind->get(self::FILEID_PROPERTYNAME));
+ $this->assertEquals(null, $propFind->get(self::SIZE_PROPERTYNAME));
+ $this->assertEquals('DWCKMSR', $propFind->get(self::PERMISSIONS_PROPERTYNAME));
+ $this->assertEquals('http://example.com/', $propFind->get(self::DOWNLOADURL_PROPERTYNAME));
+ $this->assertEquals(array(self::SIZE_PROPERTYNAME), $propFind->get404Properties());
+ }
+
+ public function testGetPublicPermissions() {
+ $this->plugin = new \OCA\DAV\Connector\Sabre\FilesPlugin($this->tree, $this->view, true);
+ $this->plugin->initialize($this->server);
+
+ $propFind = new \Sabre\DAV\PropFind(
+ '/dummyPath',
+ [
+ self::PERMISSIONS_PROPERTYNAME,
+ ],
+ 0
+ );
+
+ $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
+ $node->expects($this->any())
+ ->method('getDavPermissions')
+ ->will($this->returnValue('DWCKMSR'));
+
+ $this->plugin->handleGetProperties(
+ $propFind,
+ $node
+ );
+
+ $this->assertEquals('DWCKR', $propFind->get(self::PERMISSIONS_PROPERTYNAME));
+ }
+
+ public function testGetPropertiesForDirectory() {
+ $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\Directory');
+
+ $propFind = new \Sabre\DAV\PropFind(
+ '/dummyPath',
+ array(
+ self::GETETAG_PROPERTYNAME,
+ self::FILEID_PROPERTYNAME,
+ self::SIZE_PROPERTYNAME,
+ self::PERMISSIONS_PROPERTYNAME,
+ self::DOWNLOADURL_PROPERTYNAME,
+ ),
+ 0
+ );
+
+ $node->expects($this->never())
+ ->method('getDirectDownload');
+ $node->expects($this->once())
+ ->method('getSize')
+ ->will($this->returnValue(1025));
+
+ $this->plugin->handleGetProperties(
+ $propFind,
+ $node
+ );
+
+ $this->assertEquals('"abc"', $propFind->get(self::GETETAG_PROPERTYNAME));
+ $this->assertEquals(123, $propFind->get(self::FILEID_PROPERTYNAME));
+ $this->assertEquals(1025, $propFind->get(self::SIZE_PROPERTYNAME));
+ $this->assertEquals('DWCKMSR', $propFind->get(self::PERMISSIONS_PROPERTYNAME));
+ $this->assertEquals(null, $propFind->get(self::DOWNLOADURL_PROPERTYNAME));
+ $this->assertEquals(array(self::DOWNLOADURL_PROPERTYNAME), $propFind->get404Properties());
+ }
+
+ public function testUpdateProps() {
+ $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
+
+ $testDate = 'Fri, 13 Feb 2015 00:01:02 GMT';
+
+ $node->expects($this->once())
+ ->method('touch')
+ ->with($testDate);
+
+ $node->expects($this->once())
+ ->method('setEtag')
+ ->with('newetag')
+ ->will($this->returnValue(true));
+
+ // properties to set
+ $propPatch = new \Sabre\DAV\PropPatch(array(
+ self::GETETAG_PROPERTYNAME => 'newetag',
+ self::LASTMODIFIED_PROPERTYNAME => $testDate
+ ));
+
+ $this->plugin->handleUpdateProperties(
+ '/dummypath',
+ $propPatch
+ );
+
+ $propPatch->commit();
+
+ $this->assertEmpty($propPatch->getRemainingMutations());
+
+ $result = $propPatch->getResult();
+ $this->assertEquals(200, $result[self::LASTMODIFIED_PROPERTYNAME]);
+ $this->assertEquals(200, $result[self::GETETAG_PROPERTYNAME]);
+ }
+
+ /**
+ * Testcase from https://github.com/owncloud/core/issues/5251
+ *
+ * |-FolderA
+ * |-text.txt
+ * |-test.txt
+ *
+ * FolderA is an incomming shared folder and there are no delete permissions.
+ * Thus moving /FolderA/test.txt to /test.txt should fail already on that check
+ *
+ * @expectedException \Sabre\DAV\Exception\Forbidden
+ * @expectedExceptionMessage FolderA/test.txt cannot be deleted
+ */
+ public function testMoveSrcNotDeletable() {
+ $fileInfoFolderATestTXT = $this->getMockBuilder('\OCP\Files\FileInfo')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $fileInfoFolderATestTXT->expects($this->once())
+ ->method('isDeletable')
+ ->willReturn(false);
+
+ $this->view->expects($this->once())
+ ->method('getFileInfo')
+ ->with('FolderA/test.txt')
+ ->willReturn($fileInfoFolderATestTXT);
+
+ $this->plugin->checkMove('FolderA/test.txt', 'test.txt');
+ }
+
+ public function testMoveSrcDeletable() {
+ $fileInfoFolderATestTXT = $this->getMockBuilder('\OCP\Files\FileInfo')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $fileInfoFolderATestTXT->expects($this->once())
+ ->method('isDeletable')
+ ->willReturn(true);
+
+ $this->view->expects($this->once())
+ ->method('getFileInfo')
+ ->with('FolderA/test.txt')
+ ->willReturn($fileInfoFolderATestTXT);
+
+ $this->plugin->checkMove('FolderA/test.txt', 'test.txt');
+ }
+}