public function testGetShareByIdGroupShare() { $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('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()); // 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(); $storage = $this->getMock('OC\\Files\\Storage\\Storage'); $storage->expects($this->once())->method('getOwner')->willReturn('shareOwner'); $path = $this->getMock('OCP\\Files\\Folder'); $path->expects($this->once())->method('getStorage')->wilLReturn($storage); $this->userFolder->expects($this->once())->method('getById')->with(42)->willReturn([$path]); $sharedWith = $this->getMock('OCP\\IGroup'); $sharedBy = $this->getMock('OCP\\IUser'); $shareOwner = $this->getMock('OCP\\IUser'); $this->userManager->method('get')->will($this->returnValueMap([['sharedBy', $sharedBy], ['shareOwner', $shareOwner]])); $this->groupManager->expects($this->once())->method('get')->with('sharedWith')->willReturn($sharedWith); $share = $this->provider->getShareById($id); $this->assertEquals($id, $share->getId()); $this->assertEquals(\OCP\Share::SHARE_TYPE_GROUP, $share->getShareType()); $this->assertEquals($sharedWith, $share->getSharedWith()); $this->assertEquals($sharedBy, $share->getSharedBy()); $this->assertEquals($shareOwner, $share->getShareOwner()); $this->assertEquals($path, $share->getPath()); $this->assertEquals(13, $share->getPermissions()); $this->assertEquals(null, $share->getToken()); $this->assertEquals(null, $share->getExpirationDate()); $this->assertEquals('myTarget', $share->getTarget()); }
/** * @dataProvider dataIndex * @param bool $isAdmin */ public function testIndex($isAdmin) { $this->groupManager->expects($this->once())->method('isAdmin')->with('author')->willReturn($isAdmin); $controller = $this->getController(); $response = $controller->index(); $this->assertInstanceOf('OCP\\AppFramework\\Http\\TemplateResponse', $response); $this->assertSame(['is_admin' => $isAdmin], $response->getParams()); }
public function testAddGroupWithSpecialChar() { $this->request->method('getParam')->with('groupid')->willReturn('Iñtërnâtiônàlizætiøn'); $this->groupManager->method('groupExists')->with('Iñtërnâtiônàlizætiøn')->willReturn(false); $this->groupManager->expects($this->once())->method('createGroup')->with('Iñtërnâtiônàlizætiøn'); $result = $this->api->addGroup([]); $this->assertInstanceOf('OC_OCS_Result', $result); $this->assertTrue($result->succeeded()); }
public function testGetAppsForUser() { $user = new User('user1', null); $this->groupManager->expects($this->any())->method('getUserGroupIds')->with($user)->will($this->returnValue(array('foo', 'bar'))); $this->appConfig->setValue('test1', 'enabled', 'yes'); $this->appConfig->setValue('test2', 'enabled', 'no'); $this->appConfig->setValue('test3', 'enabled', '["foo"]'); $this->appConfig->setValue('test4', 'enabled', '["asd"]'); $this->assertEquals(['dav', 'federatedfilesharing', 'files', 'test1', 'test3'], $this->manager->getEnabledAppsForUser($user)); }
/** * @dataProvider assignabilityCheckProvider */ public function testAssignabilityCheck($userVisible, $userAssignable, $isAdmin, $expectedResult, $userGroupIds = [], $tagGroupIds = []) { $user = $this->getMockBuilder('\\OCP\\IUser')->getMock(); $user->expects($this->any())->method('getUID')->will($this->returnValue('test')); $tag1 = $this->tagManager->createTag('one', $userVisible, $userAssignable); $this->tagManager->setTagGroups($tag1, $tagGroupIds); $this->groupManager->expects($this->any())->method('isAdmin')->with('test')->will($this->returnValue($isAdmin)); $this->groupManager->expects($this->any())->method('getUserGroupIds')->with($user)->will($this->returnValue($userGroupIds)); $this->assertEquals($expectedResult, $this->tagManager->canUserAssignTag($tag1, $user)); }
public function testRun() { $repair = new OldGroupMembershipShares($this->connection, $this->groupManager); $this->groupManager->expects($this->exactly(2))->method('isInGroup')->willReturnMap([['member', 'group', true], ['not-a-member', 'group', false]]); $parent = $this->createShare(Constants::SHARE_TYPE_GROUP, 'group', null); $group2 = $this->createShare(Constants::SHARE_TYPE_GROUP, 'group2', $parent); $user1 = $this->createShare(Constants::SHARE_TYPE_USER, 'user1', $parent); // \OC\Share\Constant::$shareTypeGroupUserUnique === 2 $member = $this->createShare(2, 'member', $parent); $notAMember = $this->createShare(2, 'not-a-member', $parent); $query = $this->connection->getQueryBuilder(); $result = $query->select('id')->from('share')->orderBy('id', 'ASC')->execute(); $rows = $result->fetchAll(); $this->assertSame([['id' => $parent], ['id' => $group2], ['id' => $user1], ['id' => $member], ['id' => $notAMember]], $rows); $result->closeCursor(); $repair->run(); $query = $this->connection->getQueryBuilder(); $result = $query->select('id')->from('share')->orderBy('id', 'ASC')->execute(); $rows = $result->fetchAll(); $this->assertSame([['id' => $parent], ['id' => $group2], ['id' => $user1], ['id' => $member]], $rows); $result->closeCursor(); }
public function testProcessFilterRulesVisibleTagAsUser() { $this->groupManager->expects($this->any())->method('isAdmin')->will($this->returnValue(false)); $tag1 = $this->getMock('\\OCP\\SystemTag\\ISystemTag'); $tag1->expects($this->any())->method('getId')->will($this->returnValue('123')); $tag1->expects($this->any())->method('isUserVisible')->will($this->returnValue(true)); $tag2 = $this->getMock('\\OCP\\SystemTag\\ISystemTag'); $tag2->expects($this->any())->method('getId')->will($this->returnValue('123')); $tag2->expects($this->any())->method('isUserVisible')->will($this->returnValue(true)); $this->tagManager->expects($this->once())->method('getTagsByIds')->with(['123', '456'])->will($this->returnValue([$tag1, $tag2])); $this->tagMapper->expects($this->at(0))->method('getObjectIdsForTags')->with('123')->will($this->returnValue(['111', '222'])); $this->tagMapper->expects($this->at(1))->method('getObjectIdsForTags')->with('456')->will($this->returnValue(['222', '333'])); $rules = [['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'], ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456']]; $this->assertEquals(['222'], array_values($this->invokePrivate($this->plugin, 'processFilterRules', [$rules]))); }
public function testRun() { $repair = new OldGroupMembershipShares($this->connection, $this->groupManager); $this->groupManager->expects($this->exactly(2))->method('isInGroup')->willReturnMap([['member', 'group', true], ['not-a-member', 'group', false]]); $parent = $this->createShare(Constants::SHARE_TYPE_GROUP, 'group', null); $group2 = $this->createShare(Constants::SHARE_TYPE_GROUP, 'group2', $parent); $user1 = $this->createShare(Constants::SHARE_TYPE_USER, 'user1', $parent); // \OC\Share\Constant::$shareTypeGroupUserUnique === 2 $member = $this->createShare(2, 'member', $parent); $notAMember = $this->createShare(2, 'not-a-member', $parent); $query = $this->connection->getQueryBuilder(); $result = $query->select('id')->from('share')->orderBy('id', 'ASC')->execute(); $rows = $result->fetchAll(); $this->assertEquals([['id' => $parent], ['id' => $group2], ['id' => $user1], ['id' => $member], ['id' => $notAMember]], $rows); $result->closeCursor(); /** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */ $outputMock = $this->getMockBuilder('\\OCP\\Migration\\IOutput')->disableOriginalConstructor()->getMock(); $repair->run($outputMock); $query = $this->connection->getQueryBuilder(); $result = $query->select('id')->from('share')->orderBy('id', 'ASC')->execute(); $rows = $result->fetchAll(); $this->assertEquals([['id' => $parent], ['id' => $group2], ['id' => $user1], ['id' => $member]], $rows); $result->closeCursor(); }
/** * @dataProvider nodeClassProvider * @expectedException \Sabre\DAV\Exception\Conflict */ public function testCreateTagConflict($nodeClass) { $this->user->expects($this->once())->method('getUID')->willReturn('admin'); $this->groupManager->expects($this->once())->method('isAdmin')->with('admin')->willReturn(true); $requestData = json_encode(['name' => 'Test', 'userVisible' => true, 'userAssignable' => false]); $node = $this->getMockBuilder($nodeClass)->disableOriginalConstructor()->getMock(); $this->tagManager->expects($this->once())->method('createTag')->with('Test', true, false)->will($this->throwException(new TagAlreadyExistsException('Tag already exists'))); $this->tree->expects($this->any())->method('getNodeForPath')->with('/systemtags')->will($this->returnValue($node)); $request = $this->getMockBuilder('Sabre\\HTTP\\RequestInterface')->disableOriginalConstructor()->getMock(); $response = $this->getMockBuilder('Sabre\\HTTP\\ResponseInterface')->disableOriginalConstructor()->getMock(); $request->expects($this->once())->method('getPath')->will($this->returnValue('/systemtags')); $request->expects($this->once())->method('getBodyAsString')->will($this->returnValue($requestData)); $request->expects($this->once())->method('getHeader')->with('Content-Type')->will($this->returnValue('application/json')); $this->plugin->httpPost($request, $response); }
/** * @dataProvider dataShareFileOrFolderWithGroup * @param array $usersInGroup * @param array $settingUsers * @param array $settingsReturn * @param array $addNotifications */ public function testShareFileOrFolderWithGroup($usersInGroup, $settingUsers, $settingsReturn, $addNotifications) { $filesHooks = $this->getFilesHooks(['shareNotificationForSharer', 'addNotificationsForUser', 'fixPathsForShareExceptions', 'shareNotificationForOriginalOwners']); $group = $this->getMockBuilder('OCP\\IGroup')->disableOriginalConstructor()->getMock(); $group->expects($this->once())->method('searchUsers')->with('')->willReturn($usersInGroup); $this->groupManager->expects($this->once())->method('get')->with('group1')->willReturn($group); $this->settings->expects(empty($settingUsers) ? $this->never() : $this->exactly(2))->method('filterUsersBySetting')->willReturnMap($settingsReturn); $filesHooks->expects($this->once())->method('shareNotificationForSharer')->with('shared_group_self', 'group1', 42, 'file'); $filesHooks->expects(empty($settingUsers) ? $this->never() : $this->once())->method('fixPathsForShareExceptions')->with($this->anything(), 1337)->willReturnArgument(0); $filesHooks->expects($this->once())->method('shareNotificationForOriginalOwners')->with('user', 'reshared_group_by', 'group1', 42, 'file')->willReturnArgument(0); $i = 3; foreach ($addNotifications as $user => $arguments) { $filesHooks->expects($this->at($i))->method('addNotificationsForUser')->with($user, $arguments['subject'], $arguments['subject_params'], 42, $arguments['path'], true, $arguments['stream'], $arguments['email'], Files_Sharing::TYPE_SHARED); $i++; } $this->invokePrivate($filesHooks, 'shareFileOrFolderWithGroup', ['group1', 42, 'file', '/file', 1337]); }
/** * @dataProvider dataGetUsersToNotify * @param string[] $groups * @param array $groupUsers * @param string[] $expected */ public function testGetUsersToNotify($groups, array $groupUsers, array $expected) { $job = $this->getJob(); $this->config->expects($this->once())->method('getAppValue')->with('updatenotification', 'notify_groups', '["admin"]')->willReturn(json_encode($groups)); $groupMap = []; foreach ($groupUsers as $gid => $uids) { if ($uids === null) { $group = null; } else { $group = $this->getGroup($gid); $group->expects($this->any())->method('getUsers')->willReturn($this->getUsers($uids)); } $groupMap[] = [$gid, $group]; } $this->groupManager->expects($this->exactly(sizeof($groups)))->method('get')->willReturnMap($groupMap); $result = $this->invokePrivate($job, 'getUsersToNotify'); $this->assertEquals($expected, $result); // Test caching $result = $this->invokePrivate($job, 'getUsersToNotify'); $this->assertEquals($expected, $result); }
/** * @dataProvider dataGetGroups * * @param string $searchTerm * @param bool $shareWithGroupOnly * @param array $groupResponse * @param array $userGroupsResponse * @param array $exactExpected * @param array $expected * @param bool $reachedEnd * @param mixed $singleGroup */ public function testGetGroups($searchTerm, $shareWithGroupOnly, $groupResponse, $userGroupsResponse, $exactExpected, $expected, $reachedEnd, $singleGroup) { $this->invokePrivate($this->sharees, 'limit', [2]); $this->invokePrivate($this->sharees, 'offset', [0]); $this->invokePrivate($this->sharees, 'shareWithGroupOnly', [$shareWithGroupOnly]); $this->groupManager->expects($this->once())->method('search')->with($searchTerm, $this->invokePrivate($this->sharees, 'limit'), $this->invokePrivate($this->sharees, 'offset'))->willReturn($groupResponse); if ($singleGroup !== false) { $this->groupManager->expects($this->once())->method('get')->with($searchTerm)->willReturn($singleGroup); } if ($shareWithGroupOnly) { $user = $this->getUserMock('admin', 'Administrator'); $this->session->expects($this->any())->method('getUser')->willReturn($user); $numGetUserGroupsCalls = empty($groupResponse) ? 0 : 1; $this->groupManager->expects($this->exactly($numGetUserGroupsCalls))->method('getUserGroups')->with($user)->willReturn($userGroupsResponse); } $this->invokePrivate($this->sharees, 'getGroups', [$searchTerm]); $result = $this->invokePrivate($this->sharees, 'result'); $this->assertEquals($exactExpected, $result['exact']['groups']); $this->assertEquals($expected, $result['groups']); $this->assertCount((int) $reachedEnd, $this->invokePrivate($this->sharees, 'reachedEndFor')); }