diff options
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/connector/sabre/directory.php | 54 | ||||
-rw-r--r-- | tests/lib/connector/sabre/file.php | 16 | ||||
-rw-r--r-- | tests/lib/connector/sabre/objecttree.php | 2 | ||||
-rw-r--r-- | tests/lib/connector/sabre/tagsplugin.php | 314 | ||||
-rw-r--r-- | tests/lib/files/node/file.php | 2 | ||||
-rw-r--r-- | tests/lib/files/node/folder.php | 2 | ||||
-rw-r--r-- | tests/lib/files/node/node.php | 2 | ||||
-rw-r--r-- | tests/lib/files/node/root.php | 2 | ||||
-rw-r--r-- | tests/lib/memcache/redis.php | 29 |
9 files changed, 410 insertions, 13 deletions
diff --git a/tests/lib/connector/sabre/directory.php b/tests/lib/connector/sabre/directory.php index d8dca35cd71..e9bfea81b77 100644 --- a/tests/lib/connector/sabre/directory.php +++ b/tests/lib/connector/sabre/directory.php @@ -101,4 +101,58 @@ class Test_OC_Connector_Sabre_Directory extends \Test\TestCase { $dir = $this->getRootDir(); $dir->delete(); } + + public function testGetChildren() { + $info1 = $this->getMockBuilder('OC\Files\FileInfo') + ->disableOriginalConstructor() + ->getMock(); + $info2 = $this->getMockBuilder('OC\Files\FileInfo') + ->disableOriginalConstructor() + ->getMock(); + $info1->expects($this->any()) + ->method('getName') + ->will($this->returnValue('first')); + $info1->expects($this->any()) + ->method('getEtag') + ->will($this->returnValue('abc')); + $info2->expects($this->any()) + ->method('getName') + ->will($this->returnValue('second')); + $info2->expects($this->any()) + ->method('getEtag') + ->will($this->returnValue('def')); + + $this->view->expects($this->once()) + ->method('getDirectoryContent') + ->with('') + ->will($this->returnValue(array($info1, $info2))); + + $this->view->expects($this->any()) + ->method('getRelativePath') + ->will($this->returnValue('')); + + $dir = new OC_Connector_Sabre_Directory($this->view, $this->info); + $nodes = $dir->getChildren(); + + $this->assertEquals(2, count($nodes)); + + // 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) + ); + } } diff --git a/tests/lib/connector/sabre/file.php b/tests/lib/connector/sabre/file.php index b4fdd91f512..6bb1b4e75d1 100644 --- a/tests/lib/connector/sabre/file.php +++ b/tests/lib/connector/sabre/file.php @@ -24,7 +24,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase { $info = new \OC\Files\FileInfo('/test.txt', null, null, array( 'permissions'=>\OCP\Constants::PERMISSION_ALL - )); + ), null); $file = new OC_Connector_Sabre_File($view, $info); @@ -59,7 +59,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase { $info = new \OC\Files\FileInfo('/test.txt', null, null, array( 'permissions' => \OCP\Constants::PERMISSION_ALL - )); + ), null); $file = new OC_Connector_Sabre_File($view, $info); @@ -83,7 +83,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); // action @@ -104,7 +104,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->setName('/super*star.txt'); } @@ -136,7 +136,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase { $info = new \OC\Files\FileInfo('/test.txt', null, null, array( 'permissions' => \OCP\Constants::PERMISSION_ALL - )); + ), null); $file = new OC_Connector_Sabre_File($view, $info); @@ -158,7 +158,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase { $info = new \OC\Files\FileInfo('/test.txt', null, null, array( 'permissions' => \OCP\Constants::PERMISSION_ALL - )); + ), null); $file = new OC_Connector_Sabre_File($view, $info); @@ -176,7 +176,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase { $info = new \OC\Files\FileInfo('/test.txt', null, null, array( 'permissions' => 0 - )); + ), null); $file = new OC_Connector_Sabre_File($view, $info); @@ -199,7 +199,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase { $info = new \OC\Files\FileInfo('/test.txt', null, null, array( 'permissions' => \OCP\Constants::PERMISSION_ALL - )); + ), null); $file = new OC_Connector_Sabre_File($view, $info); diff --git a/tests/lib/connector/sabre/objecttree.php b/tests/lib/connector/sabre/objecttree.php index d1de46d2ee7..2548066214b 100644 --- a/tests/lib/connector/sabre/objecttree.php +++ b/tests/lib/connector/sabre/objecttree.php @@ -101,7 +101,7 @@ class ObjectTree extends \Test\TestCase { private function moveTest($source, $dest, $updatables, $deletables) { $view = new TestDoubleFileView($updatables, $deletables); - $info = new FileInfo('', null, null, array()); + $info = new FileInfo('', null, null, array(), null); $rootDir = new OC_Connector_Sabre_Directory($view, $info); $objectTree = $this->getMock('\OC\Connector\Sabre\ObjectTree', diff --git a/tests/lib/connector/sabre/tagsplugin.php b/tests/lib/connector/sabre/tagsplugin.php new file mode 100644 index 00000000000..2afea061ec3 --- /dev/null +++ b/tests/lib/connector/sabre/tagsplugin.php @@ -0,0 +1,314 @@ +<?php + +namespace Tests\Connector\Sabre; + +/** + * Copyright (c) 2014 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 TagsPlugin extends \Test\TestCase { + + const TAGS_PROPERTYNAME = \OC\Connector\Sabre\TagsPlugin::TAGS_PROPERTYNAME; + const FAVORITE_PROPERTYNAME = \OC\Connector\Sabre\TagsPlugin::FAVORITE_PROPERTYNAME; + const TAG_FAVORITE = \OC\Connector\Sabre\TagsPlugin::TAG_FAVORITE; + + /** + * @var \Sabre\DAV\Server + */ + private $server; + + /** + * @var \Sabre\DAV\ObjectTree + */ + private $tree; + + /** + * @var \OCP\ITagManager + */ + private $tagManager; + + /** + * @var \OCP\ITags + */ + private $tagger; + + /** + * @var \OC\Connector\Sabre\TagsPlugin + */ + private $plugin; + + public function setUp() { + parent::setUp(); + $this->server = new \Sabre\DAV\Server(); + $this->tree = $this->getMockBuilder('\Sabre\DAV\ObjectTree') + ->disableOriginalConstructor() + ->getMock(); + $this->tagger = $this->getMock('\OCP\ITags'); + $this->tagManager = $this->getMock('\OCP\ITagManager'); + $this->tagManager->expects($this->any()) + ->method('load') + ->with('files') + ->will($this->returnValue($this->tagger)); + $this->plugin = new \OC\Connector\Sabre\TagsPlugin($this->tree, $this->tagManager); + $this->plugin->initialize($this->server); + } + + /** + * @dataProvider tagsGetPropertiesDataProvider + */ + public function testGetProperties($tags, $requestedProperties, $expectedProperties) { + $node = $this->getMockBuilder('\OC_Connector_Sabre_Node') + ->disableOriginalConstructor() + ->getMock(); + $node->expects($this->any()) + ->method('getId') + ->will($this->returnValue(123)); + + $expectedCallCount = 0; + if (count($requestedProperties) > 0) { + $expectedCallCount = 1; + } + + $this->tagger->expects($this->exactly($expectedCallCount)) + ->method('getTagsForObjects') + ->with($this->equalTo(array(123))) + ->will($this->returnValue(array(123 => $tags))); + + $returnedProperties = array(); + + $this->plugin->beforeGetProperties( + '', + $node, + $requestedProperties, + $returnedProperties + ); + + $this->assertEquals($expectedProperties, $returnedProperties); + } + + /** + * @dataProvider tagsGetPropertiesDataProvider + */ + public function testPreloadThenGetProperties($tags, $requestedProperties, $expectedProperties) { + $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') + ->disableOriginalConstructor() + ->getMock(); + $node2->expects($this->any()) + ->method('getId') + ->will($this->returnValue(222)); + + $expectedCallCount = 0; + if (count($requestedProperties) > 0) { + // this guarantees that getTagsForObjects + // is only called once and then the tags + // are cached + $expectedCallCount = 1; + } + + $node = $this->getMockBuilder('\OC_Connector_Sabre_Directory') + ->disableOriginalConstructor() + ->getMock(); + $node->expects($this->any()) + ->method('getId') + ->will($this->returnValue(123)); + $node->expects($this->exactly($expectedCallCount)) + ->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))) + ->will($this->returnValue( + array( + 111 => $tags, + 123 => $tags + ) + )); + + $returnedProperties = array(); + + $this->plugin->beforeGetPropertiesForPath( + '/subdir', + $requestedProperties, + 1 + ); + + $this->plugin->beforeGetProperties( + '/subdir/test.txt', + $node1, + $requestedProperties, + $returnedProperties + ); + + $this->assertEquals($expectedProperties, $returnedProperties); + } + + function tagsGetPropertiesDataProvider() { + return array( + // request both, receive both + array( + array('tag1', 'tag2', self::TAG_FAVORITE), + array(self::TAGS_PROPERTYNAME, self::FAVORITE_PROPERTYNAME), + array( + 200 => array( + self::TAGS_PROPERTYNAME => new \OC\Connector\Sabre\TagList(array('tag1', 'tag2')), + self::FAVORITE_PROPERTYNAME => true, + ) + ) + ), + // request tags alone + array( + array('tag1', 'tag2', self::TAG_FAVORITE), + array(self::TAGS_PROPERTYNAME), + array( + 200 => array( + self::TAGS_PROPERTYNAME => new \OC\Connector\Sabre\TagList(array('tag1', 'tag2')), + ) + ) + ), + // request fav alone + array( + array('tag1', 'tag2', self::TAG_FAVORITE), + array(self::FAVORITE_PROPERTYNAME), + array( + 200 => array( + self::FAVORITE_PROPERTYNAME => true, + ) + ) + ), + // request none + array( + array('tag1', 'tag2', self::TAG_FAVORITE), + array(), + array(), + ), + // request both with none set, receive both + array( + array(), + array(self::TAGS_PROPERTYNAME, self::FAVORITE_PROPERTYNAME), + array( + 200 => array( + self::TAGS_PROPERTYNAME => new \OC\Connector\Sabre\TagList(array()), + self::FAVORITE_PROPERTYNAME => false, + ) + ) + ), + ); + } + + 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') + ->disableOriginalConstructor() + ->getMock(); + $node->expects($this->any()) + ->method('getId') + ->will($this->returnValue(123)); + + $this->tagger->expects($this->at(0)) + ->method('getTagsForObjects') + ->with($this->equalTo(array(123))) + ->will($this->returnValue(array(123 => array('tagkeep', 'tagremove', self::TAG_FAVORITE)))); + + // 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'); + + // it will untag tag3 + $this->tagger->expects($this->at(3)) + ->method('unTag') + ->with(123, 'tagremove'); + + // properties to set + $properties = array( + self::TAGS_PROPERTYNAME => new \OC\Connector\Sabre\TagList(array('tag1', 'tag2', 'tagkeep')) + ); + $result = array(); + + $this->plugin->updateProperties( + $properties, + $result, + $node + ); + + // all requested properties removed, as they were processed already + $this->assertEmpty($properties); + + $this->assertEquals( + new \OC\Connector\Sabre\TagList(array('tag1', 'tag2', 'tagkeep')), + $result[200][self::TAGS_PROPERTYNAME] + ); + $this->assertFalse(isset($result[200][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') + ->disableOriginalConstructor() + ->getMock(); + $node->expects($this->any()) + ->method('getId') + ->will($this->returnValue(123)); + + // set favorite tag + $this->tagger->expects($this->once()) + ->method('tagAs') + ->with(123, self::TAG_FAVORITE); + + // properties to set + $properties = array( + self::FAVORITE_PROPERTYNAME => true + ); + $result = array(); + $this->plugin->updateProperties( + $properties, + $result, + $node + ); + + // all requested properties removed, as they were processed already + $this->assertEmpty($properties); + + $this->assertTrue($result[200][self::FAVORITE_PROPERTYNAME]); + $this->assertFalse(isset($result[200][self::TAGS_PROPERTYNAME])); + + // unfavorite now + // set favorite tag + $this->tagger->expects($this->once()) + ->method('unTag') + ->with(123, self::TAG_FAVORITE); + + $properties = array( + self::FAVORITE_PROPERTYNAME => false + ); + $result = array(); + $this->plugin->updateProperties( + $properties, + $result, + $node + ); + + $this->assertFalse($result[200][self::FAVORITE_PROPERTYNAME]); + $this->assertFalse(isset($result[200][self::TAGS_PROPERTYNAME])); + } + +} diff --git a/tests/lib/files/node/file.php b/tests/lib/files/node/file.php index a1d2266edf7..e3b8019b4ca 100644 --- a/tests/lib/files/node/file.php +++ b/tests/lib/files/node/file.php @@ -22,7 +22,7 @@ class File extends \Test\TestCase { } protected function getFileInfo($data) { - return new FileInfo('', null, '', $data); + return new FileInfo('', null, '', $data, null); } public function testDelete() { diff --git a/tests/lib/files/node/folder.php b/tests/lib/files/node/folder.php index e69a2776979..bcd9cc93b5e 100644 --- a/tests/lib/files/node/folder.php +++ b/tests/lib/files/node/folder.php @@ -25,7 +25,7 @@ class Folder extends \Test\TestCase { } protected function getFileInfo($data) { - return new FileInfo('', null, '', $data); + return new FileInfo('', null, '', $data, null); } public function testDelete() { diff --git a/tests/lib/files/node/node.php b/tests/lib/files/node/node.php index 4697479ba95..49a2006c767 100644 --- a/tests/lib/files/node/node.php +++ b/tests/lib/files/node/node.php @@ -19,7 +19,7 @@ class Node extends \Test\TestCase { } protected function getFileInfo($data) { - return new FileInfo('', null, '', $data); + return new FileInfo('', null, '', $data, null); } public function testStat() { diff --git a/tests/lib/files/node/root.php b/tests/lib/files/node/root.php index 35bd462157e..a763428209c 100644 --- a/tests/lib/files/node/root.php +++ b/tests/lib/files/node/root.php @@ -21,7 +21,7 @@ class Root extends \Test\TestCase { } protected function getFileInfo($data) { - return new FileInfo('', null, '', $data); + return new FileInfo('', null, '', $data, null); } public function testGet() { diff --git a/tests/lib/memcache/redis.php b/tests/lib/memcache/redis.php new file mode 100644 index 00000000000..c0bd18b46f9 --- /dev/null +++ b/tests/lib/memcache/redis.php @@ -0,0 +1,29 @@ +<?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\Memcache; + +class Redis extends Cache { + static public function setUpBeforeClass() { + parent::setUpBeforeClass(); + + if (!\OC\Memcache\Redis::isAvailable()) { + self::markTestSkipped('The redis extension is not available.'); + } + $instance = new \OC\Memcache\Redis(self::getUniqueID()); + if ($instance->set(self::getUniqueID(), self::getUniqueID()) === false) { + self::markTestSkipped('redis server seems to be down.'); + } + } + + protected function setUp() { + parent::setUp(); + $this->instance = new \OC\Memcache\Redis($this->getUniqueID()); + } +} |