diff options
-rw-r--r-- | lib/private/group/manager.php | 6 | ||||
-rw-r--r-- | tests/lib/group/manager.php | 22 |
2 files changed, 26 insertions, 2 deletions
diff --git a/lib/private/group/manager.php b/lib/private/group/manager.php index 774a76a3063..12136a1bd25 100644 --- a/lib/private/group/manager.php +++ b/lib/private/group/manager.php @@ -205,8 +205,10 @@ class Manager extends PublicEmitter implements IGroupManager { $groups = array(); foreach ($this->backends as $backend) { $groupIds = $backend->getUserGroups($uid); - foreach ($groupIds as $groupId) { - $groups[$groupId] = $this->get($groupId); + if (is_array($groupIds)) { + foreach ($groupIds as $groupId) { + $groups[$groupId] = $this->get($groupId); + } } } $this->cachedUserGroups[$uid] = $groups; diff --git a/tests/lib/group/manager.php b/tests/lib/group/manager.php index 76996a2b9bb..e3e2a96e46d 100644 --- a/tests/lib/group/manager.php +++ b/tests/lib/group/manager.php @@ -846,4 +846,26 @@ class Manager extends \Test\TestCase { $groups = $manager->getUserGroups($user1); $this->assertEquals(array(), $groups); } + + public function testGetUserIdGroups() { + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + */ + $backend = $this->getMock('\OC_Group_Database'); + $backend->expects($this->any()) + ->method('getUserGroups') + ->with('user1') + ->will($this->returnValue(null)); + + /** + * @var \OC\User\Manager $userManager + */ + $userManager = $this->getMock('\OC\User\Manager'); + $manager = new \OC\Group\Manager($userManager); + $manager->addBackend($backend); + + $groups = $manager->getUserIdGroups('user1'); + $this->assertEquals([], $groups); + } + } |