Avoid php message "Invalid argument supplied for foreach()" - refs #15590
This commit is contained in:
parent
75adee1ebd
commit
88cc52c408
2 changed files with 39 additions and 2 deletions
|
@ -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;
|
||||
|
|
|
@ -846,4 +846,39 @@ 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));
|
||||
// $backend->expects($this->any())
|
||||
// ->method('groupExists')
|
||||
// ->with('group1')
|
||||
// ->will($this->returnValue(true));
|
||||
// $backend->expects($this->once())
|
||||
// ->method('implementsActions')
|
||||
// ->will($this->returnValue(true));
|
||||
// $backend->expects($this->once())
|
||||
// ->method('inGroup')
|
||||
// ->will($this->returnValue(true));
|
||||
// $backend->expects($this->once())
|
||||
// ->method('removeFromGroup')
|
||||
// ->will($this->returnValue(true));
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue