diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Files/FilesystemTest.php | 31 | ||||
-rw-r--r-- | tests/lib/Files/Storage/HomeTest.php | 8 | ||||
-rw-r--r-- | tests/lib/Group/ManagerTest.php | 449 | ||||
-rw-r--r-- | tests/lib/TestCase.php | 4 |
4 files changed, 232 insertions, 260 deletions
diff --git a/tests/lib/Files/FilesystemTest.php b/tests/lib/Files/FilesystemTest.php index dd4785ecf09..df77a0855de 100644 --- a/tests/lib/Files/FilesystemTest.php +++ b/tests/lib/Files/FilesystemTest.php @@ -426,37 +426,6 @@ class FilesystemTest extends \Test\TestCase { if ($user !== null) { $user->delete(); } } - /** - * Tests that the home storage is used in legacy mode - * for the user's mount point - */ - public function testLegacyHomeMount() { - if (getenv('RUN_OBJECTSTORE_TESTS')) { - $this->markTestSkipped('legacy storage unrelated to objectstore environments'); - } - $datadir = \OC::$server->getConfig()->getSystemValue("datadirectory", \OC::$SERVERROOT . "/data"); - $userId = $this->getUniqueID('user_'); - - // insert storage into DB by constructing it - // to make initMountsPoint find its existence - $localStorage = new \OC\Files\Storage\Local(array('datadir' => $datadir . '/' . $userId . '/')); - // this will trigger the insert - $cache = $localStorage->getCache(); - - \OC::$server->getUserManager()->createUser($userId, $userId); - \OC\Files\Filesystem::initMountPoints($userId); - - $homeMount = \OC\Files\Filesystem::getStorage('/' . $userId . '/'); - - $this->assertTrue($homeMount->instanceOfStorage('\OC\Files\Storage\Home')); - $this->assertEquals('local::' . $datadir . '/' . $userId . '/', $homeMount->getId()); - - $user = \OC::$server->getUserManager()->get($userId); - if ($user !== null) { $user->delete(); } - // delete storage entry - $cache->clear(); - } - public function dummyHook($arguments) { $path = $arguments['path']; $this->assertEquals($path, \OC\Files\Filesystem::normalizePath($path)); //the path passed to the hook should already be normalized diff --git a/tests/lib/Files/Storage/HomeTest.php b/tests/lib/Files/Storage/HomeTest.php index d9a1b11849e..e6899ff7d38 100644 --- a/tests/lib/Files/Storage/HomeTest.php +++ b/tests/lib/Files/Storage/HomeTest.php @@ -89,14 +89,6 @@ class HomeTest extends Storage { } /** - * Tests that the legacy home id is in the format local::/path/to/datadir/user1/ - */ - public function testLegacyId() { - $this->instance = new \OC\Files\Storage\Home(array('user' => $this->user, 'legacy' => true)); - $this->assertEquals('local::' . $this->tmpDir . '/', $this->instance->getId()); - } - - /** * Tests that getCache() returns an instance of HomeCache */ public function testGetCacheReturnsHomeCache() { diff --git a/tests/lib/Group/ManagerTest.php b/tests/lib/Group/ManagerTest.php index ece99eb569d..1a7ced5f1ba 100644 --- a/tests/lib/Group/ManagerTest.php +++ b/tests/lib/Group/ManagerTest.php @@ -1,52 +1,91 @@ <?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; + /** @var Manager|\PHPUnit_Framework_MockObject_MockObject $userManager */ + protected $userManager; - public function setUp() { + protected function setUp() { parent::setUp(); - $this->userManager = $this->getMockBuilder('\OC\User\Manager') - ->disableOriginalConstructor() - ->getMock(); + $this->userManager = $this->createMock(Manager::class); } - /** - * @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() - ->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; + } - return new User($uid, $backend, null, $config, $urlgenerator); + 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(); + $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 +109,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 +137,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 +146,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 +166,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 +174,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 +190,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 +209,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 +232,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 +244,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 +269,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 +281,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 +306,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') @@ -302,13 +316,10 @@ class ManagerTest extends \Test\TestCase { ->with('group1') ->will($this->returnValue(true)); - $userBackend = $this->getMockBuilder('\OC\Group\Database') - ->disableOriginalConstructor() - ->getMock(); $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 +355,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 +374,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 +393,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 +412,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 +424,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') @@ -432,14 +433,11 @@ class ManagerTest extends \Test\TestCase { ->method('groupExists') ->will($this->returnValue(true)); - $userBackend = $this->getMockBuilder('\OC\User\Backend') - ->disableOriginalConstructor() - ->getMock(); $manager = new \OC\Group\Manager($this->userManager); $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 +445,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 +476,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 []; + } + return null; + })); $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 +507,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 +539,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')]; + } + return null; + })); $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 +574,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 +604,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') + ]; + } + return null; + })); $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 +642,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 +663,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 +685,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 +706,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 +726,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 +749,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 +773,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,22 +785,19 @@ 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); // add user $group = $manager->get('group1'); $group->addUser($user1); - $expectedGroups = array('group1'); + $expectedGroups = ['group1']; // check result $groups = $manager->getUserGroups($user1); @@ -829,10 +810,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 +823,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 +833,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 +853,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 +866,39 @@ 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']], + ])); + + $manager = new \OC\Group\Manager($this->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()); + } + } diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php index f115c11938a..afed2817910 100644 --- a/tests/lib/TestCase.php +++ b/tests/lib/TestCase.php @@ -184,7 +184,9 @@ abstract class TestCase extends TestCasePhpUnitCompatibility { // fail hard if xml errors have not been cleaned up $errors = libxml_get_errors(); libxml_clear_errors(); - $this->assertEquals([], $errors); + if (!empty($errors)) { + self::assertEquals([], $errors, "There have been xml parsing errors"); + } \OC\Files\Cache\Storage::getGlobalCache()->clearCache(); |