diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-09-12 21:58:09 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-09-26 23:10:24 +0200 |
commit | b35760de2718cbf8c9361d2192051e50ff447d43 (patch) | |
tree | 33f7a48367e881626d89a1789baae7d49d6b2ed2 /apps/files_sharing | |
parent | dd9e191d373217b2a07e4ac5b2cc294c0a6227a1 (diff) | |
download | nextcloud-server-b35760de2718cbf8c9361d2192051e50ff447d43.tar.gz nextcloud-server-b35760de2718cbf8c9361d2192051e50ff447d43.zip |
split off getGroups unit tests
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/files_sharing')
-rw-r--r-- | apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php | 392 |
1 files changed, 0 insertions, 392 deletions
diff --git a/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php b/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php index aa5ad4eec65..f9d762d65aa 100644 --- a/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php +++ b/apps/files_sharing/tests/Controller/ShareesAPIControllerTest.php @@ -117,398 +117,6 @@ class ShareesAPIControllerTest extends TestCase { } /** - * @param string $uid - * @param string $displayName - * @return \OCP\IUser|\PHPUnit_Framework_MockObject_MockObject - */ - protected function getUserMock($uid, $displayName) { - $user = $this->getMockBuilder('OCP\IUser') - ->disableOriginalConstructor() - ->getMock(); - - $user->expects($this->any()) - ->method('getUID') - ->willReturn($uid); - - $user->expects($this->any()) - ->method('getDisplayName') - ->willReturn($displayName); - - return $user; - } - - /** - * @param string $gid - * @return \OCP\IGroup|\PHPUnit_Framework_MockObject_MockObject - */ - protected function getGroupMock($gid, $displayName = null) { - $group = $this->getMockBuilder('OCP\IGroup') - ->disableOriginalConstructor() - ->getMock(); - - $group->expects($this->any()) - ->method('getGID') - ->willReturn($gid); - - if (is_null($displayName)) { - // note: this is how the Group class behaves - $displayName = $gid; - } - - $group->expects($this->any()) - ->method('getDisplayName') - ->willReturn($displayName); - - return $group; - } - - public function dataGetGroups() { - return [ - ['test', false, true, [], [], [], [], true, false], - ['test', false, false, [], [], [], [], true, false], - // group without display name - [ - 'test', false, true, - [$this->getGroupMock('test1')], - [], - [], - [['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']]], - true, - false, - ], - // group with display name, search by id - [ - 'test', false, true, - [$this->getGroupMock('test1', 'Test One')], - [], - [], - [['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']]], - true, - false, - ], - // group with display name, search by display name - [ - 'one', false, true, - [$this->getGroupMock('test1', 'Test One')], - [], - [], - [['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']]], - true, - false, - ], - // group with display name, search by display name, exact expected - [ - 'Test One', false, true, - [$this->getGroupMock('test1', 'Test One')], - [], - [['label' => 'Test One', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']]], - [], - true, - false, - ], - [ - 'test', false, false, - [$this->getGroupMock('test1')], - [], - [], - [], - true, - false, - ], - [ - 'test', false, true, - [ - $this->getGroupMock('test'), - $this->getGroupMock('test1'), - ], - [], - [['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']]], - [['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']]], - false, - false, - ], - [ - 'test', false, false, - [ - $this->getGroupMock('test'), - $this->getGroupMock('test1'), - ], - [], - [['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']]], - [], - true, - false, - ], - [ - 'test', false, true, - [ - $this->getGroupMock('test0'), - $this->getGroupMock('test1'), - ], - [], - [], - [ - ['label' => 'test0', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test0']], - ['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']], - ], - false, - null, - ], - [ - 'test', false, false, - [ - $this->getGroupMock('test0'), - $this->getGroupMock('test1'), - ], - [], - [], - [], - true, - null, - ], - [ - 'test', false, true, - [ - $this->getGroupMock('test0'), - $this->getGroupMock('test1'), - ], - [], - [ - ['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']], - ], - [ - ['label' => 'test0', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test0']], - ['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']], - ], - false, - $this->getGroupMock('test'), - ], - [ - 'test', false, false, - [ - $this->getGroupMock('test0'), - $this->getGroupMock('test1'), - ], - [], - [ - ['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']], - ], - [], - true, - $this->getGroupMock('test'), - ], - ['test', true, true, [], [], [], [], true, false], - ['test', true, false, [], [], [], [], true, false], - [ - 'test', true, true, - [ - $this->getGroupMock('test1'), - $this->getGroupMock('test2'), - ], - [$this->getGroupMock('test1')], - [], - [['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']]], - false, - false, - ], - [ - 'test', true, false, - [ - $this->getGroupMock('test1'), - $this->getGroupMock('test2'), - ], - [$this->getGroupMock('test1')], - [], - [], - true, - false, - ], - [ - 'test', true, true, - [ - $this->getGroupMock('test'), - $this->getGroupMock('test1'), - ], - [$this->getGroupMock('test')], - [['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']]], - [], - false, - false, - ], - [ - 'test', true, false, - [ - $this->getGroupMock('test'), - $this->getGroupMock('test1'), - ], - [$this->getGroupMock('test')], - [['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']]], - [], - true, - false, - ], - [ - 'test', true, true, - [ - $this->getGroupMock('test'), - $this->getGroupMock('test1'), - ], - [$this->getGroupMock('test1')], - [], - [['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']]], - false, - false, - ], - [ - 'test', true, false, - [ - $this->getGroupMock('test'), - $this->getGroupMock('test1'), - ], - [$this->getGroupMock('test1')], - [], - [], - true, - false, - ], - [ - 'test', true, true, - [ - $this->getGroupMock('test'), - $this->getGroupMock('test1'), - ], - [$this->getGroupMock('test'), $this->getGroupMock('test0'), $this->getGroupMock('test1')], - [['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']]], - [['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']]], - false, - false, - ], - [ - 'test', true, false, - [ - $this->getGroupMock('test'), - $this->getGroupMock('test1'), - ], - [$this->getGroupMock('test'), $this->getGroupMock('test0'), $this->getGroupMock('test1')], - [['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']]], - [], - true, - false, - ], - [ - 'test', true, true, - [ - $this->getGroupMock('test0'), - $this->getGroupMock('test1'), - ], - [$this->getGroupMock('test'), $this->getGroupMock('test0'), $this->getGroupMock('test1')], - [], - [ - ['label' => 'test0', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test0']], - ['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']], - ], - false, - null, - ], - [ - 'test', true, false, - [ - $this->getGroupMock('test0'), - $this->getGroupMock('test1'), - ], - [$this->getGroupMock('test'), $this->getGroupMock('test0'), $this->getGroupMock('test1')], - [], - [], - true, - null, - ], - [ - 'test', true, true, - [ - $this->getGroupMock('test0'), - $this->getGroupMock('test1'), - ], - [$this->getGroupMock('test'), $this->getGroupMock('test0'), $this->getGroupMock('test1')], - [ - ['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']], - ], - [ - ['label' => 'test0', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test0']], - ['label' => 'test1', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test1']], - ], - false, - $this->getGroupMock('test'), - ], - [ - 'test', true, false, - [ - $this->getGroupMock('test0'), - $this->getGroupMock('test1'), - ], - [$this->getGroupMock('test'), $this->getGroupMock('test0'), $this->getGroupMock('test1')], - [ - ['label' => 'test', 'value' => ['shareType' => Share::SHARE_TYPE_GROUP, 'shareWith' => 'test']], - ], - [], - true, - $this->getGroupMock('test'), - ], - ]; - } - - /** - * @dataProvider dataGetGroups - * - * @param string $searchTerm - * @param bool $shareWithGroupOnly - * @param bool $shareeEnumeration - * @param array $groupResponse - * @param array $userGroupsResponse - * @param array $exactExpected - * @param array $expected - * @param bool $reachedEnd - * @param mixed $singleGroup - */ - public function testGetGroups($searchTerm, $shareWithGroupOnly, $shareeEnumeration, $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->invokePrivate($this->sharees, 'shareeEnumeration', [$shareeEnumeration]); - - $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')); - } - - /** * @dataProvider dataGetRemote * * @param string $searchTerm |