public function testGetChildren()
 {
     $qb = $this->dbConn->getQueryBuilder();
     $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), 'share_with' => $qb->expr()->literal('sharedWith'), 'uid_owner' => $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)]);
     $qb->execute();
     // Get the id
     $qb = $this->dbConn->getQueryBuilder();
     $cursor = $qb->select('id')->from('share')->setMaxResults(1)->orderBy('id', 'DESC')->execute();
     $id = $cursor->fetch();
     $id = $id['id'];
     $cursor->closeCursor();
     $qb = $this->dbConn->getQueryBuilder();
     $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), 'share_with' => $qb->expr()->literal('user1'), 'uid_owner' => $qb->expr()->literal('user2'), 'item_type' => $qb->expr()->literal('file'), 'file_source' => $qb->expr()->literal(1), 'file_target' => $qb->expr()->literal('myTarget1'), 'permissions' => $qb->expr()->literal(2), 'parent' => $qb->expr()->literal($id)]);
     $qb->execute();
     $qb = $this->dbConn->getQueryBuilder();
     $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_GROUP), 'share_with' => $qb->expr()->literal('group1'), 'uid_owner' => $qb->expr()->literal('user3'), 'item_type' => $qb->expr()->literal('folder'), 'file_source' => $qb->expr()->literal(3), 'file_target' => $qb->expr()->literal('myTarget2'), 'permissions' => $qb->expr()->literal(4), 'parent' => $qb->expr()->literal($id)]);
     $qb->execute();
     $storage = $this->getMock('OC\\Files\\Storage\\Storage');
     $storage->method('getOwner')->willReturn('shareOwner');
     $path1 = $this->getMock('OCP\\Files\\File');
     $path1->expects($this->once())->method('getStorage')->willReturn($storage);
     $path2 = $this->getMock('OCP\\Files\\Folder');
     $path2->expects($this->once())->method('getStorage')->willReturn($storage);
     $this->userFolder->method('getById')->will($this->returnValueMap([[1, [$path1]], [3, [$path2]]]));
     $shareOwner = $this->getMock('OCP\\IUser');
     $user1 = $this->getMock('OCP\\IUser');
     $user2 = $this->getMock('OCP\\IUser');
     $user3 = $this->getMock('OCP\\IUser');
     $this->userManager->method('get')->will($this->returnValueMap([['shareOwner', $shareOwner], ['user1', $user1], ['user2', $user2], ['user3', $user3]]));
     $group1 = $this->getMock('OCP\\IGroup');
     $this->groupManager->method('get')->will($this->returnValueMap([['group1', $group1]]));
     $share = $this->getMock('\\OC\\Share20\\IShare');
     $share->method('getId')->willReturn($id);
     $children = $this->provider->getChildren($share);
     $this->assertCount(2, $children);
     //Child1
     $this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $children[0]->getShareType());
     $this->assertEquals($user1, $children[0]->getSharedWith());
     $this->assertEquals($user2, $children[0]->getSharedBy());
     $this->assertEquals($shareOwner, $children[0]->getShareOwner());
     $this->assertEquals($path1, $children[0]->getPath());
     $this->assertEquals(2, $children[0]->getPermissions());
     $this->assertEquals(null, $children[0]->getToken());
     $this->assertEquals(null, $children[0]->getExpirationDate());
     $this->assertEquals('myTarget1', $children[0]->getTarget());
     //Child2
     $this->assertEquals(\OCP\Share::SHARE_TYPE_GROUP, $children[1]->getShareType());
     $this->assertEquals($group1, $children[1]->getSharedWith());
     $this->assertEquals($user3, $children[1]->getSharedBy());
     $this->assertEquals($shareOwner, $children[1]->getShareOwner());
     $this->assertEquals($path2, $children[1]->getPath());
     $this->assertEquals(4, $children[1]->getPermissions());
     $this->assertEquals(null, $children[1]->getToken());
     $this->assertEquals(null, $children[1]->getExpirationDate());
     $this->assertEquals('myTarget2', $children[1]->getTarget());
 }
 public function testGetChildren()
 {
     $qb = $this->dbConn->getQueryBuilder();
     $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), '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)]);
     $qb->execute();
     // Get the id
     $id = $qb->getLastInsertId();
     $qb = $this->dbConn->getQueryBuilder();
     $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER), 'share_with' => $qb->expr()->literal('user1'), 'uid_owner' => $qb->expr()->literal('shareOwner'), 'uid_initiator' => $qb->expr()->literal('user2'), 'item_type' => $qb->expr()->literal('file'), 'file_source' => $qb->expr()->literal(1), 'file_target' => $qb->expr()->literal('myTarget1'), 'permissions' => $qb->expr()->literal(2), 'parent' => $qb->expr()->literal($id)]);
     $qb->execute();
     $qb = $this->dbConn->getQueryBuilder();
     $qb->insert('share')->values(['share_type' => $qb->expr()->literal(\OCP\Share::SHARE_TYPE_GROUP), 'share_with' => $qb->expr()->literal('group1'), 'uid_owner' => $qb->expr()->literal('shareOwner'), 'uid_initiator' => $qb->expr()->literal('user3'), 'item_type' => $qb->expr()->literal('folder'), 'file_source' => $qb->expr()->literal(3), 'file_target' => $qb->expr()->literal('myTarget2'), 'permissions' => $qb->expr()->literal(4), 'parent' => $qb->expr()->literal($id)]);
     $qb->execute();
     $ownerPath = $this->getMock('\\OCP\\Files\\Folder');
     $ownerFolder = $this->getMock('\\OCP\\Files\\Folder');
     $ownerFolder->method('getById')->willReturn([$ownerPath]);
     $this->rootFolder->method('getUserFolder')->will($this->returnValueMap([['shareOwner', $ownerFolder]]));
     $share = $this->getMock('\\OCP\\Share\\IShare');
     $share->method('getId')->willReturn($id);
     $children = $this->provider->getChildren($share);
     $this->assertCount(2, $children);
     //Child1
     $this->assertEquals(\OCP\Share::SHARE_TYPE_USER, $children[0]->getShareType());
     $this->assertEquals('user1', $children[0]->getSharedWith());
     $this->assertEquals('user2', $children[0]->getSharedBy());
     $this->assertEquals('shareOwner', $children[0]->getShareOwner());
     $this->assertEquals($ownerPath, $children[0]->getNode());
     $this->assertEquals(2, $children[0]->getPermissions());
     $this->assertEquals(null, $children[0]->getToken());
     $this->assertEquals(null, $children[0]->getExpirationDate());
     $this->assertEquals('myTarget1', $children[0]->getTarget());
     //Child2
     $this->assertEquals(\OCP\Share::SHARE_TYPE_GROUP, $children[1]->getShareType());
     $this->assertEquals('group1', $children[1]->getSharedWith());
     $this->assertEquals('user3', $children[1]->getSharedBy());
     $this->assertEquals('shareOwner', $children[1]->getShareOwner());
     $this->assertEquals($ownerPath, $children[1]->getNode());
     $this->assertEquals(4, $children[1]->getPermissions());
     $this->assertEquals(null, $children[1]->getToken());
     $this->assertEquals(null, $children[1]->getExpirationDate());
     $this->assertEquals('myTarget2', $children[1]->getTarget());
 }