]> source.dussan.org Git - nextcloud-server.git/commitdiff
Avoid php message "Invalid argument supplied for foreach()" - refs #15590
authorThomas Müller <thomas.mueller@tmit.eu>
Tue, 14 Apr 2015 09:00:20 +0000 (11:00 +0200)
committerThomas Müller <thomas.mueller@tmit.eu>
Tue, 14 Apr 2015 09:00:20 +0000 (11:00 +0200)
lib/private/group/manager.php
tests/lib/group/manager.php

index 774a76a30636014321db1972efb9ec0aa8b42753..12136a1bd2516965f048b5e8711ad8e9b1bbeeef 100644 (file)
@@ -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;
index 76996a2b9bb8a318ba00e3028416e2033f760a99..0f3573f96e1dd908774e90904ab88defdb93e349 100644 (file)
@@ -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);
+       }
+
 }