diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-11-30 20:21:44 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2016-12-22 18:34:45 +0100 |
commit | 453f3beffaf629efa5c715f7ca88b5c0a1034af8 (patch) | |
tree | 68dce83e8613a7dd8321d53567a8f745c46d8266 /tests/lib/Group | |
parent | 7130fa7b4cddd35e9275f7453593049c1e989562 (diff) | |
download | nextcloud-server-453f3beffaf629efa5c715f7ca88b5c0a1034af8.tar.gz nextcloud-server-453f3beffaf629efa5c715f7ca88b5c0a1034af8.zip |
Adding group display name support
Diffstat (limited to 'tests/lib/Group')
-rw-r--r-- | tests/lib/Group/ManagerTest.php | 437 |
1 files changed, 223 insertions, 214 deletions
diff --git a/tests/lib/Group/ManagerTest.php b/tests/lib/Group/ManagerTest.php index ece99eb569d..93fe67ad9bb 100644 --- a/tests/lib/Group/ManagerTest.php +++ b/tests/lib/Group/ManagerTest.php @@ -1,52 +1,81 @@ <?php /** - * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. + * @author Robin Appelman <icewind@owncloud.com> + * @author Vincent Petry <pvince81@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud GmbH. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * */ - namespace Test\Group; -use OC\User\Manager; -use OC\User\User; +use OCP\IUser; +use OCP\GroupInterface; class ManagerTest extends \Test\TestCase { - /** @var Manager */ - private $userManager; - - public function setUp() { - parent::setUp(); - - $this->userManager = $this->getMockBuilder('\OC\User\Manager') - ->disableOriginalConstructor() - ->getMock(); + private function getTestUser($userId) { + $mockUser = $this->createMock(IUser::class); + $mockUser->expects($this->any()) + ->method('getUID') + ->will($this->returnValue($userId)); + $mockUser->expects($this->any()) + ->method('getDisplayName') + ->will($this->returnValue($userId)); + return $mockUser; } - /** - * @param string $uid - * @param \OC\User\Backend $backend - * @return User - */ - private function newUser($uid, $backend) { - $config = $this->getMockBuilder('\OCP\IConfig') - ->disableOriginalConstructor() - ->getMock(); - $urlgenerator = $this->getMockBuilder('\OCP\IURLGenerator') - ->disableOriginalConstructor() + private function getTestBackend($implementedActions = null) { + if (is_null($implementedActions)) { + $implementedActions = + GroupInterface::ADD_TO_GROUP | + GroupInterface::REMOVE_FROM_GOUP | + GroupInterface::COUNT_USERS | + GroupInterface::CREATE_GROUP | + GroupInterface::DELETE_GROUP; + } + // need to declare it this way due to optional methods + // thanks to the implementsActions logic + $backend = $this->getMockBuilder(\OCP\GroupInterface::class) + ->disableOriginalConstructor() + ->setMethods([ + 'getGroupDetails', + 'implementsActions', + 'getUserGroups', + 'inGroup', + 'getGroups', + 'groupExists', + 'usersInGroup', + 'createGroup', + 'addToGroup', + 'removeFromGroup', + ]) ->getMock(); - - return new User($uid, $backend, null, $config, $urlgenerator); + $backend->expects($this->any()) + ->method('implementsActions') + ->will($this->returnCallback(function($actions) use ($implementedActions) { + return (bool)($actions & $implementedActions); + })); + return $backend; } - + public function testGet() { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend = $this->getTestBackend(); $backend->expects($this->any()) ->method('groupExists') ->with('group1') @@ -70,9 +99,7 @@ class ManagerTest extends \Test\TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend = $this->getTestBackend(); $backend->expects($this->once()) ->method('groupExists') ->with('group1') @@ -100,9 +127,7 @@ class ManagerTest extends \Test\TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1 */ - $backend1 = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend1 = $this->getTestBackend(); $backend1->expects($this->any()) ->method('groupExists') ->with('group1') @@ -111,9 +136,7 @@ class ManagerTest extends \Test\TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend2 */ - $backend2 = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend2 = $this->getTestBackend(); $backend2->expects($this->any()) ->method('groupExists') ->with('group1') @@ -133,9 +156,7 @@ class ManagerTest extends \Test\TestCase { * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ $backendGroupCreated = false; - $backend = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend = $this->getTestBackend(); $backend->expects($this->any()) ->method('groupExists') ->with('group1') @@ -143,9 +164,6 @@ class ManagerTest extends \Test\TestCase { return $backendGroupCreated; })); $backend->expects($this->once()) - ->method('implementsActions') - ->will($this->returnValue(true)); - $backend->expects($this->once()) ->method('createGroup') ->will($this->returnCallback(function () use (&$backendGroupCreated) { $backendGroupCreated = true; @@ -162,9 +180,7 @@ class ManagerTest extends \Test\TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend = $this->getTestBackend(); $backend->expects($this->any()) ->method('groupExists') ->with('group1') @@ -183,9 +199,7 @@ class ManagerTest extends \Test\TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend = $this->getTestBackend(); $backend->expects($this->once()) ->method('getGroups') ->with('1') @@ -208,9 +222,7 @@ class ManagerTest extends \Test\TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1 */ - $backend1 = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend1 = $this->getTestBackend(); $backend1->expects($this->once()) ->method('getGroups') ->with('1') @@ -222,9 +234,7 @@ class ManagerTest extends \Test\TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend2 */ - $backend2 = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend2 = $this->getTestBackend(); $backend2->expects($this->once()) ->method('getGroups') ->with('1') @@ -249,9 +259,7 @@ class ManagerTest extends \Test\TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1 */ - $backend1 = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend1 = $this->getTestBackend(); $backend1->expects($this->once()) ->method('getGroups') ->with('1', 2, 1) @@ -263,9 +271,7 @@ class ManagerTest extends \Test\TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend2 */ - $backend2 = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend2 = $this->getTestBackend(); $backend2->expects($this->once()) ->method('getGroups') ->with('1', 2, 1) @@ -290,9 +296,7 @@ class ManagerTest extends \Test\TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend = $this->getTestBackend(); $backend->expects($this->once()) ->method('getUserGroups') ->with('user1') @@ -308,7 +312,7 @@ class ManagerTest extends \Test\TestCase { $manager = new \OC\Group\Manager($this->userManager); $manager->addBackend($backend); - $groups = $manager->getUserGroups($this->newUser('user1', $userBackend)); + $groups = $manager->getUserGroups($this->getTestUser('user1')); $this->assertEquals(1, count($groups)); $group1 = reset($groups); $this->assertEquals('group1', $group1->getGID()); @@ -344,9 +348,7 @@ class ManagerTest extends \Test\TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend = $this->getTestBackend(); $backend->expects($this->once()) ->method('getUserGroups') ->with('user1') @@ -365,9 +367,7 @@ class ManagerTest extends \Test\TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend = $this->getTestBackend(); $backend->expects($this->once()) ->method('getUserGroups') ->with('user1') @@ -386,9 +386,7 @@ class ManagerTest extends \Test\TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend = $this->getTestBackend(); $backend->expects($this->once()) ->method('getUserGroups') ->with('user1') @@ -407,9 +405,7 @@ class ManagerTest extends \Test\TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1 */ - $backend1 = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend1 = $this->getTestBackend(); $backend1->expects($this->once()) ->method('getUserGroups') ->with('user1') @@ -421,9 +417,7 @@ class ManagerTest extends \Test\TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend2 */ - $backend2 = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend2 = $this->getTestBackend(); $backend2->expects($this->once()) ->method('getUserGroups') ->with('user1') @@ -439,7 +433,7 @@ class ManagerTest extends \Test\TestCase { $manager->addBackend($backend1); $manager->addBackend($backend2); - $groups = $manager->getUserGroups($this->newUser('user1', $userBackend)); + $groups = $manager->getUserGroups($this->getTestUser('user1')); $this->assertEquals(2, count($groups)); $group1 = reset($groups); $group2 = next($groups); @@ -447,30 +441,28 @@ class ManagerTest extends \Test\TestCase { $this->assertEquals('group2', $group2->getGID()); } - public function testDisplayNamesInGroupWithOneUserBackend() { + public function testDisplayNamesInGroupWithOneUserBackend() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1 + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend = $this->getTestBackend(); $backend->expects($this->exactly(1)) ->method('groupExists') ->with('testgroup') ->will($this->returnValue(true)); - $backend->expects($this->any()) - ->method('InGroup') + $backend->expects($this->any()) + ->method('inGroup') ->will($this->returnCallback(function($uid, $gid) { - switch($uid) { - case 'user1' : return false; - case 'user2' : return true; - case 'user3' : return false; - case 'user33': return true; - default: - return null; - } - })); + switch($uid) { + case 'user1' : return false; + case 'user2' : return true; + case 'user3' : return false; + case 'user33': return true; + default: + return null; + } + })); $userBackend = $this->getMockBuilder('\OC\User\Backend') ->disableOriginalConstructor() @@ -480,21 +472,21 @@ class ManagerTest extends \Test\TestCase { ->method('searchDisplayName') ->with('user3') ->will($this->returnCallback(function($search, $limit, $offset) use ($userBackend) { - switch($offset) { - case 0 : return array('user3' => $this->newUser('user3', $userBackend), - 'user33' => $this->newUser('user33', $userBackend)); - case 2 : return array(); - } - })); + switch($offset) { + case 0 : return ['user3' => $this->getTestUser('user3'), + 'user33' => $this->getTestUser('user33')]; + case 2 : return []; + } + })); $this->userManager->expects($this->any()) ->method('get') ->will($this->returnCallback(function($uid) use ($userBackend) { switch($uid) { - case 'user1' : return $this->newUser('user1', $userBackend); - case 'user2' : return $this->newUser('user2', $userBackend); - case 'user3' : return $this->newUser('user3', $userBackend); - case 'user33': return $this->newUser('user33', $userBackend); + case 'user1' : return $this->getTestUser('user1'); + case 'user2' : return $this->getTestUser('user2'); + case 'user3' : return $this->getTestUser('user3'); + case 'user33': return $this->getTestUser('user33'); default: return null; } @@ -511,31 +503,29 @@ class ManagerTest extends \Test\TestCase { $this->assertTrue(isset($users['user33'])); } - public function testDisplayNamesInGroupWithOneUserBackendWithLimitSpecified() { + public function testDisplayNamesInGroupWithOneUserBackendWithLimitSpecified() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1 + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend = $this->getTestBackend(); $backend->expects($this->exactly(1)) ->method('groupExists') ->with('testgroup') ->will($this->returnValue(true)); - $backend->expects($this->any()) - ->method('InGroup') + $backend->expects($this->any()) + ->method('inGroup') ->will($this->returnCallback(function($uid, $gid) { - switch($uid) { - case 'user1' : return false; - case 'user2' : return true; - case 'user3' : return false; - case 'user33': return true; - case 'user333': return true; - default: - return null; - } - })); + switch($uid) { + case 'user1' : return false; + case 'user2' : return true; + case 'user3' : return false; + case 'user33': return true; + case 'user333': return true; + default: + return null; + } + })); $userBackend = $this->getMockBuilder('\OC\User\Backend') ->disableOriginalConstructor() @@ -545,22 +535,22 @@ class ManagerTest extends \Test\TestCase { ->method('searchDisplayName') ->with('user3') ->will($this->returnCallback(function($search, $limit, $offset) use ($userBackend) { - switch($offset) { - case 0 : return array('user3' => $this->newUser('user3', $userBackend), - 'user33' => $this->newUser('user33', $userBackend)); - case 2 : return array('user333' => $this->newUser('user333', $userBackend)); - } - })); + switch($offset) { + case 0 : return ['user3' => $this->getTestUser('user3'), + 'user33' => $this->getTestUser('user33')]; + case 2 : return ['user333' => $this->getTestUser('user333')]; + } + })); $this->userManager->expects($this->any()) ->method('get') ->will($this->returnCallback(function($uid) use ($userBackend) { switch($uid) { - case 'user1' : return $this->newUser('user1', $userBackend); - case 'user2' : return $this->newUser('user2', $userBackend); - case 'user3' : return $this->newUser('user3', $userBackend); - case 'user33': return $this->newUser('user33', $userBackend); - case 'user333': return $this->newUser('user333', $userBackend); + case 'user1' : return $this->getTestUser('user1'); + case 'user2' : return $this->getTestUser('user2'); + case 'user3' : return $this->getTestUser('user3'); + case 'user33': return $this->getTestUser('user33'); + case 'user333': return $this->getTestUser('user333'); default: return null; } @@ -580,29 +570,27 @@ class ManagerTest extends \Test\TestCase { public function testDisplayNamesInGroupWithOneUserBackendWithLimitAndOffsetSpecified() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1 + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend = $this->getTestBackend(); $backend->expects($this->exactly(1)) ->method('groupExists') ->with('testgroup') ->will($this->returnValue(true)); - $backend->expects($this->any()) + $backend->expects($this->any()) ->method('inGroup') ->will($this->returnCallback(function($uid) { - switch($uid) { - case 'user1' : return false; - case 'user2' : return true; - case 'user3' : return false; - case 'user33': return true; - case 'user333': return true; - default: - return null; - } - })); + switch($uid) { + case 'user1' : return false; + case 'user2' : return true; + case 'user3' : return false; + case 'user33': return true; + case 'user333': return true; + default: + return null; + } + })); $userBackend = $this->getMockBuilder('\OC\User\Backend') ->disableOriginalConstructor() @@ -612,25 +600,25 @@ class ManagerTest extends \Test\TestCase { ->method('searchDisplayName') ->with('user3') ->will($this->returnCallback(function($search, $limit, $offset) use ($userBackend) { - switch($offset) { - case 0 : - return array( - 'user3' => $this->newUser('user3', $userBackend), - 'user33' => $this->newUser('user33', $userBackend), - 'user333' => $this->newUser('user333', $userBackend) - ); - } - })); + switch($offset) { + case 0 : + return [ + 'user3' => $this->getTestUser('user3'), + 'user33' => $this->getTestUser('user33'), + 'user333' => $this->getTestUser('user333') + ]; + } + })); $this->userManager->expects($this->any()) ->method('get') ->will($this->returnCallback(function($uid) use ($userBackend) { switch($uid) { - case 'user1' : return $this->newUser('user1', $userBackend); - case 'user2' : return $this->newUser('user2', $userBackend); - case 'user3' : return $this->newUser('user3', $userBackend); - case 'user33': return $this->newUser('user33', $userBackend); - case 'user333': return $this->newUser('user333', $userBackend); + case 'user1' : return $this->getTestUser('user1'); + case 'user2' : return $this->getTestUser('user2'); + case 'user3' : return $this->getTestUser('user3'); + case 'user33': return $this->getTestUser('user33'); + case 'user333': return $this->getTestUser('user333'); default: return null; } @@ -650,17 +638,15 @@ class ManagerTest extends \Test\TestCase { public function testDisplayNamesInGroupWithOneUserBackendAndSearchEmpty() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1 + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend = $this->getTestBackend(); $backend->expects($this->exactly(1)) ->method('groupExists') ->with('testgroup') ->will($this->returnValue(true)); - $backend->expects($this->once()) + $backend->expects($this->once()) ->method('usersInGroup') ->with('testgroup', '', -1, 0) ->will($this->returnValue(array('user2', 'user33'))); @@ -673,10 +659,10 @@ class ManagerTest extends \Test\TestCase { ->method('get') ->will($this->returnCallback(function($uid) use ($userBackend) { switch($uid) { - case 'user1' : return $this->newUser('user1', $userBackend); - case 'user2' : return $this->newUser('user2', $userBackend); - case 'user3' : return $this->newUser('user3', $userBackend); - case 'user33': return $this->newUser('user33', $userBackend); + case 'user1' : return $this->getTestUser('user1'); + case 'user2' : return $this->getTestUser('user2'); + case 'user3' : return $this->getTestUser('user3'); + case 'user33': return $this->getTestUser('user33'); default: return null; } @@ -695,11 +681,9 @@ class ManagerTest extends \Test\TestCase { public function testDisplayNamesInGroupWithOneUserBackendAndSearchEmptyAndLimitSpecified() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1 + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend = $this->getTestBackend(); $backend->expects($this->exactly(1)) ->method('groupExists') ->with('testgroup') @@ -718,10 +702,10 @@ class ManagerTest extends \Test\TestCase { ->method('get') ->will($this->returnCallback(function($uid) use ($userBackend) { switch($uid) { - case 'user1' : return $this->newUser('user1', $userBackend); - case 'user2' : return $this->newUser('user2', $userBackend); - case 'user3' : return $this->newUser('user3', $userBackend); - case 'user33': return $this->newUser('user33', $userBackend); + case 'user1' : return $this->getTestUser('user1'); + case 'user2' : return $this->getTestUser('user2'); + case 'user3' : return $this->getTestUser('user3'); + case 'user33': return $this->getTestUser('user33'); default: return null; } @@ -738,13 +722,11 @@ class ManagerTest extends \Test\TestCase { $this->assertFalse(isset($users['user33'])); } - public function testDisplayNamesInGroupWithOneUserBackendAndSearchEmptyAndLimitAndOffsetSpecified() { + public function testDisplayNamesInGroupWithOneUserBackendAndSearchEmptyAndLimitAndOffsetSpecified() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1 + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend = $this->getTestBackend(); $backend->expects($this->exactly(1)) ->method('groupExists') ->with('testgroup') @@ -763,10 +745,10 @@ class ManagerTest extends \Test\TestCase { ->method('get') ->will($this->returnCallback(function($uid) use ($userBackend) { switch($uid) { - case 'user1' : return $this->newUser('user1', $userBackend); - case 'user2' : return $this->newUser('user2', $userBackend); - case 'user3' : return $this->newUser('user3', $userBackend); - case 'user33': return $this->newUser('user33', $userBackend); + case 'user1' : return $this->getTestUser('user1'); + case 'user2' : return $this->getTestUser('user2'); + case 'user3' : return $this->getTestUser('user3'); + case 'user33': return $this->getTestUser('user33'); default: return null; } @@ -787,10 +769,8 @@ class ManagerTest extends \Test\TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); - $expectedGroups = array(); + $backend = $this->getTestBackend(); + $expectedGroups = []; $backend->expects($this->any()) ->method('getUserGroups') ->with('user1') @@ -801,15 +781,12 @@ class ManagerTest extends \Test\TestCase { ->method('groupExists') ->with('group1') ->will($this->returnValue(true)); - $backend->expects($this->once()) - ->method('implementsActions') - ->will($this->returnValue(true)); $manager = new \OC\Group\Manager($this->userManager); $manager->addBackend($backend); // prime cache - $user1 = $this->newUser('user1', null); + $user1 = $this->getTestUser('user1'); $groups = $manager->getUserGroups($user1); $this->assertEquals(array(), $groups); @@ -829,10 +806,8 @@ class ManagerTest extends \Test\TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); - $expectedGroups = array('group1'); + $backend = $this->getTestBackend(); + $expectedGroups = ['group1']; $backend->expects($this->any()) ->method('getUserGroups') ->with('user1') @@ -844,9 +819,6 @@ class ManagerTest extends \Test\TestCase { ->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()) @@ -857,7 +829,7 @@ class ManagerTest extends \Test\TestCase { $manager->addBackend($backend); // prime cache - $user1 = $this->newUser('user1', null); + $user1 = $this->getTestUser('user1'); $groups = $manager->getUserGroups($user1); $this->assertEquals(1, count($groups)); $group1 = reset($groups); @@ -877,9 +849,7 @@ class ManagerTest extends \Test\TestCase { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); + $backend = $this->getTestBackend(); $backend->expects($this->any()) ->method('getUserGroups') ->with('user1') @@ -892,4 +862,43 @@ class ManagerTest extends \Test\TestCase { $this->assertEquals([], $groups); } + public function testGroupDisplayName() { + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend + */ + $backend = $this->getTestBackend( + GroupInterface::ADD_TO_GROUP | + GroupInterface::REMOVE_FROM_GOUP | + GroupInterface::COUNT_USERS | + GroupInterface::CREATE_GROUP | + GroupInterface::DELETE_GROUP | + GroupInterface::GROUP_DETAILS + ); + $backend->expects($this->any()) + ->method('getGroupDetails') + ->will($this->returnValueMap([ + ['group1', ['gid' => 'group1', 'displayName' => 'Group One']], + ['group2', ['gid' => 'group2']], + ])); + + /** + * @var \OC\User\Manager $userManager + */ + $userManager = $this->createMock('\OC\User\Manager'); + $manager = new \OC\Group\Manager($userManager); + $manager->addBackend($backend); + + // group with display name + $group = $manager->get('group1'); + $this->assertNotNull($group); + $this->assertEquals('group1', $group->getGID()); + $this->assertEquals('Group One', $group->getDisplayName()); + + // group without display name + $group = $manager->get('group2'); + $this->assertNotNull($group); + $this->assertEquals('group2', $group->getGID()); + $this->assertEquals('group2', $group->getDisplayName()); + } + } |