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 testGetSharedWithGroupUserModified() { $qb = $this->dbConn->getQueryBuilder(); $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_GROUP), 'share_with' => $qb->expr()->literal('sharedWith'), 'uid_owner' => $qb->expr()->literal('shareOwner'), 'uid_initiator' => $qb->expr()->literal('sharedBy'), 'item_type' => $qb->expr()->literal('file'), 'file_source' => $qb->expr()->literal(42), 'file_target' => $qb->expr()->literal('myTarget'), 'permissions' => $qb->expr()->literal(13)]); $this->assertEquals(1, $qb->execute()); $id = $qb->getLastInsertId(); $qb = $this->dbConn->getQueryBuilder(); $qb->insert('share')->values(['share_type' => $qb->expr()->literal(2), 'share_with' => $qb->expr()->literal('user'), 'uid_owner' => $qb->expr()->literal('shareOwner'), 'uid_initiator' => $qb->expr()->literal('sharedBy'), 'item_type' => $qb->expr()->literal('file'), 'file_source' => $qb->expr()->literal(42), 'file_target' => $qb->expr()->literal('userTarget'), 'permissions' => $qb->expr()->literal(0), 'parent' => $qb->expr()->literal($id)]); $this->assertEquals(1, $qb->execute()); $group = $this->getMock('\\OCP\\IGroup'); $group->method('getGID')->willReturn('sharedWith'); $groups = [$group]; $user = $this->getMock('\\OCP\\IUser'); $user->method('getUID')->willReturn('user'); $owner = $this->getMock('\\OCP\\IUser'); $owner->method('getUID')->willReturn('shareOwner'); $initiator = $this->getMock('\\OCP\\IUser'); $initiator->method('getUID')->willReturn('sharedBy'); $this->userManager->method('get')->willReturnMap([['shareOwner', $owner], ['sharedBy', $initiator]]); $this->groupManager->method('getUserGroups')->with($user)->willReturn($groups); $this->groupManager->method('get')->with('sharedWith')->willReturn($group); $file = $this->getMock('\\OCP\\Files\\File'); $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); $this->assertCount(1, $share); $share = $share[0]; $this->assertEquals($id, $share->getId()); $this->assertEquals($group, $share->getSharedWith()); $this->assertEquals($owner, $share->getShareOwner()); $this->assertEquals($initiator, $share->getSharedBy()); $this->assertEquals(\OCP\Share::SHARE_TYPE_GROUP, $share->getShareType()); $this->assertEquals(0, $share->getPermissions()); $this->assertEquals('userTarget', $share->getTarget()); }