summaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2016-01-29 15:26:04 +0100
committerRoeland Jago Douma <rullzer@owncloud.com>2016-01-29 15:36:23 +0100
commita24e7f655885b5047e73036acb2f1706803a2b65 (patch)
tree368b0e20962529da9a1fe6d0a48c0842945ebde8 /tests/lib
parent8ad45dad38c2c502ac1fae48e4bc12ec3dcfd565 (diff)
downloadnextcloud-server-a24e7f655885b5047e73036acb2f1706803a2b65.tar.gz
nextcloud-server-a24e7f655885b5047e73036acb2f1706803a2b65.zip
Add path filter to OCS Share API ?shared_with_me=true
This allows all clients to quickly get the share info for a given path. Instead of returning everything and filtering it then manually on the client side.
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/share20/defaultshareprovidertest.php78
1 files changed, 75 insertions, 3 deletions
diff --git a/tests/lib/share20/defaultshareprovidertest.php b/tests/lib/share20/defaultshareprovidertest.php
index 45f2bedcb63..28b57435e1d 100644
--- a/tests/lib/share20/defaultshareprovidertest.php
+++ b/tests/lib/share20/defaultshareprovidertest.php
@@ -824,7 +824,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf());
$this->rootFolder->method('getById')->with(42)->willReturn([$file]);
- $share = $this->provider->getSharedWith($user, \OCP\Share::SHARE_TYPE_USER, 1 , 0);
+ $share = $this->provider->getSharedWith($user, \OCP\Share::SHARE_TYPE_USER, null, 1 , 0);
$this->assertCount(1, $share);
$share = $share[0];
@@ -894,7 +894,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf());
$this->rootFolder->method('getById')->with(42)->willReturn([$file]);
- $share = $this->provider->getSharedWith($user, \OCP\Share::SHARE_TYPE_GROUP, 20 , 1);
+ $share = $this->provider->getSharedWith($user, \OCP\Share::SHARE_TYPE_GROUP, null, 20 , 1);
$this->assertCount(1, $share);
$share = $share[0];
@@ -979,7 +979,7 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf());
$this->rootFolder->method('getById')->with(42)->willReturn([$file]);
- $share = $this->provider->getSharedWith($user, \OCP\Share::SHARE_TYPE_GROUP, -1, 0);
+ $share = $this->provider->getSharedWith($user, \OCP\Share::SHARE_TYPE_GROUP, null, -1, 0);
$this->assertCount(1, $share);
$share = $share[0];
@@ -992,6 +992,78 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->assertSame('userTarget', $share->getTarget());
}
+ public function testGetSharedWithUserWithNode() {
+ $this->addShareToDB(\OCP\Share::SHARE_TYPE_USER, 'user0', 'user1', 'user1',
+ 'file', 42, 'myTarget', 31, null, null, null);
+ $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_USER, 'user0', 'user1', 'user1',
+ 'file', 43, 'myTarget', 31, null, null, null);
+
+ $user0 = $this->getMock('\OCP\IUser');
+ $user0->method('getUID')->willReturn('user0');
+ $user1 = $this->getMock('\OCP\IUser');
+ $user1->method('getUID')->willReturn('user1');
+
+ $this->userManager->method('get')->willReturnMap([
+ ['user0', $user0],
+ ['user1', $user1],
+ ]);
+
+ $file = $this->getMock('\OCP\Files\File');
+ $file->method('getId')->willReturn(43);
+ $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf());
+ $this->rootFolder->method('getById')->with(43)->willReturn([$file]);
+
+ $share = $this->provider->getSharedWith($user0, \OCP\Share::SHARE_TYPE_USER, $file, -1, 0);
+ $this->assertCount(1, $share);
+
+ $share = $share[0];
+ $this->assertEquals($id, $share->getId());
+ $this->assertSame($user0, $share->getSharedWith());
+ $this->assertSame($user1, $share->getShareOwner());
+ $this->assertSame($user1, $share->getSharedBy());
+ $this->assertSame($file, $share->getNode());
+ $this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $share->getShareType());
+ }
+
+ public function testGetSharedWithGroupWithNode() {
+ $this->addShareToDB(\OCP\Share::SHARE_TYPE_GROUP, 'group0', 'user1', 'user1',
+ 'file', 42, 'myTarget', 31, null, null, null);
+ $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_GROUP, 'group0', 'user1', 'user1',
+ 'file', 43, 'myTarget', 31, null, null, null);
+
+ $user0 = $this->getMock('\OCP\IUser');
+ $user0->method('getUID')->willReturn('user0');
+ $user1 = $this->getMock('\OCP\IUser');
+ $user1->method('getUID')->willReturn('user1');
+
+ $this->userManager->method('get')->willReturnMap([
+ ['user0', $user0],
+ ['user1', $user1],
+ ]);
+
+ $group0 = $this->getMock('\OCP\IGroup');
+ $group0->method('getGID')->willReturn('group0');
+
+ $this->groupManager->method('get')->with('group0')->willReturn($group0);
+ $this->groupManager->method('getUserGroups')->with($user0)->willReturn([$group0]);
+
+ $node = $this->getMock('\OCP\Files\Folder');
+ $node->method('getId')->willReturn(43);
+ $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf());
+ $this->rootFolder->method('getById')->with(43)->willReturn([$node]);
+
+ $share = $this->provider->getSharedWith($user0, \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0);
+ $this->assertCount(1, $share);
+
+ $share = $share[0];
+ $this->assertEquals($id, $share->getId());
+ $this->assertSame($group0, $share->getSharedWith());
+ $this->assertSame($user1, $share->getShareOwner());
+ $this->assertSame($user1, $share->getSharedBy());
+ $this->assertSame($node, $share->getNode());
+ $this->assertEquals(\OCP\Share::SHARE_TYPE_GROUP, $share->getShareType());
+ }
+
public function testGetSharesBy() {
$qb = $this->dbConn->getQueryBuilder();
$qb->insert('share')