summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-02-12 12:29:01 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-02-23 22:27:23 +0100
commit9f6dcb9d3e2f43f336dafeb739e04ba9614d9b5f (patch)
treefa72017a9bf76c526ddb3dfe0969f0584a4a7d67 /tests
parent66e3211fd8a57b0fb296d1dcc980272721e9f99d (diff)
downloadnextcloud-server-9f6dcb9d3e2f43f336dafeb739e04ba9614d9b5f.tar.gz
nextcloud-server-9f6dcb9d3e2f43f336dafeb739e04ba9614d9b5f.zip
Sabre Update to 2.1
- VObject fixes for Sabre\VObject 3.3 - Remove VObject property workarounds - Added prefetching for tags in sabre tags plugin - Moved oc_properties logic to separate PropertyStorage backend (WIP) - Fixed Sabre connector namespaces - Improved files plugin to handle props on-demand - Moved allowed props from server class to files plugin - Fixed tags caching for files that are known to have no tags (less queries) - Added/fixed unit tests for Sabre FilesPlugin, TagsPlugin - Replace OC\Connector\Sabre\Request with direct call to httpRequest->setUrl() - Fix exception detection in DAV client when using Sabre\DAV\Client - Added setETag() on Node instead of using the static FileSystem - Also preload tags/props when depth is infinity
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/connector/sabre/custompropertiesbackend.php248
-rw-r--r--tests/lib/connector/sabre/directory.php21
-rw-r--r--tests/lib/connector/sabre/file.php18
-rw-r--r--tests/lib/connector/sabre/filesplugin.php174
-rw-r--r--tests/lib/connector/sabre/node.php2
-rw-r--r--tests/lib/connector/sabre/objecttree.php123
-rw-r--r--tests/lib/connector/sabre/principal.php3
-rw-r--r--tests/lib/connector/sabre/quotaplugin.php38
-rw-r--r--tests/lib/connector/sabre/tagsplugin.php204
-rw-r--r--tests/lib/vobject.php40
10 files changed, 721 insertions, 150 deletions
diff --git a/tests/lib/connector/sabre/custompropertiesbackend.php b/tests/lib/connector/sabre/custompropertiesbackend.php
new file mode 100644
index 00000000000..ee0c3c4e53d
--- /dev/null
+++ b/tests/lib/connector/sabre/custompropertiesbackend.php
@@ -0,0 +1,248 @@
+<?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 CustomPropertiesBackend extends \Test\TestCase {
+
+ /**
+ * @var \Sabre\DAV\Server
+ */
+ private $server;
+
+ /**
+ * @var \Sabre\DAV\ObjectTree
+ */
+ private $tree;
+
+ /**
+ * @var \OC\Connector\Sabre\CustomPropertiesBackend
+ */
+ private $plugin;
+
+ /**
+ * @var \OCP\IUser
+ */
+ private $user;
+
+ public function setUp() {
+ parent::setUp();
+ $this->server = new \Sabre\DAV\Server();
+ $this->tree = $this->getMockBuilder('\Sabre\DAV\Tree')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $userId = $this->getUniqueID('testcustompropertiesuser');
+
+ $this->user = $this->getMock('\OCP\IUser');
+ $this->user->expects($this->any())
+ ->method('getUID')
+ ->will($this->returnValue($userId));
+
+ $this->plugin = new \OC\Connector\Sabre\CustomPropertiesBackend(
+ $this->tree,
+ \OC::$server->getDatabaseConnection(),
+ $this->user
+ );
+ }
+
+ public function tearDown() {
+ $connection = \OC::$server->getDatabaseConnection();
+ $deleteStatement = $connection->prepare(
+ 'DELETE FROM `*PREFIX*properties`' .
+ ' WHERE `userid` = ?'
+ );
+ $deleteStatement->execute(
+ array(
+ $this->user->getUID(),
+ )
+ );
+ $deleteStatement->closeCursor();
+ }
+
+ private function createTestNode($class) {
+ $node = $this->getMockBuilder($class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $node->expects($this->any())
+ ->method('getId')
+ ->will($this->returnValue(123));
+
+ $node->expects($this->any())
+ ->method('getPath')
+ ->will($this->returnValue('/dummypath'));
+
+ return $node;
+ }
+
+ private function applyDefaultProps($path = '/dummypath') {
+ // properties to set
+ $propPatch = new \Sabre\DAV\PropPatch(array(
+ 'customprop' => 'value1',
+ 'customprop2' => 'value2',
+ ));
+
+ $this->plugin->propPatch(
+ $path,
+ $propPatch
+ );
+
+ $propPatch->commit();
+
+ $this->assertEmpty($propPatch->getRemainingMutations());
+
+ $result = $propPatch->getResult();
+ $this->assertEquals(200, $result['customprop']);
+ $this->assertEquals(200, $result['customprop2']);
+ }
+
+ /**
+ * Test setting/getting properties
+ */
+ public function testSetGetPropertiesForFile() {
+ $node = $this->createTestNode('\OC\Connector\Sabre\File');
+ $this->tree->expects($this->any())
+ ->method('getNodeForPath')
+ ->with('/dummypath')
+ ->will($this->returnValue($node));
+
+ $this->applyDefaultProps();
+
+ $propFind = new \Sabre\DAV\PropFind(
+ '/dummypath',
+ array(
+ 'customprop',
+ 'customprop2',
+ 'unsetprop',
+ ),
+ 0
+ );
+
+ $this->plugin->propFind(
+ '/dummypath',
+ $propFind
+ );
+
+ $this->assertEquals('value1', $propFind->get('customprop'));
+ $this->assertEquals('value2', $propFind->get('customprop2'));
+ $this->assertEquals(array('unsetprop'), $propFind->get404Properties());
+ }
+
+ /**
+ * Test getting properties from directory
+ */
+ public function testGetPropertiesForDirectory() {
+ $rootNode = $this->createTestNode('\OC\Connector\Sabre\Directory');
+
+ $nodeSub = $this->getMockBuilder('\OC\Connector\Sabre\File')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $nodeSub->expects($this->any())
+ ->method('getId')
+ ->will($this->returnValue(456));
+
+ $nodeSub->expects($this->any())
+ ->method('getPath')
+ ->will($this->returnValue('/dummypath/test.txt'));
+
+ $rootNode->expects($this->once())
+ ->method('getChildren')
+ ->will($this->returnValue(array($nodeSub)));
+
+ $this->tree->expects($this->at(0))
+ ->method('getNodeForPath')
+ ->with('/dummypath')
+ ->will($this->returnValue($rootNode));
+
+ $this->tree->expects($this->at(1))
+ ->method('getNodeForPath')
+ ->with('/dummypath/test.txt')
+ ->will($this->returnValue($nodeSub));
+
+ $this->tree->expects($this->at(2))
+ ->method('getNodeForPath')
+ ->with('/dummypath')
+ ->will($this->returnValue($rootNode));
+
+ $this->tree->expects($this->at(3))
+ ->method('getNodeForPath')
+ ->with('/dummypath/test.txt')
+ ->will($this->returnValue($nodeSub));
+
+ $this->applyDefaultProps('/dummypath');
+ $this->applyDefaultProps('/dummypath/test.txt');
+
+ $propNames = array(
+ 'customprop',
+ 'customprop2',
+ 'unsetprop',
+ );
+
+ $propFindRoot = new \Sabre\DAV\PropFind(
+ '/dummypath',
+ $propNames,
+ 1
+ );
+
+ $propFindSub = new \Sabre\DAV\PropFind(
+ '/dummypath/test.txt',
+ $propNames,
+ 0
+ );
+
+ $this->plugin->propFind(
+ '/dummypath',
+ $propFindRoot
+ );
+
+ $this->plugin->propFind(
+ '/dummypath/test.txt',
+ $propFindSub
+ );
+
+ // TODO: find a way to assert that no additional SQL queries were
+ // run while doing the second propFind
+
+ $this->assertEquals('value1', $propFindRoot->get('customprop'));
+ $this->assertEquals('value2', $propFindRoot->get('customprop2'));
+ $this->assertEquals(array('unsetprop'), $propFindRoot->get404Properties());
+
+ $this->assertEquals('value1', $propFindSub->get('customprop'));
+ $this->assertEquals('value2', $propFindSub->get('customprop2'));
+ $this->assertEquals(array('unsetprop'), $propFindSub->get404Properties());
+ }
+
+ /**
+ * Test delete property
+ */
+ public function testDeleteProperty() {
+ $node = $this->createTestNode('\OC\Connector\Sabre\File');
+ $this->tree->expects($this->any())
+ ->method('getNodeForPath')
+ ->with('/dummypath')
+ ->will($this->returnValue($node));
+
+ $this->applyDefaultProps();
+
+ $propPatch = new \Sabre\DAV\PropPatch(array(
+ 'customprop' => null,
+ ));
+
+ $this->plugin->propPatch(
+ '/dummypath',
+ $propPatch
+ );
+
+ $propPatch->commit();
+
+ $this->assertEmpty($propPatch->getRemainingMutations());
+
+ $result = $propPatch->getResult();
+ $this->assertEquals(204, $result['customprop']);
+ }
+}
diff --git a/tests/lib/connector/sabre/directory.php b/tests/lib/connector/sabre/directory.php
index 599a6ca3f7c..e7fbd1d27b6 100644
--- a/tests/lib/connector/sabre/directory.php
+++ b/tests/lib/connector/sabre/directory.php
@@ -27,7 +27,7 @@ class Test_OC_Connector_Sabre_Directory extends \Test\TestCase {
->method('getPath')
->will($this->returnValue(''));
- return new OC_Connector_Sabre_Directory($this->view, $this->info);
+ return new \OC\Connector\Sabre\Directory($this->view, $this->info);
}
/**
@@ -131,7 +131,7 @@ class Test_OC_Connector_Sabre_Directory extends \Test\TestCase {
->method('getRelativePath')
->will($this->returnValue(''));
- $dir = new OC_Connector_Sabre_Directory($this->view, $this->info);
+ $dir = new \OC\Connector\Sabre\Directory($this->view, $this->info);
$nodes = $dir->getChildren();
$this->assertEquals(2, count($nodes));
@@ -139,21 +139,6 @@ class Test_OC_Connector_Sabre_Directory extends \Test\TestCase {
// calling a second time just returns the cached values,
// does not call getDirectoryContents again
$nodes = $dir->getChildren();
-
- $properties = array('testprop', OC_Connector_Sabre_Node::GETETAG_PROPERTYNAME);
- $this->assertEquals(2, count($nodes));
- $this->assertEquals(
- array(
- OC_Connector_Sabre_Node::GETETAG_PROPERTYNAME => '"abc"'
- ),
- $nodes[0]->getProperties($properties)
- );
- $this->assertEquals(
- array(
- OC_Connector_Sabre_Node::GETETAG_PROPERTYNAME => '"def"'
- ),
- $nodes[1]->getProperties($properties)
- );
}
public function testGetQuotaInfo() {
@@ -182,7 +167,7 @@ class Test_OC_Connector_Sabre_Directory extends \Test\TestCase {
->method('getStorage')
->will($this->returnValue($storage));
- $dir = new OC_Connector_Sabre_Directory($this->view, $this->info);
+ $dir = new \OC\Connector\Sabre\Directory($this->view, $this->info);
$this->assertEquals([200, 800], $dir->getQuotaInfo()); //200 used, 800 free
}
}
diff --git a/tests/lib/connector/sabre/file.php b/tests/lib/connector/sabre/file.php
index 33dc78f87d8..2ef5fd794be 100644
--- a/tests/lib/connector/sabre/file.php
+++ b/tests/lib/connector/sabre/file.php
@@ -26,7 +26,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase {
'permissions'=>\OCP\Constants::PERMISSION_ALL
), null);
- $file = new OC_Connector_Sabre_File($view, $info);
+ $file = new \OC\Connector\Sabre\File($view, $info);
// action
$file->put('test data');
@@ -52,7 +52,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase {
'permissions' => \OCP\Constants::PERMISSION_ALL
), null);
- $file = new OC_Connector_Sabre_File($view, $info);
+ $file = new \OC\Connector\Sabre\File($view, $info);
$this->assertNotEmpty($file->put('test data'));
}
@@ -86,7 +86,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase {
'permissions' => \OCP\Constants::PERMISSION_ALL
), null);
- $file = new OC_Connector_Sabre_File($view, $info);
+ $file = new \OC\Connector\Sabre\File($view, $info);
// action
$file->put('test data');
@@ -109,7 +109,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase {
$info = new \OC\Files\FileInfo('/super*star.txt', null, null, array(
'permissions' => \OCP\Constants::PERMISSION_ALL
), null);
- $file = new OC_Connector_Sabre_File($view, $info);
+ $file = new \OC\Connector\Sabre\File($view, $info);
// action
$file->put('test data');
@@ -130,7 +130,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase {
$info = new \OC\Files\FileInfo('/super*star.txt', null, null, array(
'permissions' => \OCP\Constants::PERMISSION_ALL
), null);
- $file = new OC_Connector_Sabre_File($view, $info);
+ $file = new \OC\Connector\Sabre\File($view, $info);
$file->setName('/super*star.txt');
}
@@ -163,7 +163,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase {
'permissions' => \OCP\Constants::PERMISSION_ALL
), null);
- $file = new OC_Connector_Sabre_File($view, $info);
+ $file = new \OC\Connector\Sabre\File($view, $info);
// action
$file->put('test data');
@@ -185,7 +185,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase {
'permissions' => \OCP\Constants::PERMISSION_ALL
), null);
- $file = new OC_Connector_Sabre_File($view, $info);
+ $file = new \OC\Connector\Sabre\File($view, $info);
// action
$file->delete();
@@ -203,7 +203,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase {
'permissions' => 0
), null);
- $file = new OC_Connector_Sabre_File($view, $info);
+ $file = new \OC\Connector\Sabre\File($view, $info);
// action
$file->delete();
@@ -226,7 +226,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase {
'permissions' => \OCP\Constants::PERMISSION_ALL
), null);
- $file = new OC_Connector_Sabre_File($view, $info);
+ $file = new \OC\Connector\Sabre\File($view, $info);
// action
$file->delete();
diff --git a/tests/lib/connector/sabre/filesplugin.php b/tests/lib/connector/sabre/filesplugin.php
new file mode 100644
index 00000000000..54d43d66dda
--- /dev/null
+++ b/tests/lib/connector/sabre/filesplugin.php
@@ -0,0 +1,174 @@
+<?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 = \OC\Connector\Sabre\FilesPlugin::GETETAG_PROPERTYNAME;
+ const FILEID_PROPERTYNAME = \OC\Connector\Sabre\FilesPlugin::FILEID_PROPERTYNAME;
+ const SIZE_PROPERTYNAME = \OC\Connector\Sabre\FilesPlugin::SIZE_PROPERTYNAME;
+ const PERMISSIONS_PROPERTYNAME = \OC\Connector\Sabre\FilesPlugin::PERMISSIONS_PROPERTYNAME;
+ const GETLASTMODIFIED_PROPERTYNAME = \OC\Connector\Sabre\FilesPlugin::GETLASTMODIFIED_PROPERTYNAME;
+ const DOWNLOADURL_PROPERTYNAME = \OC\Connector\Sabre\FilesPlugin::DOWNLOADURL_PROPERTYNAME;
+
+ /**
+ * @var \Sabre\DAV\Server
+ */
+ private $server;
+
+ /**
+ * @var \Sabre\DAV\ObjectTree
+ */
+ private $tree;
+
+ /**
+ * @var \OC\Connector\Sabre\FilesPlugin
+ */
+ private $plugin;
+
+ public function setUp() {
+ parent::setUp();
+ $this->server = new \Sabre\DAV\Server();
+ $this->tree = $this->getMockBuilder('\Sabre\DAV\Tree')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->plugin = new \OC\Connector\Sabre\FilesPlugin($this->tree);
+ $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('R'));
+
+ return $node;
+ }
+
+ /**
+ */
+ public function testGetPropertiesForFile() {
+ $node = $this->createTestNode('\OC\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('R', $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 testGetPropertiesForDirectory() {
+ $node = $this->createTestNode('\OC\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('R', $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('\OC\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::GETLASTMODIFIED_PROPERTYNAME => $testDate
+ ));
+
+ $this->plugin->handleUpdateProperties(
+ '/dummypath',
+ $propPatch
+ );
+
+ $propPatch->commit();
+
+ $this->assertEmpty($propPatch->getRemainingMutations());
+
+ $result = $propPatch->getResult();
+ $this->assertEquals(200, $result[self::GETLASTMODIFIED_PROPERTYNAME]);
+ $this->assertEquals(200, $result[self::GETETAG_PROPERTYNAME]);
+ }
+
+}
diff --git a/tests/lib/connector/sabre/node.php b/tests/lib/connector/sabre/node.php
index 1e927deed44..e1ae05b2170 100644
--- a/tests/lib/connector/sabre/node.php
+++ b/tests/lib/connector/sabre/node.php
@@ -49,7 +49,7 @@ class Node extends \Test\TestCase {
->will($this->returnValue($type));
$view = $this->getMock('\OC\Files\View');
- $node = new \OC_Connector_Sabre_File($view, $info);
+ $node = new \OC\Connector\Sabre\File($view, $info);
$this->assertEquals($expected, $node->getDavPermissions());
}
}
diff --git a/tests/lib/connector/sabre/objecttree.php b/tests/lib/connector/sabre/objecttree.php
index 2548066214b..3c972fe6f0f 100644
--- a/tests/lib/connector/sabre/objecttree.php
+++ b/tests/lib/connector/sabre/objecttree.php
@@ -10,7 +10,7 @@ namespace Test\OC\Connector\Sabre;
use OC\Files\FileInfo;
-use OC_Connector_Sabre_Directory;
+use OC\Connector\Sabre\Directory;
use PHPUnit_Framework_TestCase;
class TestDoubleFileView extends \OC\Files\View {
@@ -103,7 +103,7 @@ class ObjectTree extends \Test\TestCase {
$info = new FileInfo('', null, null, array(), null);
- $rootDir = new OC_Connector_Sabre_Directory($view, $info);
+ $rootDir = new Directory($view, $info);
$objectTree = $this->getMock('\OC\Connector\Sabre\ObjectTree',
array('nodeExists', 'getNodeForPath'),
array($rootDir, $view));
@@ -119,4 +119,123 @@ class ObjectTree extends \Test\TestCase {
$objectTree->move($source, $dest);
}
+ /**
+ * @dataProvider nodeForPathProvider
+ */
+ public function testGetNodeForPath(
+ $inputFileName,
+ $fileInfoQueryPath,
+ $outputFileName,
+ $type,
+ $enableChunkingHeader
+ ) {
+
+ if ($enableChunkingHeader) {
+ $_SERVER['HTTP_OC_CHUNKED'] = true;
+ }
+
+ $rootNode = $this->getMockBuilder('\OC\Connector\Sabre\Directory')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $mountManager = $this->getMock('\OC\Files\Mount\Manager');
+ $view = $this->getMock('\OC\Files\View');
+ $fileInfo = $this->getMock('\OCP\Files\FileInfo');
+ $fileInfo->expects($this->once())
+ ->method('getType')
+ ->will($this->returnValue($type));
+ $fileInfo->expects($this->once())
+ ->method('getName')
+ ->will($this->returnValue($outputFileName));
+
+ $view->expects($this->once())
+ ->method('getFileInfo')
+ ->with($fileInfoQueryPath)
+ ->will($this->returnValue($fileInfo));
+
+ $tree = new \OC\Connector\Sabre\ObjectTree();
+ $tree->init($rootNode, $view, $mountManager);
+
+ $node = $tree->getNodeForPath($inputFileName);
+
+ $this->assertNotNull($node);
+ $this->assertEquals($outputFileName, $node->getName());
+
+ if ($type === 'file') {
+ $this->assertTrue($node instanceof \OC\Connector\Sabre\File);
+ } else {
+ $this->assertTrue($node instanceof \OC\Connector\Sabre\Directory);
+ }
+
+ unset($_SERVER['HTTP_OC_CHUNKED']);
+ }
+
+ function nodeForPathProvider() {
+ return array(
+ // regular file
+ array(
+ 'regularfile.txt',
+ 'regularfile.txt',
+ 'regularfile.txt',
+ 'file',
+ false
+ ),
+ // regular directory
+ array(
+ 'regulardir',
+ 'regulardir',
+ 'regulardir',
+ 'dir',
+ false
+ ),
+ // regular file with chunking
+ array(
+ 'regularfile.txt',
+ 'regularfile.txt',
+ 'regularfile.txt',
+ 'file',
+ true
+ ),
+ // regular directory with chunking
+ array(
+ 'regulardir',
+ 'regulardir',
+ 'regulardir',
+ 'dir',
+ true
+ ),
+ // file with chunky file name
+ array(
+ 'regularfile.txt-chunking-123566789-10-1',
+ 'regularfile.txt',
+ 'regularfile.txt',
+ 'file',
+ true
+ ),
+ // regular file in subdir
+ array(
+ 'subdir/regularfile.txt',
+ 'subdir/regularfile.txt',
+ 'regularfile.txt',
+ 'file',
+ false
+ ),
+ // regular directory in subdir
+ array(
+ 'subdir/regulardir',
+ 'subdir/regulardir',
+ 'regulardir',
+ 'dir',
+ false
+ ),
+ // file with chunky file name in subdir
+ array(
+ 'subdir/regularfile.txt-chunking-123566789-10-1',
+ 'subdir/regularfile.txt',
+ 'regularfile.txt',
+ 'file',
+ true
+ ),
+ );
+ }
+
}
diff --git a/tests/lib/connector/sabre/principal.php b/tests/lib/connector/sabre/principal.php
index 5d13aa4421e..1841a79bec7 100644
--- a/tests/lib/connector/sabre/principal.php
+++ b/tests/lib/connector/sabre/principal.php
@@ -10,6 +10,7 @@
namespace Test\Connector\Sabre;
+use \Sabre\DAV\PropPatch;
use OCP\IUserManager;
use OCP\IConfig;
@@ -240,7 +241,7 @@ class Principal extends \Test\TestCase {
}
public function testUpdatePrincipal() {
- $this->assertSame(0, $this->connector->updatePrincipal('foo', []));
+ $this->assertSame(0, $this->connector->updatePrincipal('foo', new PropPatch(array())));
}
public function testSearchPrincipals() {
diff --git a/tests/lib/connector/sabre/quotaplugin.php b/tests/lib/connector/sabre/quotaplugin.php
index f08637854ce..48f8f319ae4 100644
--- a/tests/lib/connector/sabre/quotaplugin.php
+++ b/tests/lib/connector/sabre/quotaplugin.php
@@ -14,14 +14,14 @@ class Test_OC_Connector_Sabre_QuotaPlugin extends \Test\TestCase {
private $server;
/**
- * @var OC_Connector_Sabre_QuotaPlugin
+ * @var \OC\Connector\Sabre\QuotaPlugin
*/
private $plugin;
private function init($quota) {
$view = $this->buildFileViewMock($quota);
$this->server = new \Sabre\DAV\Server();
- $this->plugin = new OC_Connector_Sabre_QuotaPlugin($view);
+ $this->plugin = new \OC\Connector\Sabre\QuotaPlugin($view);
$this->plugin->initialize($this->server);
}
@@ -30,7 +30,7 @@ class Test_OC_Connector_Sabre_QuotaPlugin extends \Test\TestCase {
*/
public function testLength($expected, $headers) {
$this->init(0);
- $this->server->httpRequest = new \Sabre\HTTP\Request($headers);
+ $this->server->httpRequest = new \Sabre\HTTP\Request(null, null, $headers);
$length = $this->plugin->getLength();
$this->assertEquals($expected, $length);
}
@@ -41,7 +41,7 @@ class Test_OC_Connector_Sabre_QuotaPlugin extends \Test\TestCase {
public function testCheckQuota($quota, $headers) {
$this->init($quota);
- $this->server->httpRequest = new Sabre\HTTP\Request($headers);
+ $this->server->httpRequest = new \Sabre\HTTP\Request(null, null, $headers);
$result = $this->plugin->checkQuota('');
$this->assertTrue($result);
}
@@ -53,39 +53,39 @@ class Test_OC_Connector_Sabre_QuotaPlugin extends \Test\TestCase {
public function testCheckExceededQuota($quota, $headers) {
$this->init($quota);
- $this->server->httpRequest = new Sabre\HTTP\Request($headers);
+ $this->server->httpRequest = new \Sabre\HTTP\Request(null, null, $headers);
$this->plugin->checkQuota('');
}
public function quotaOkayProvider() {
return array(
array(1024, array()),
- array(1024, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')),
- array(1024, array('HTTP_CONTENT_LENGTH' => '512')),
- array(1024, array('HTTP_OC_TOTAL_LENGTH' => '1024', 'HTTP_CONTENT_LENGTH' => '512')),
- // \OCP\Files\FileInfo::SPACE_UNKNOWN = -2
+ array(1024, array('X-EXPECTED-ENTITY-LENGTH' => '1024')),
+ array(1024, array('CONTENT-LENGTH' => '512')),
+ array(1024, array('OC-TOTAL-LENGTH' => '1024', 'CONTENT-LENGTH' => '512')),
+ // \OCP\Files\FileInfo::SPACE-UNKNOWN = -2
array(-2, array()),
- array(-2, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')),
- array(-2, array('HTTP_CONTENT_LENGTH' => '512')),
- array(-2, array('HTTP_OC_TOTAL_LENGTH' => '1024', 'HTTP_CONTENT_LENGTH' => '512')),
+ array(-2, array('X-EXPECTED-ENTITY-LENGTH' => '1024')),
+ array(-2, array('CONTENT-LENGTH' => '512')),
+ array(-2, array('OC-TOTAL-LENGTH' => '1024', 'CONTENT-LENGTH' => '512')),
);
}
public function quotaExceededProvider() {
return array(
- array(1023, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')),
- array(511, array('HTTP_CONTENT_LENGTH' => '512')),
- array(2047, array('HTTP_OC_TOTAL_LENGTH' => '2048', 'HTTP_CONTENT_LENGTH' => '1024')),
+ array(1023, array('X-EXPECTED-ENTITY-LENGTH' => '1024')),
+ array(511, array('CONTENT-LENGTH' => '512')),
+ array(2047, array('OC-TOTAL-LENGTH' => '2048', 'CONTENT-LENGTH' => '1024')),
);
}
public function lengthProvider() {
return array(
array(null, array()),
- array(1024, array('HTTP_X_EXPECTED_ENTITY_LENGTH' => '1024')),
- array(512, array('HTTP_CONTENT_LENGTH' => '512')),
- array(2048, array('HTTP_OC_TOTAL_LENGTH' => '2048', 'HTTP_CONTENT_LENGTH' => '1024')),
- array(4096, array('HTTP_OC_TOTAL_LENGTH' => '2048', 'HTTP_X_EXPECTED_ENTITY_LENGTH' => '4096')),
+ array(1024, array('X-EXPECTED-ENTITY-LENGTH' => '1024')),
+ array(512, array('CONTENT-LENGTH' => '512')),
+ array(2048, array('OC-TOTAL-LENGTH' => '2048', 'CONTENT-LENGTH' => '1024')),
+ array(4096, array('OC-TOTAL-LENGTH' => '2048', 'X-EXPECTED-ENTITY-LENGTH' => '4096')),
);
}
diff --git a/tests/lib/connector/sabre/tagsplugin.php b/tests/lib/connector/sabre/tagsplugin.php
index 2afea061ec3..f8af73fecfb 100644
--- a/tests/lib/connector/sabre/tagsplugin.php
+++ b/tests/lib/connector/sabre/tagsplugin.php
@@ -42,7 +42,7 @@ class TagsPlugin extends \Test\TestCase {
public function setUp() {
parent::setUp();
$this->server = new \Sabre\DAV\Server();
- $this->tree = $this->getMockBuilder('\Sabre\DAV\ObjectTree')
+ $this->tree = $this->getMockBuilder('\Sabre\DAV\Tree')
->disableOriginalConstructor()
->getMock();
$this->tagger = $this->getMock('\OCP\ITags');
@@ -59,7 +59,7 @@ class TagsPlugin extends \Test\TestCase {
* @dataProvider tagsGetPropertiesDataProvider
*/
public function testGetProperties($tags, $requestedProperties, $expectedProperties) {
- $node = $this->getMockBuilder('\OC_Connector_Sabre_Node')
+ $node = $this->getMockBuilder('\OC\Connector\Sabre\Node')
->disableOriginalConstructor()
->getMock();
$node->expects($this->any())
@@ -76,29 +76,35 @@ class TagsPlugin extends \Test\TestCase {
->with($this->equalTo(array(123)))
->will($this->returnValue(array(123 => $tags)));
- $returnedProperties = array();
-
- $this->plugin->beforeGetProperties(
- '',
- $node,
+ $propFind = new \Sabre\DAV\PropFind(
+ '/dummyPath',
$requestedProperties,
- $returnedProperties
+ 0
);
- $this->assertEquals($expectedProperties, $returnedProperties);
+ $this->plugin->handleGetProperties(
+ $propFind,
+ $node
+ );
+
+ $result = $propFind->getResultForMultiStatus();
+
+ $this->assertEmpty($result[404]);
+ unset($result[404]);
+ $this->assertEquals($expectedProperties, $result);
}
/**
* @dataProvider tagsGetPropertiesDataProvider
*/
public function testPreloadThenGetProperties($tags, $requestedProperties, $expectedProperties) {
- $node1 = $this->getMockBuilder('\OC_Connector_Sabre_File')
+ $node1 = $this->getMockBuilder('\OC\Connector\Sabre\File')
->disableOriginalConstructor()
->getMock();
$node1->expects($this->any())
->method('getId')
->will($this->returnValue(111));
- $node2 = $this->getMockBuilder('\OC_Connector_Sabre_File')
+ $node2 = $this->getMockBuilder('\OC\Connector\Sabre\File')
->disableOriginalConstructor()
->getMock();
$node2->expects($this->any())
@@ -113,7 +119,7 @@ class TagsPlugin extends \Test\TestCase {
$expectedCallCount = 1;
}
- $node = $this->getMockBuilder('\OC_Connector_Sabre_Directory')
+ $node = $this->getMockBuilder('\OC\Connector\Sabre\Directory')
->disableOriginalConstructor()
->getMock();
$node->expects($this->any())
@@ -123,14 +129,9 @@ class TagsPlugin extends \Test\TestCase {
->method('getChildren')
->will($this->returnValue(array($node1, $node2)));
- $this->tree->expects($this->once())
- ->method('getNodeForPath')
- ->with('/subdir')
- ->will($this->returnValue($node));
-
$this->tagger->expects($this->exactly($expectedCallCount))
->method('getTagsForObjects')
- ->with($this->equalTo(array(111, 222)))
+ ->with($this->equalTo(array(123, 111, 222)))
->will($this->returnValue(
array(
111 => $tags,
@@ -138,22 +139,41 @@ class TagsPlugin extends \Test\TestCase {
)
));
- $returnedProperties = array();
-
- $this->plugin->beforeGetPropertiesForPath(
+ // simulate sabre recursive PROPFIND traversal
+ $propFindRoot = new \Sabre\DAV\PropFind(
'/subdir',
$requestedProperties,
1
);
-
- $this->plugin->beforeGetProperties(
+ $propFind1 = new \Sabre\DAV\PropFind(
'/subdir/test.txt',
- $node1,
$requestedProperties,
- $returnedProperties
+ 0
+ );
+ $propFind2 = new \Sabre\DAV\PropFind(
+ '/subdir/test2.txt',
+ $requestedProperties,
+ 0
);
- $this->assertEquals($expectedProperties, $returnedProperties);
+ $this->plugin->handleGetProperties(
+ $propFindRoot,
+ $node
+ );
+ $this->plugin->handleGetProperties(
+ $propFind1,
+ $node1
+ );
+ $this->plugin->handleGetProperties(
+ $propFind2,
+ $node2
+ );
+
+ $result = $propFind1->getResultForMultiStatus();
+
+ $this->assertEmpty($result[404]);
+ unset($result[404]);
+ $this->assertEquals($expectedProperties, $result);
}
function tagsGetPropertiesDataProvider() {
@@ -193,7 +213,9 @@ class TagsPlugin extends \Test\TestCase {
array(
array('tag1', 'tag2', self::TAG_FAVORITE),
array(),
- array(),
+ array(
+ 200 => array()
+ ),
),
// request both with none set, receive both
array(
@@ -212,13 +234,18 @@ class TagsPlugin extends \Test\TestCase {
public function testUpdateTags() {
// this test will replace the existing tags "tagremove" with "tag1" and "tag2"
// and keep "tagkeep"
- $node = $this->getMockBuilder('\OC_Connector_Sabre_Node')
+ $node = $this->getMockBuilder('\OC\Connector\Sabre\Node')
->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));
+
$this->tagger->expects($this->at(0))
->method('getTagsForObjects')
->with($this->equalTo(array(123)))
@@ -238,58 +265,109 @@ class TagsPlugin extends \Test\TestCase {
->with(123, 'tagremove');
// properties to set
- $properties = array(
+ $propPatch = new \Sabre\DAV\PropPatch(array(
self::TAGS_PROPERTYNAME => new \OC\Connector\Sabre\TagList(array('tag1', 'tag2', 'tagkeep'))
- );
- $result = array();
+ ));
- $this->plugin->updateProperties(
- $properties,
- $result,
- $node
+ $this->plugin->handleUpdateProperties(
+ '/dummypath',
+ $propPatch
);
+ $propPatch->commit();
+
// all requested properties removed, as they were processed already
- $this->assertEmpty($properties);
+ $this->assertEmpty($propPatch->getRemainingMutations());
+
+ $result = $propPatch->getResult();
+ $this->assertEquals(200, $result[self::TAGS_PROPERTYNAME]);
+ $this->assertFalse(isset($result[self::FAVORITE_PROPERTYNAME]));
+ }
+
+ public function testUpdateTagsFromScratch() {
+ $node = $this->getMockBuilder('\OC\Connector\Sabre\Node')
+ ->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));
+
+ $this->tagger->expects($this->at(0))
+ ->method('getTagsForObjects')
+ ->with($this->equalTo(array(123)))
+ ->will($this->returnValue(array()));
+
+ // then tag as tag1 and tag2
+ $this->tagger->expects($this->at(1))
+ ->method('tagAs')
+ ->with(123, 'tag1');
+ $this->tagger->expects($this->at(2))
+ ->method('tagAs')
+ ->with(123, 'tag2');
- $this->assertEquals(
- new \OC\Connector\Sabre\TagList(array('tag1', 'tag2', 'tagkeep')),
- $result[200][self::TAGS_PROPERTYNAME]
+ // properties to set
+ $propPatch = new \Sabre\DAV\PropPatch(array(
+ self::TAGS_PROPERTYNAME => new \OC\Connector\Sabre\TagList(array('tag1', 'tag2', 'tagkeep'))
+ ));
+
+ $this->plugin->handleUpdateProperties(
+ '/dummypath',
+ $propPatch
);
- $this->assertFalse(isset($result[200][self::FAVORITE_PROPERTYNAME]));
+
+ $propPatch->commit();
+
+ // all requested properties removed, as they were processed already
+ $this->assertEmpty($propPatch->getRemainingMutations());
+
+ $result = $propPatch->getResult();
+ $this->assertEquals(200, $result[self::TAGS_PROPERTYNAME]);
+ $this->assertFalse(false, isset($result[self::FAVORITE_PROPERTYNAME]));
}
public function testUpdateFav() {
// this test will replace the existing tags "tagremove" with "tag1" and "tag2"
// and keep "tagkeep"
- $node = $this->getMockBuilder('\OC_Connector_Sabre_Node')
+ $node = $this->getMockBuilder('\OC\Connector\Sabre\Node')
->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));
+
// set favorite tag
$this->tagger->expects($this->once())
->method('tagAs')
->with(123, self::TAG_FAVORITE);
// properties to set
- $properties = array(
+ $propPatch = new \Sabre\DAV\PropPatch(array(
self::FAVORITE_PROPERTYNAME => true
- );
- $result = array();
- $this->plugin->updateProperties(
- $properties,
- $result,
- $node
+ ));
+
+ $this->plugin->handleUpdateProperties(
+ '/dummypath',
+ $propPatch
);
+ $propPatch->commit();
+
// all requested properties removed, as they were processed already
- $this->assertEmpty($properties);
+ $this->assertEmpty($propPatch->getRemainingMutations());
- $this->assertTrue($result[200][self::FAVORITE_PROPERTYNAME]);
- $this->assertFalse(isset($result[200][self::TAGS_PROPERTYNAME]));
+ $result = $propPatch->getResult();
+ $this->assertFalse(false, isset($result[self::TAGS_PROPERTYNAME]));
+ $this->assertEquals(200, isset($result[self::FAVORITE_PROPERTYNAME]));
// unfavorite now
// set favorite tag
@@ -297,18 +375,24 @@ class TagsPlugin extends \Test\TestCase {
->method('unTag')
->with(123, self::TAG_FAVORITE);
- $properties = array(
+ // properties to set
+ $propPatch = new \Sabre\DAV\PropPatch(array(
self::FAVORITE_PROPERTYNAME => false
+ ));
+
+ $this->plugin->handleUpdateProperties(
+ '/dummypath',
+ $propPatch
);
- $result = array();
- $this->plugin->updateProperties(
- $properties,
- $result,
- $node
- );
- $this->assertFalse($result[200][self::FAVORITE_PROPERTYNAME]);
- $this->assertFalse(isset($result[200][self::TAGS_PROPERTYNAME]));
+ $propPatch->commit();
+
+ // all requested properties removed, as they were processed already
+ $this->assertEmpty($propPatch->getRemainingMutations());
+
+ $result = $propPatch->getResult();
+ $this->assertFalse(false, isset($result[self::TAGS_PROPERTYNAME]));
+ $this->assertEquals(200, isset($result[self::FAVORITE_PROPERTYNAME]));
}
}
diff --git a/tests/lib/vobject.php b/tests/lib/vobject.php
deleted file mode 100644
index 6fabf30e48f..00000000000
--- a/tests/lib/vobject.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-/**
- * Copyright (c) 2013 Thomas Tanghus (thomas@tanghus.net)
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-class Test_VObject extends \Test\TestCase {
-
- protected function setUp() {
- parent::setUp();
-
- Sabre\VObject\Property::$classMap['SUMMARY'] = 'OC\VObject\StringProperty';
- Sabre\VObject\Property::$classMap['ORG'] = 'OC\VObject\CompoundProperty';
- }
-
- function testStringProperty() {
- $property = Sabre\VObject\Property::create('SUMMARY', 'Escape;this,please');
- $this->assertEquals("SUMMARY:Escape\;this\,please\r\n", $property->serialize());
- }
-
- function testCompoundProperty() {
-
- $arr = array(
- 'ABC, Inc.',
- 'North American Division',
- 'Marketing;Sales',
- );
-
- $property = Sabre\VObject\Property::create('ORG');
- $property->setParts($arr);
-
- $this->assertEquals('ABC\, Inc.;North American Division;Marketing\;Sales', $property->value);
- $this->assertEquals('ORG:ABC\, Inc.;North American Division;Marketing\;Sales' . "\r\n", $property->serialize());
- $this->assertEquals(3, count($property->getParts()));
- $parts = $property->getParts();
- $this->assertEquals('Marketing;Sales', $parts[2]);
- }
-}