diff options
author | Bart Visscher <bartv@thisnet.nl> | 2014-05-07 17:54:38 +0200 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2014-05-07 17:54:38 +0200 |
commit | f569c721a64486d0e7c7e307ed77ac0caed2dc2d (patch) | |
tree | df7b3399a858ffdae6bd6e66616746efbcee24bc /tests/lib/group | |
parent | 47d70da2f5cb55ad47023b061b68062dd8b8d8e2 (diff) | |
parent | 254fa5eb22efa5ba572702064377a6ad9eec9a53 (diff) | |
download | nextcloud-server-f569c721a64486d0e7c7e307ed77ac0caed2dc2d.tar.gz nextcloud-server-f569c721a64486d0e7c7e307ed77ac0caed2dc2d.zip |
Merge branch 'master' into optimize-startup-queries
Conflicts:
apps/files_sharing/lib/sharedstorage.php
tests/lib/group/manager.php
removed hasFilesSharedWith from lib/public/share.php and
sharedstorage.php to fix merge
Diffstat (limited to 'tests/lib/group')
-rw-r--r-- | tests/lib/group/group.php | 64 | ||||
-rw-r--r-- | tests/lib/group/manager.php | 52 |
2 files changed, 114 insertions, 2 deletions
diff --git a/tests/lib/group/group.php b/tests/lib/group/group.php index 3982c00e45f..990f8ecc1d5 100644 --- a/tests/lib/group/group.php +++ b/tests/lib/group/group.php @@ -287,7 +287,7 @@ class Group extends \PHPUnit_Framework_TestCase { ->will($this->returnValue(array('user2'))); $backend2->expects($this->once()) ->method('usersInGroup') - ->with('group1', 'user', 1, 0) + ->with('group1', 'user', 2, 1) ->will($this->returnValue(array('user1'))); $users = $group->searchUsers('user', 2, 1); @@ -299,6 +299,68 @@ class Group extends \PHPUnit_Framework_TestCase { $this->assertEquals('user1', $user1->getUID()); } + public function testCountUsers() { + $backend1 = $this->getMock('OC_Group_Database'); + $userManager = $this->getUserManager(); + $group = new \OC\Group\Group('group1', array($backend1), $userManager); + + $backend1->expects($this->once()) + ->method('countUsersInGroup') + ->with('group1', '2') + ->will($this->returnValue(3)); + + $backend1->expects($this->any()) + ->method('implementsActions') + ->will($this->returnValue(true)); + + $users = $group->count('2'); + + $this->assertSame(3, $users); + } + + public function testCountUsersMultipleBackends() { + $backend1 = $this->getMock('OC_Group_Database'); + $backend2 = $this->getMock('OC_Group_Database'); + $userManager = $this->getUserManager(); + $group = new \OC\Group\Group('group1', array($backend1, $backend2), $userManager); + + $backend1->expects($this->once()) + ->method('countUsersInGroup') + ->with('group1', '2') + ->will($this->returnValue(3)); + $backend1->expects($this->any()) + ->method('implementsActions') + ->will($this->returnValue(true)); + + $backend2->expects($this->once()) + ->method('countUsersInGroup') + ->with('group1', '2') + ->will($this->returnValue(4)); + $backend2->expects($this->any()) + ->method('implementsActions') + ->will($this->returnValue(true)); + + $users = $group->count('2'); + + $this->assertSame(7, $users); + } + + public function testCountUsersNoMethod() { + $backend1 = $this->getMock('OC_Group_Database'); + $userManager = $this->getUserManager(); + $group = new \OC\Group\Group('group1', array($backend1), $userManager); + + $backend1->expects($this->never()) + ->method('countUsersInGroup'); + $backend1->expects($this->any()) + ->method('implementsActions') + ->will($this->returnValue(false)); + + $users = $group->count('2'); + + $this->assertSame(false, $users); + } + public function testDelete() { $backend = $this->getMock('OC_Group_Database'); $userManager = $this->getUserManager(); diff --git a/tests/lib/group/manager.php b/tests/lib/group/manager.php index c39a7d6f33a..bab9621e39d 100644 --- a/tests/lib/group/manager.php +++ b/tests/lib/group/manager.php @@ -254,7 +254,7 @@ class Manager extends \PHPUnit_Framework_TestCase { $backend2 = $this->getMock('\OC_Group_Database'); $backend2->expects($this->once()) ->method('getGroups') - ->with('1', 1, 0) + ->with('1', 2, 1) ->will($this->returnValue(array('group12'))); $backend2->expects($this->any()) ->method('groupExists') @@ -344,6 +344,56 @@ class Manager extends \PHPUnit_Framework_TestCase { $this->assertEquals('group2', $group2->getGID()); } + public function testDisplayNamesInGroupMultipleUserBackends() { + $user1 = new User('user1', null); + $user2 = new User('user2', null); + $user3 = new User('user3', null); + $user4 = new User('user33', null); + + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1 + */ + $backend = $this->getMock('\OC_Group_Database'); + $backend->expects($this->exactly(1)) + ->method('groupExists') + ->with('testgroup') + ->will($this->returnValue(true)); + + $backend->expects($this->once()) + ->method('usersInGroup') + ->with('testgroup', '', -1, 0) + ->will($this->returnValue(array('user2', 'user33'))); + + /** + * @var \OC\User\Manager $userManager + */ + $userManager = $this->getMock('\OC\User\Manager'); + $userManager->expects($this->once()) + ->method('search') + ->with('user3') + ->will($this->returnValue(array('user3' => $user3, 'user33' => $user4))); + + $userManager->expects($this->any()) + ->method('get') + ->will($this->returnCallback(function($uid) { + switch($uid) { + case 'user1' : return new User('user1', null); + case 'user2' : return new User('user2', null); + case 'user3' : return new User('user3', null); + case 'user33': return new User('user33', null); + default: + return null; + } + })); + + $manager = new \OC\Group\Manager($userManager); + $manager->addBackend($backend); + + $users = $manager->displayNamesInGroup('testgroup', 'user3'); + $this->assertEquals(1, count($users)); + $this->assertTrue(isset($users['user33'])); + } + public function testGetUserGroupsWithAddUser() { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend |