From 5c9103287f7ed8f2d69dd179b7eb160c1b1a65fd Mon Sep 17 00:00:00 2001 From: Roeland Douma Date: Tue, 17 May 2016 16:06:44 +0200 Subject: [PATCH] Group fixup (#24621) * Move used OC_Group_xx to \OC\Group * Add (deprecated) legacy wrapper in legacy, OC_Group_xx * Replace deprecated use of OC_Group_xx with \OC\Group\xx --- apps/files_sharing/tests/testcase.php | 2 +- apps/user_ldap/group_ldap.php | 2 +- lib/base.php | 2 +- lib/private/Group/Backend.php | 149 ++++++++++++ lib/private/Group/Database.php | 338 ++++++++++++++++++++++++++ lib/private/Group/Group.php | 12 +- lib/private/Group/Manager.php | 2 +- lib/private/legacy/group.php | 2 +- lib/private/legacy/group/backend.php | 114 +-------- lib/private/legacy/group/database.php | 316 +----------------------- tests/lib/group/backend.php | 2 +- tests/lib/group/database.php | 4 +- tests/lib/group/group.php | 46 ++-- tests/lib/group/manager.php | 104 ++++---- tests/lib/util/group/dummy.php | 4 +- 15 files changed, 585 insertions(+), 514 deletions(-) create mode 100644 lib/private/Group/Backend.php create mode 100644 lib/private/Group/Database.php diff --git a/apps/files_sharing/tests/testcase.php b/apps/files_sharing/tests/testcase.php index 0950c2a62f5..b1d6facafd6 100644 --- a/apps/files_sharing/tests/testcase.php +++ b/apps/files_sharing/tests/testcase.php @@ -143,7 +143,7 @@ abstract class TestCase extends \Test\TestCase { \OC_User::clearBackends(); \OC_User::useBackend('database'); \OC_Group::clearBackends(); - \OC_Group::useBackend(new \OC_Group_Database()); + \OC_Group::useBackend(new \OC\Group\Database()); parent::tearDownAfterClass(); } diff --git a/apps/user_ldap/group_ldap.php b/apps/user_ldap/group_ldap.php index eba39ca50f7..ff8197fb43a 100644 --- a/apps/user_ldap/group_ldap.php +++ b/apps/user_ldap/group_ldap.php @@ -894,6 +894,6 @@ class GROUP_LDAP extends BackendUtility implements \OCP\GroupInterface { * compared with OC_USER_BACKEND_CREATE_USER etc. */ public function implementsActions($actions) { - return (bool)(\OC_Group_Backend::COUNT_USERS & $actions); + return (bool)(\OC\Group\Backend::COUNT_USERS & $actions); } } diff --git a/lib/base.php b/lib/base.php index cc0429af110..ad3c9501268 100644 --- a/lib/base.php +++ b/lib/base.php @@ -620,7 +620,7 @@ class OC { } OC_User::useBackend(new \OC\User\Database()); - OC_Group::useBackend(new OC_Group_Database()); + OC_Group::useBackend(new \OC\Group\Database()); // Subscribe to the hook \OCP\Util::connectHook( diff --git a/lib/private/Group/Backend.php b/lib/private/Group/Backend.php new file mode 100644 index 00000000000..6dd5bdc3507 --- /dev/null +++ b/lib/private/Group/Backend.php @@ -0,0 +1,149 @@ + + * @author Bart Visscher + * @author Jakob Sack + * @author Joas Schilling + * @author Jörn Friedrich Dreyer + * @author Lukas Reschke + * @author Michael Gapczynski + * @author Morris Jobke + * @author Robin Appelman + * @author Robin McCorkell + * @author Thomas Müller + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 + * + */ + +namespace OC\Group; + +/** + * Abstract base class for user management + */ +abstract class Backend implements \OCP\GroupInterface { + /** + * error code for functions not provided by the group backend + */ + const NOT_IMPLEMENTED = -501; + + /** + * actions that user backends can define + */ + const CREATE_GROUP = 0x00000001; + const DELETE_GROUP = 0x00000010; + const ADD_TO_GROUP = 0x00000100; + const REMOVE_FROM_GOUP = 0x00001000; + //OBSOLETE const GET_DISPLAYNAME = 0x00010000; + const COUNT_USERS = 0x00100000; + + protected $possibleActions = array( + self::CREATE_GROUP => 'createGroup', + self::DELETE_GROUP => 'deleteGroup', + self::ADD_TO_GROUP => 'addToGroup', + self::REMOVE_FROM_GOUP => 'removeFromGroup', + self::COUNT_USERS => 'countUsersInGroup', + ); + + /** + * Get all supported actions + * @return int bitwise-or'ed actions + * + * Returns the supported actions as int to be + * compared with \OC\Group\Backend::CREATE_GROUP etc. + */ + public function getSupportedActions() { + $actions = 0; + foreach($this->possibleActions AS $action => $methodName) { + if(method_exists($this, $methodName)) { + $actions |= $action; + } + } + + return $actions; + } + + /** + * Check if backend implements actions + * @param int $actions bitwise-or'ed actions + * @return bool + * + * Returns the supported actions as int to be + * compared with \OC\Group\Backend::CREATE_GROUP etc. + */ + public function implementsActions($actions) { + return (bool)($this->getSupportedActions() & $actions); + } + + /** + * is user in group? + * @param string $uid uid of the user + * @param string $gid gid of the group + * @return bool + * + * Checks whether the user is member of a group or not. + */ + public function inGroup($uid, $gid) { + return in_array($gid, $this->getUserGroups($uid)); + } + + /** + * Get all groups a user belongs to + * @param string $uid Name of the user + * @return array an array of group names + * + * This function fetches all groups a user belongs to. It does not check + * if the user exists at all. + */ + public function getUserGroups($uid) { + return array(); + } + + /** + * get a list of all groups + * @param string $search + * @param int $limit + * @param int $offset + * @return array an array of group names + * + * Returns a list with all groups + */ + + public function getGroups($search = '', $limit = -1, $offset = 0) { + return array(); + } + + /** + * check if a group exists + * @param string $gid + * @return bool + */ + public function groupExists($gid) { + return in_array($gid, $this->getGroups($gid, 1)); + } + + /** + * get a list of all users in a group + * @param string $gid + * @param string $search + * @param int $limit + * @param int $offset + * @return array an array of user ids + */ + public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { + return array(); + } +} diff --git a/lib/private/Group/Database.php b/lib/private/Group/Database.php new file mode 100644 index 00000000000..9fefdd77300 --- /dev/null +++ b/lib/private/Group/Database.php @@ -0,0 +1,338 @@ + + * @author Bart Visscher + * @author Jakob Sack + * @author Joas Schilling + * @author Jörn Friedrich Dreyer + * @author Michael Gapczynski + * @author michag86 + * @author Morris Jobke + * @author Robin Appelman + * @author Robin McCorkell + * @author Roeland Jago Douma + * @author Thomas Müller + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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 + * + */ +/* + * + * The following SQL statement is just a help for developers and will not be + * executed! + * + * CREATE TABLE `groups` ( + * `gid` varchar(64) COLLATE utf8_unicode_ci NOT NULL, + * PRIMARY KEY (`gid`) + * ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + * + * CREATE TABLE `group_user` ( + * `gid` varchar(64) COLLATE utf8_unicode_ci NOT NULL, + * `uid` varchar(64) COLLATE utf8_unicode_ci NOT NULL + * ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + * + */ + +namespace OC\Group; + +/** + * Class for group management in a SQL Database (e.g. MySQL, SQLite) + */ +class Database extends \OC\Group\Backend { + + /** @var string[] */ + private $groupCache = []; + + /** @var \OCP\IDBConnection */ + private $dbConn; + + /** + * \OC\Group\Database constructor. + * + * @param \OCP\IDBConnection|null $dbConn + */ + public function __construct(\OCP\IDBConnection $dbConn = null) { + $this->dbConn = $dbConn; + } + + /** + * FIXME: This function should not be required! + */ + private function fixDI() { + if ($this->dbConn === null) { + $this->dbConn = \OC::$server->getDatabaseConnection(); + } + } + + /** + * Try to create a new group + * @param string $gid The name of the group to create + * @return bool + * + * Tries to create a new group. If the group name already exists, false will + * be returned. + */ + public function createGroup( $gid ) { + $this->fixDI(); + + // Add group + $result = $this->dbConn->insertIfNotExist('*PREFIX*groups', [ + 'gid' => $gid, + ]); + + // Add to cache + $this->groupCache[$gid] = $gid; + + return $result === 1; + } + + /** + * delete a group + * @param string $gid gid of the group to delete + * @return bool + * + * Deletes a group and removes it from the group_user-table + */ + public function deleteGroup( $gid ) { + $this->fixDI(); + + // Delete the group + $qb = $this->dbConn->getQueryBuilder(); + $qb->delete('groups') + ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) + ->execute(); + + // Delete the group-user relation + $qb = $this->dbConn->getQueryBuilder(); + $qb->delete('group_user') + ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) + ->execute(); + + // Delete the group-groupadmin relation + $qb = $this->dbConn->getQueryBuilder(); + $qb->delete('group_admin') + ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) + ->execute(); + + // Delete from cache + unset($this->groupCache[$gid]); + + return true; + } + + /** + * is user in group? + * @param string $uid uid of the user + * @param string $gid gid of the group + * @return bool + * + * Checks whether the user is member of a group or not. + */ + public function inGroup( $uid, $gid ) { + $this->fixDI(); + + // check + $qb = $this->dbConn->getQueryBuilder(); + $cursor = $qb->select('uid') + ->from('group_user') + ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) + ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) + ->execute(); + + $result = $cursor->fetch(); + $cursor->closeCursor(); + + return $result ? true : false; + } + + /** + * Add a user to a group + * @param string $uid Name of the user to add to group + * @param string $gid Name of the group in which add the user + * @return bool + * + * Adds a user to a group. + */ + public function addToGroup( $uid, $gid ) { + $this->fixDI(); + + // No duplicate entries! + if( !$this->inGroup( $uid, $gid )) { + $qb = $this->dbConn->getQueryBuilder(); + $qb->insert('group_user') + ->setValue('uid', $qb->createNamedParameter($uid)) + ->setValue('gid', $qb->createNamedParameter($gid)) + ->execute(); + return true; + }else{ + return false; + } + } + + /** + * Removes a user from a group + * @param string $uid Name of the user to remove from group + * @param string $gid Name of the group from which remove the user + * @return bool + * + * removes the user from a group. + */ + public function removeFromGroup( $uid, $gid ) { + $this->fixDI(); + + $qb = $this->dbConn->getQueryBuilder(); + $qb->delete('group_user') + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) + ->andWhere($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) + ->execute(); + + return true; + } + + /** + * Get all groups a user belongs to + * @param string $uid Name of the user + * @return array an array of group names + * + * This function fetches all groups a user belongs to. It does not check + * if the user exists at all. + */ + public function getUserGroups( $uid ) { + $this->fixDI(); + + // No magic! + $qb = $this->dbConn->getQueryBuilder(); + $cursor = $qb->select('gid') + ->from('group_user') + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) + ->execute(); + + $groups = []; + while( $row = $cursor->fetch()) { + $groups[] = $row["gid"]; + $this->groupCache[$row['gid']] = $row['gid']; + } + $cursor->closeCursor(); + + return $groups; + } + + /** + * get a list of all groups + * @param string $search + * @param int $limit + * @param int $offset + * @return array an array of group names + * + * Returns a list with all groups + */ + public function getGroups($search = '', $limit = null, $offset = null) { + $parameters = []; + $searchLike = ''; + if ($search !== '') { + $parameters[] = '%' . $search . '%'; + $searchLike = ' WHERE LOWER(`gid`) LIKE LOWER(?)'; + } + + $stmt = \OC_DB::prepare('SELECT `gid` FROM `*PREFIX*groups`' . $searchLike . ' ORDER BY `gid` ASC', $limit, $offset); + $result = $stmt->execute($parameters); + $groups = array(); + while ($row = $result->fetchRow()) { + $groups[] = $row['gid']; + } + return $groups; + } + + /** + * check if a group exists + * @param string $gid + * @return bool + */ + public function groupExists($gid) { + $this->fixDI(); + + // Check cache first + if (isset($this->groupCache[$gid])) { + return true; + } + + $qb = $this->dbConn->getQueryBuilder(); + $cursor = $qb->select('gid') + ->from('groups') + ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) + ->execute(); + $result = $cursor->fetch(); + $cursor->closeCursor(); + + if ($result !== false) { + $this->groupCache[$gid] = $gid; + return true; + } + return false; + } + + /** + * get a list of all users in a group + * @param string $gid + * @param string $search + * @param int $limit + * @param int $offset + * @return array an array of user ids + */ + public function usersInGroup($gid, $search = '', $limit = null, $offset = null) { + $parameters = [$gid]; + $searchLike = ''; + if ($search !== '') { + $parameters[] = '%' . $search . '%'; + $searchLike = ' AND `uid` LIKE ?'; + } + + $stmt = \OC_DB::prepare('SELECT `uid` FROM `*PREFIX*group_user` WHERE `gid` = ?' . $searchLike . ' ORDER BY `uid` ASC', + $limit, + $offset); + $result = $stmt->execute($parameters); + $users = array(); + while ($row = $result->fetchRow()) { + $users[] = $row['uid']; + } + return $users; + } + + /** + * get the number of all users matching the search string in a group + * @param string $gid + * @param string $search + * @return int|false + * @throws \OC\DatabaseException + */ + public function countUsersInGroup($gid, $search = '') { + $parameters = [$gid]; + $searchLike = ''; + if ($search !== '') { + $parameters[] = '%' . $search . '%'; + $searchLike = ' AND `uid` LIKE ?'; + } + + $stmt = \OC_DB::prepare('SELECT COUNT(`uid`) AS `count` FROM `*PREFIX*group_user` WHERE `gid` = ?' . $searchLike); + $result = $stmt->execute($parameters); + $count = $result->fetchOne(); + if($count !== false) { + $count = intval($count); + } + return $count; + } + +} diff --git a/lib/private/Group/Group.php b/lib/private/Group/Group.php index 064b9f899e6..c42f53af9a6 100644 --- a/lib/private/Group/Group.php +++ b/lib/private/Group/Group.php @@ -46,7 +46,7 @@ class Group implements IGroup { private $usersLoaded; /** - * @var \OC_Group_Backend[]|\OC_Group_Database[] $backend + * @var \OC\Group\Backend[]|\OC\Group\Database[] $backend */ private $backends; @@ -62,7 +62,7 @@ class Group implements IGroup { /** * @param string $gid - * @param \OC_Group_Backend[] $backends + * @param \OC\Group\Backend[] $backends * @param \OC\User\Manager $userManager * @param \OC\Hooks\PublicEmitter $emitter */ @@ -136,7 +136,7 @@ class Group implements IGroup { $this->emitter->emit('\OC\Group', 'preAddUser', array($this, $user)); } foreach ($this->backends as $backend) { - if ($backend->implementsActions(\OC_Group_Backend::ADD_TO_GROUP)) { + if ($backend->implementsActions(\OC\Group\Backend::ADD_TO_GROUP)) { $backend->addToGroup($user->getUID(), $this->gid); if ($this->users) { $this->users[$user->getUID()] = $user; @@ -160,7 +160,7 @@ class Group implements IGroup { $this->emitter->emit('\OC\Group', 'preRemoveUser', array($this, $user)); } foreach ($this->backends as $backend) { - if ($backend->implementsActions(\OC_Group_Backend::REMOVE_FROM_GOUP) and $backend->inGroup($user->getUID(), $this->gid)) { + if ($backend->implementsActions(\OC\Group\Backend::REMOVE_FROM_GOUP) and $backend->inGroup($user->getUID(), $this->gid)) { $backend->removeFromGroup($user->getUID(), $this->gid); $result = true; } @@ -209,7 +209,7 @@ class Group implements IGroup { public function count($search = '') { $users = false; foreach ($this->backends as $backend) { - if($backend->implementsActions(\OC_Group_Backend::COUNT_USERS)) { + if($backend->implementsActions(\OC\Group\Backend::COUNT_USERS)) { if($users === false) { //we could directly add to a bool variable, but this would //be ugly @@ -257,7 +257,7 @@ class Group implements IGroup { $this->emitter->emit('\OC\Group', 'preDelete', array($this)); } foreach ($this->backends as $backend) { - if ($backend->implementsActions(\OC_Group_Backend::DELETE_GROUP)) { + if ($backend->implementsActions(\OC\Group\Backend::DELETE_GROUP)) { $result = true; $backend->deleteGroup($this->gid); } diff --git a/lib/private/Group/Manager.php b/lib/private/Group/Manager.php index e82a1d4f2e6..22367180edd 100644 --- a/lib/private/Group/Manager.php +++ b/lib/private/Group/Manager.php @@ -190,7 +190,7 @@ class Manager extends PublicEmitter implements IGroupManager { } else { $this->emit('\OC\Group', 'preCreate', array($gid)); foreach ($this->backends as $backend) { - if ($backend->implementsActions(\OC_Group_Backend::CREATE_GROUP)) { + if ($backend->implementsActions(\OC\Group\Backend::CREATE_GROUP)) { $backend->createGroup($gid); $group = $this->getGroupObject($gid); $this->emit('\OC\Group', 'postCreate', array($group)); diff --git a/lib/private/legacy/group.php b/lib/private/legacy/group.php index f1b84069a38..ceb99389942 100644 --- a/lib/private/legacy/group.php +++ b/lib/private/legacy/group.php @@ -66,7 +66,7 @@ class OC_Group { /** * set the group backend - * @param \OC_Group_Backend $backend The backend to use for user management + * @param \OC\Group\Backend $backend The backend to use for user management * @return bool */ public static function useBackend($backend) { diff --git a/lib/private/legacy/group/backend.php b/lib/private/legacy/group/backend.php index 3d8d71b1529..a5df9c339b9 100644 --- a/lib/private/legacy/group/backend.php +++ b/lib/private/legacy/group/backend.php @@ -53,117 +53,7 @@ define('OC_GROUP_BACKEND_COUNT_USERS', 0x00100000); /** * Abstract base class for user management + * @deprecated Since 9.1.0 use \OC\Group\Backend */ -abstract class OC_Group_Backend implements \OCP\GroupInterface { - /** - * error code for functions not provided by the group backend - */ - const NOT_IMPLEMENTED = -501; - - /** - * actions that user backends can define - */ - const CREATE_GROUP = 0x00000001; - const DELETE_GROUP = 0x00000010; - const ADD_TO_GROUP = 0x00000100; - const REMOVE_FROM_GOUP = 0x00001000; - //OBSOLETE const GET_DISPLAYNAME = 0x00010000; - const COUNT_USERS = 0x00100000; - - protected $possibleActions = array( - self::CREATE_GROUP => 'createGroup', - self::DELETE_GROUP => 'deleteGroup', - self::ADD_TO_GROUP => 'addToGroup', - self::REMOVE_FROM_GOUP => 'removeFromGroup', - self::COUNT_USERS => 'countUsersInGroup', - ); - - /** - * Get all supported actions - * @return int bitwise-or'ed actions - * - * Returns the supported actions as int to be - * compared with \OC_Group_Backend::CREATE_GROUP etc. - */ - public function getSupportedActions() { - $actions = 0; - foreach($this->possibleActions AS $action => $methodName) { - if(method_exists($this, $methodName)) { - $actions |= $action; - } - } - - return $actions; - } - - /** - * Check if backend implements actions - * @param int $actions bitwise-or'ed actions - * @return bool - * - * Returns the supported actions as int to be - * compared with \OC_Group_Backend::CREATE_GROUP etc. - */ - public function implementsActions($actions) { - return (bool)($this->getSupportedActions() & $actions); - } - - /** - * is user in group? - * @param string $uid uid of the user - * @param string $gid gid of the group - * @return bool - * - * Checks whether the user is member of a group or not. - */ - public function inGroup($uid, $gid) { - return in_array($gid, $this->getUserGroups($uid)); - } - - /** - * Get all groups a user belongs to - * @param string $uid Name of the user - * @return array an array of group names - * - * This function fetches all groups a user belongs to. It does not check - * if the user exists at all. - */ - public function getUserGroups($uid) { - return array(); - } - - /** - * get a list of all groups - * @param string $search - * @param int $limit - * @param int $offset - * @return array an array of group names - * - * Returns a list with all groups - */ - - public function getGroups($search = '', $limit = -1, $offset = 0) { - return array(); - } - - /** - * check if a group exists - * @param string $gid - * @return bool - */ - public function groupExists($gid) { - return in_array($gid, $this->getGroups($gid, 1)); - } - - /** - * get a list of all users in a group - * @param string $gid - * @param string $search - * @param int $limit - * @param int $offset - * @return array an array of user ids - */ - public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { - return array(); - } +abstract class OC_Group_Backend extends \OC\Group\Backend { } diff --git a/lib/private/legacy/group/database.php b/lib/private/legacy/group/database.php index 9ea0bbb8242..3969b3681fe 100644 --- a/lib/private/legacy/group/database.php +++ b/lib/private/legacy/group/database.php @@ -1,17 +1,8 @@ - * @author Bart Visscher * @author Jakob Sack - * @author Joas Schilling - * @author Jörn Friedrich Dreyer - * @author Michael Gapczynski - * @author michag86 * @author Morris Jobke - * @author Robin Appelman - * @author Robin McCorkell * @author Roeland Jago Douma - * @author Thomas Müller * * @copyright Copyright (c) 2016, ownCloud, Inc. * @license AGPL-3.0 @@ -29,308 +20,11 @@ * along with this program. If not, see * */ -/* - * - * The following SQL statement is just a help for developers and will not be - * executed! - * - * CREATE TABLE `groups` ( - * `gid` varchar(64) COLLATE utf8_unicode_ci NOT NULL, - * PRIMARY KEY (`gid`) - * ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; - * - * CREATE TABLE `group_user` ( - * `gid` varchar(64) COLLATE utf8_unicode_ci NOT NULL, - * `uid` varchar(64) COLLATE utf8_unicode_ci NOT NULL - * ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; - * - */ /** - * Class for group management in a SQL Database (e.g. MySQL, SQLite) + * Class OC_Group_Database + * @deprecated Since 9.1.0 use \OC\Group\Database */ -class OC_Group_Database extends OC_Group_Backend { - - /** @var string[] */ - private $groupCache = []; - - /** @var \OCP\IDBConnection */ - private $dbConn; - - /** - * OC_Group_Database constructor. - * - * @param \OCP\IDBConnection|null $dbConn - */ - public function __construct(\OCP\IDBConnection $dbConn = null) { - $this->dbConn = $dbConn; - } - - /** - * FIXME: This function should not be required! - */ - private function fixDI() { - if ($this->dbConn === null) { - $this->dbConn = \OC::$server->getDatabaseConnection(); - } - } - - /** - * Try to create a new group - * @param string $gid The name of the group to create - * @return bool - * - * Tries to create a new group. If the group name already exists, false will - * be returned. - */ - public function createGroup( $gid ) { - $this->fixDI(); - - // Add group - $result = $this->dbConn->insertIfNotExist('*PREFIX*groups', [ - 'gid' => $gid, - ]); - - // Add to cache - $this->groupCache[$gid] = $gid; - - return $result === 1; - } - - /** - * delete a group - * @param string $gid gid of the group to delete - * @return bool - * - * Deletes a group and removes it from the group_user-table - */ - public function deleteGroup( $gid ) { - $this->fixDI(); - - // Delete the group - $qb = $this->dbConn->getQueryBuilder(); - $qb->delete('groups') - ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) - ->execute(); - - // Delete the group-user relation - $qb = $this->dbConn->getQueryBuilder(); - $qb->delete('group_user') - ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) - ->execute(); - - // Delete the group-groupadmin relation - $qb = $this->dbConn->getQueryBuilder(); - $qb->delete('group_admin') - ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) - ->execute(); - - // Delete from cache - unset($this->groupCache[$gid]); - - return true; - } - - /** - * is user in group? - * @param string $uid uid of the user - * @param string $gid gid of the group - * @return bool - * - * Checks whether the user is member of a group or not. - */ - public function inGroup( $uid, $gid ) { - $this->fixDI(); - - // check - $qb = $this->dbConn->getQueryBuilder(); - $cursor = $qb->select('uid') - ->from('group_user') - ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) - ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) - ->execute(); - - $result = $cursor->fetch(); - $cursor->closeCursor(); - - return $result ? true : false; - } - - /** - * Add a user to a group - * @param string $uid Name of the user to add to group - * @param string $gid Name of the group in which add the user - * @return bool - * - * Adds a user to a group. - */ - public function addToGroup( $uid, $gid ) { - $this->fixDI(); - - // No duplicate entries! - if( !$this->inGroup( $uid, $gid )) { - $qb = $this->dbConn->getQueryBuilder(); - $qb->insert('group_user') - ->setValue('uid', $qb->createNamedParameter($uid)) - ->setValue('gid', $qb->createNamedParameter($gid)) - ->execute(); - return true; - }else{ - return false; - } - } - - /** - * Removes a user from a group - * @param string $uid Name of the user to remove from group - * @param string $gid Name of the group from which remove the user - * @return bool - * - * removes the user from a group. - */ - public function removeFromGroup( $uid, $gid ) { - $this->fixDI(); - - $qb = $this->dbConn->getQueryBuilder(); - $qb->delete('group_user') - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) - ->andWhere($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) - ->execute(); - - return true; - } - - /** - * Get all groups a user belongs to - * @param string $uid Name of the user - * @return array an array of group names - * - * This function fetches all groups a user belongs to. It does not check - * if the user exists at all. - */ - public function getUserGroups( $uid ) { - $this->fixDI(); - - // No magic! - $qb = $this->dbConn->getQueryBuilder(); - $cursor = $qb->select('gid') - ->from('group_user') - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) - ->execute(); - - $groups = []; - while( $row = $cursor->fetch()) { - $groups[] = $row["gid"]; - $this->groupCache[$row['gid']] = $row['gid']; - } - $cursor->closeCursor(); - - return $groups; - } - - /** - * get a list of all groups - * @param string $search - * @param int $limit - * @param int $offset - * @return array an array of group names - * - * Returns a list with all groups - */ - public function getGroups($search = '', $limit = null, $offset = null) { - $parameters = []; - $searchLike = ''; - if ($search !== '') { - $parameters[] = '%' . $search . '%'; - $searchLike = ' WHERE LOWER(`gid`) LIKE LOWER(?)'; - } - - $stmt = OC_DB::prepare('SELECT `gid` FROM `*PREFIX*groups`' . $searchLike . ' ORDER BY `gid` ASC', $limit, $offset); - $result = $stmt->execute($parameters); - $groups = array(); - while ($row = $result->fetchRow()) { - $groups[] = $row['gid']; - } - return $groups; - } - - /** - * check if a group exists - * @param string $gid - * @return bool - */ - public function groupExists($gid) { - $this->fixDI(); - - // Check cache first - if (isset($this->groupCache[$gid])) { - return true; - } - - $qb = $this->dbConn->getQueryBuilder(); - $cursor = $qb->select('gid') - ->from('groups') - ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) - ->execute(); - $result = $cursor->fetch(); - $cursor->closeCursor(); - - if ($result !== false) { - $this->groupCache[$gid] = $gid; - return true; - } - return false; - } - - /** - * get a list of all users in a group - * @param string $gid - * @param string $search - * @param int $limit - * @param int $offset - * @return array an array of user ids - */ - public function usersInGroup($gid, $search = '', $limit = null, $offset = null) { - $parameters = [$gid]; - $searchLike = ''; - if ($search !== '') { - $parameters[] = '%' . $search . '%'; - $searchLike = ' AND `uid` LIKE ?'; - } - - $stmt = OC_DB::prepare('SELECT `uid` FROM `*PREFIX*group_user` WHERE `gid` = ?' . $searchLike . ' ORDER BY `uid` ASC', - $limit, - $offset); - $result = $stmt->execute($parameters); - $users = array(); - while ($row = $result->fetchRow()) { - $users[] = $row['uid']; - } - return $users; - } - - /** - * get the number of all users matching the search string in a group - * @param string $gid - * @param string $search - * @return int|false - * @throws \OC\DatabaseException - */ - public function countUsersInGroup($gid, $search = '') { - $parameters = [$gid]; - $searchLike = ''; - if ($search !== '') { - $parameters[] = '%' . $search . '%'; - $searchLike = ' AND `uid` LIKE ?'; - } - - $stmt = OC_DB::prepare('SELECT COUNT(`uid`) AS `count` FROM `*PREFIX*group_user` WHERE `gid` = ?' . $searchLike); - $result = $stmt->execute($parameters); - $count = $result->fetchOne(); - if($count !== false) { - $count = intval($count); - } - return $count; - } - -} +class OC_Group_Database extends \OC\Group\Database { + +} \ No newline at end of file diff --git a/tests/lib/group/backend.php b/tests/lib/group/backend.php index 238b83de5d7..3b06a3eb3a9 100644 --- a/tests/lib/group/backend.php +++ b/tests/lib/group/backend.php @@ -31,7 +31,7 @@ */ abstract class Test_Group_Backend extends \Test\TestCase { /** - * @var OC_Group_Backend $backend + * @var \OC\Group\Backend $backend */ protected $backend; diff --git a/tests/lib/group/database.php b/tests/lib/group/database.php index b0be5774c7d..aae9f8bf1de 100644 --- a/tests/lib/group/database.php +++ b/tests/lib/group/database.php @@ -45,7 +45,7 @@ class Test_Group_Database extends Test_Group_Backend { protected function setUp() { parent::setUp(); - $this->backend = new OC_Group_Database(); + $this->backend = new \OC\Group\Database(); } protected function tearDown() { @@ -60,7 +60,7 @@ class Test_Group_Database extends Test_Group_Backend { $this->backend->createGroup($group); - $backend = new OC_Group_Database(); + $backend = new \OC\Group\Database(); $this->assertFalse($backend->createGroup($group)); } } diff --git a/tests/lib/group/group.php b/tests/lib/group/group.php index d758e5959d0..bf834ab2348 100644 --- a/tests/lib/group/group.php +++ b/tests/lib/group/group.php @@ -32,7 +32,7 @@ class Group extends \Test\TestCase { } public function testGetUsersSingleBackend() { - $backend = $this->getMock('OC_Group_Database'); + $backend = $this->getMock('OC\Group\Database'); $userManager = $this->getUserManager(); $group = new \OC\Group\Group('group1', array($backend), $userManager); @@ -51,8 +51,8 @@ class Group extends \Test\TestCase { } public function testGetUsersMultipleBackends() { - $backend1 = $this->getMock('OC_Group_Database'); - $backend2 = $this->getMock('OC_Group_Database'); + $backend1 = $this->getMock('OC\Group\Database'); + $backend2 = $this->getMock('OC\Group\Database'); $userManager = $this->getUserManager(); $group = new \OC\Group\Group('group1', array($backend1, $backend2), $userManager); @@ -78,7 +78,7 @@ class Group extends \Test\TestCase { } public function testInGroupSingleBackend() { - $backend = $this->getMock('OC_Group_Database'); + $backend = $this->getMock('OC\Group\Database'); $userManager = $this->getUserManager(); $userBackend = $this->getMock('\OC_User_Backend'); $group = new \OC\Group\Group('group1', array($backend), $userManager); @@ -92,8 +92,8 @@ class Group extends \Test\TestCase { } public function testInGroupMultipleBackends() { - $backend1 = $this->getMock('OC_Group_Database'); - $backend2 = $this->getMock('OC_Group_Database'); + $backend1 = $this->getMock('OC\Group\Database'); + $backend2 = $this->getMock('OC\Group\Database'); $userManager = $this->getUserManager(); $userBackend = $this->getMock('\OC_User_Backend'); $group = new \OC\Group\Group('group1', array($backend1, $backend2), $userManager); @@ -112,7 +112,7 @@ class Group extends \Test\TestCase { } public function testAddUser() { - $backend = $this->getMock('OC_Group_Database'); + $backend = $this->getMock('OC\Group\Database'); $userManager = $this->getUserManager(); $userBackend = $this->getMock('\OC_User_Backend'); $group = new \OC\Group\Group('group1', array($backend), $userManager); @@ -133,7 +133,7 @@ class Group extends \Test\TestCase { } public function testAddUserAlreadyInGroup() { - $backend = $this->getMock('OC_Group_Database'); + $backend = $this->getMock('OC\Group\Database'); $userManager = $this->getUserManager(); $userBackend = $this->getMock('\OC_User_Backend'); $group = new \OC\Group\Group('group1', array($backend), $userManager); @@ -153,7 +153,7 @@ class Group extends \Test\TestCase { } public function testRemoveUser() { - $backend = $this->getMock('OC_Group_Database'); + $backend = $this->getMock('OC\Group\Database'); $userManager = $this->getUserManager(); $userBackend = $this->getMock('\OC_User_Backend'); $group = new \OC\Group\Group('group1', array($backend), $userManager); @@ -174,7 +174,7 @@ class Group extends \Test\TestCase { } public function testRemoveUserNotInGroup() { - $backend = $this->getMock('OC_Group_Database'); + $backend = $this->getMock('OC\Group\Database'); $userManager = $this->getUserManager(); $userBackend = $this->getMock('\OC_User_Backend'); $group = new \OC\Group\Group('group1', array($backend), $userManager); @@ -194,8 +194,8 @@ class Group extends \Test\TestCase { } public function testRemoveUserMultipleBackends() { - $backend1 = $this->getMock('OC_Group_Database'); - $backend2 = $this->getMock('OC_Group_Database'); + $backend1 = $this->getMock('OC\Group\Database'); + $backend2 = $this->getMock('OC\Group\Database'); $userManager = $this->getUserManager(); $userBackend = $this->getMock('\OC_User_Backend'); $group = new \OC\Group\Group('group1', array($backend1, $backend2), $userManager); @@ -228,7 +228,7 @@ class Group extends \Test\TestCase { } public function testSearchUsers() { - $backend = $this->getMock('OC_Group_Database'); + $backend = $this->getMock('OC\Group\Database'); $userManager = $this->getUserManager(); $group = new \OC\Group\Group('group1', array($backend), $userManager); @@ -245,8 +245,8 @@ class Group extends \Test\TestCase { } public function testSearchUsersMultipleBackends() { - $backend1 = $this->getMock('OC_Group_Database'); - $backend2 = $this->getMock('OC_Group_Database'); + $backend1 = $this->getMock('OC\Group\Database'); + $backend2 = $this->getMock('OC\Group\Database'); $userManager = $this->getUserManager(); $group = new \OC\Group\Group('group1', array($backend1, $backend2), $userManager); @@ -267,7 +267,7 @@ class Group extends \Test\TestCase { } public function testSearchUsersLimitAndOffset() { - $backend = $this->getMock('OC_Group_Database'); + $backend = $this->getMock('OC\Group\Database'); $userManager = $this->getUserManager(); $group = new \OC\Group\Group('group1', array($backend), $userManager); @@ -284,8 +284,8 @@ class Group extends \Test\TestCase { } public function testSearchUsersMultipleBackendsLimitAndOffset() { - $backend1 = $this->getMock('OC_Group_Database'); - $backend2 = $this->getMock('OC_Group_Database'); + $backend1 = $this->getMock('OC\Group\Database'); + $backend2 = $this->getMock('OC\Group\Database'); $userManager = $this->getUserManager(); $group = new \OC\Group\Group('group1', array($backend1, $backend2), $userManager); @@ -308,7 +308,7 @@ class Group extends \Test\TestCase { } public function testCountUsers() { - $backend1 = $this->getMock('OC_Group_Database'); + $backend1 = $this->getMock('OC\Group\Database'); $userManager = $this->getUserManager(); $group = new \OC\Group\Group('group1', array($backend1), $userManager); @@ -327,8 +327,8 @@ class Group extends \Test\TestCase { } public function testCountUsersMultipleBackends() { - $backend1 = $this->getMock('OC_Group_Database'); - $backend2 = $this->getMock('OC_Group_Database'); + $backend1 = $this->getMock('OC\Group\Database'); + $backend2 = $this->getMock('OC\Group\Database'); $userManager = $this->getUserManager(); $group = new \OC\Group\Group('group1', array($backend1, $backend2), $userManager); @@ -354,7 +354,7 @@ class Group extends \Test\TestCase { } public function testCountUsersNoMethod() { - $backend1 = $this->getMock('OC_Group_Database'); + $backend1 = $this->getMock('OC\Group\Database'); $userManager = $this->getUserManager(); $group = new \OC\Group\Group('group1', array($backend1), $userManager); @@ -370,7 +370,7 @@ class Group extends \Test\TestCase { } public function testDelete() { - $backend = $this->getMock('OC_Group_Database'); + $backend = $this->getMock('OC\Group\Database'); $userManager = $this->getUserManager(); $group = new \OC\Group\Group('group1', array($backend), $userManager); diff --git a/tests/lib/group/manager.php b/tests/lib/group/manager.php index 410e11114c4..751f0d0ebd5 100644 --- a/tests/lib/group/manager.php +++ b/tests/lib/group/manager.php @@ -14,9 +14,9 @@ use OC\User\User; class Manager extends \Test\TestCase { public function testGet() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMock('\OC_Group_Database'); + $backend = $this->getMock('\OC\Group\Database'); $backend->expects($this->any()) ->method('groupExists') ->with('group1') @@ -46,9 +46,9 @@ class Manager extends \Test\TestCase { public function testGetNotExists() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMock('\OC_Group_Database'); + $backend = $this->getMock('\OC\Group\Database'); $backend->expects($this->once()) ->method('groupExists') ->with('group1') @@ -82,18 +82,18 @@ class Manager extends \Test\TestCase { public function testGetMultipleBackends() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1 + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1 */ - $backend1 = $this->getMock('\OC_Group_Database'); + $backend1 = $this->getMock('\OC\Group\Database'); $backend1->expects($this->any()) ->method('groupExists') ->with('group1') ->will($this->returnValue(false)); /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2 + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend2 */ - $backend2 = $this->getMock('\OC_Group_Database'); + $backend2 = $this->getMock('\OC\Group\Database'); $backend2->expects($this->any()) ->method('groupExists') ->with('group1') @@ -114,10 +114,10 @@ class Manager extends \Test\TestCase { public function testCreate() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ $backendGroupCreated = false; - $backend = $this->getMock('\OC_Group_Database'); + $backend = $this->getMock('\OC\Group\Database'); $backend->expects($this->any()) ->method('groupExists') ->with('group1') @@ -146,9 +146,9 @@ class Manager extends \Test\TestCase { public function testCreateExists() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMock('\OC_Group_Database'); + $backend = $this->getMock('\OC\Group\Database'); $backend->expects($this->any()) ->method('groupExists') ->with('group1') @@ -169,9 +169,9 @@ class Manager extends \Test\TestCase { public function testSearch() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMock('\OC_Group_Database'); + $backend = $this->getMock('\OC\Group\Database'); $backend->expects($this->once()) ->method('getGroups') ->with('1') @@ -196,9 +196,9 @@ class Manager extends \Test\TestCase { public function testSearchMultipleBackends() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1 + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1 */ - $backend1 = $this->getMock('\OC_Group_Database'); + $backend1 = $this->getMock('\OC\Group\Database'); $backend1->expects($this->once()) ->method('getGroups') ->with('1') @@ -208,9 +208,9 @@ class Manager extends \Test\TestCase { ->will($this->returnValue(true)); /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2 + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend2 */ - $backend2 = $this->getMock('\OC_Group_Database'); + $backend2 = $this->getMock('\OC\Group\Database'); $backend2->expects($this->once()) ->method('getGroups') ->with('1') @@ -237,9 +237,9 @@ class Manager extends \Test\TestCase { public function testSearchMultipleBackendsLimitAndOffset() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1 + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1 */ - $backend1 = $this->getMock('\OC_Group_Database'); + $backend1 = $this->getMock('\OC\Group\Database'); $backend1->expects($this->once()) ->method('getGroups') ->with('1', 2, 1) @@ -249,9 +249,9 @@ class Manager extends \Test\TestCase { ->will($this->returnValue(true)); /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2 + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend2 */ - $backend2 = $this->getMock('\OC_Group_Database'); + $backend2 = $this->getMock('\OC\Group\Database'); $backend2->expects($this->once()) ->method('getGroups') ->with('1', 2, 1) @@ -278,9 +278,9 @@ class Manager extends \Test\TestCase { public function testGetUserGroups() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMock('\OC_Group_Database'); + $backend = $this->getMock('\OC\Group\Database'); $backend->expects($this->once()) ->method('getUserGroups') ->with('user1') @@ -332,9 +332,9 @@ class Manager extends \Test\TestCase { public function testInGroup() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMock('\OC_Group_Database'); + $backend = $this->getMock('\OC\Group\Database'); $backend->expects($this->once()) ->method('getUserGroups') ->with('user1') @@ -356,9 +356,9 @@ class Manager extends \Test\TestCase { public function testIsAdmin() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMock('\OC_Group_Database'); + $backend = $this->getMock('\OC\Group\Database'); $backend->expects($this->once()) ->method('getUserGroups') ->with('user1') @@ -380,9 +380,9 @@ class Manager extends \Test\TestCase { public function testNotAdmin() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMock('\OC_Group_Database'); + $backend = $this->getMock('\OC\Group\Database'); $backend->expects($this->once()) ->method('getUserGroups') ->with('user1') @@ -404,9 +404,9 @@ class Manager extends \Test\TestCase { public function testGetUserGroupsMultipleBackends() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1 + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1 */ - $backend1 = $this->getMock('\OC_Group_Database'); + $backend1 = $this->getMock('\OC\Group\Database'); $backend1->expects($this->once()) ->method('getUserGroups') ->with('user1') @@ -416,9 +416,9 @@ class Manager extends \Test\TestCase { ->will($this->returnValue(true)); /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend2 + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend2 */ - $backend2 = $this->getMock('\OC_Group_Database'); + $backend2 = $this->getMock('\OC\Group\Database'); $backend2->expects($this->once()) ->method('getUserGroups') ->with('user1') @@ -446,9 +446,9 @@ class Manager extends \Test\TestCase { public function testDisplayNamesInGroupWithOneUserBackend() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1 + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1 */ - $backend = $this->getMock('\OC_Group_Database'); + $backend = $this->getMock('\OC\Group\Database'); $backend->expects($this->exactly(1)) ->method('groupExists') ->with('testgroup') @@ -510,9 +510,9 @@ class Manager extends \Test\TestCase { public function testDisplayNamesInGroupWithOneUserBackendWithLimitSpecified() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1 + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1 */ - $backend = $this->getMock('\OC_Group_Database'); + $backend = $this->getMock('\OC\Group\Database'); $backend->expects($this->exactly(1)) ->method('groupExists') ->with('testgroup') @@ -577,9 +577,9 @@ class Manager extends \Test\TestCase { public function testDisplayNamesInGroupWithOneUserBackendWithLimitAndOffsetSpecified() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1 + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1 */ - $backend = $this->getMock('\OC_Group_Database'); + $backend = $this->getMock('\OC\Group\Database'); $backend->expects($this->exactly(1)) ->method('groupExists') ->with('testgroup') @@ -647,9 +647,9 @@ class Manager extends \Test\TestCase { public function testDisplayNamesInGroupWithOneUserBackendAndSearchEmpty() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1 + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1 */ - $backend = $this->getMock('\OC_Group_Database'); + $backend = $this->getMock('\OC\Group\Database'); $backend->expects($this->exactly(1)) ->method('groupExists') ->with('testgroup') @@ -692,9 +692,9 @@ class Manager extends \Test\TestCase { public function testDisplayNamesInGroupWithOneUserBackendAndSearchEmptyAndLimitSpecified() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1 + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1 */ - $backend = $this->getMock('\OC_Group_Database'); + $backend = $this->getMock('\OC\Group\Database'); $backend->expects($this->exactly(1)) ->method('groupExists') ->with('testgroup') @@ -736,9 +736,9 @@ class Manager extends \Test\TestCase { public function testDisplayNamesInGroupWithOneUserBackendAndSearchEmptyAndLimitAndOffsetSpecified() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1 + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend1 */ - $backend = $this->getMock('\OC_Group_Database'); + $backend = $this->getMock('\OC\Group\Database'); $backend->expects($this->exactly(1)) ->method('groupExists') ->with('testgroup') @@ -781,9 +781,9 @@ class Manager extends \Test\TestCase { public function testGetUserGroupsWithAddUser() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMock('\OC_Group_Database'); + $backend = $this->getMock('\OC\Group\Database'); $expectedGroups = array(); $backend->expects($this->any()) ->method('getUserGroups') @@ -825,9 +825,9 @@ class Manager extends \Test\TestCase { public function testGetUserGroupsWithRemoveUser() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMock('\OC_Group_Database'); + $backend = $this->getMock('\OC\Group\Database'); $expectedGroups = array('group1'); $backend->expects($this->any()) ->method('getUserGroups') @@ -875,9 +875,9 @@ class Manager extends \Test\TestCase { public function testGetUserIdGroups() { /** - * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + * @var \PHPUnit_Framework_MockObject_MockObject | \OC\Group\Backend $backend */ - $backend = $this->getMock('\OC_Group_Database'); + $backend = $this->getMock('\OC\Group\Database'); $backend->expects($this->any()) ->method('getUserGroups') ->with('user1') diff --git a/tests/lib/util/group/dummy.php b/tests/lib/util/group/dummy.php index e72be827d8a..8f06316ca03 100644 --- a/tests/lib/util/group/dummy.php +++ b/tests/lib/util/group/dummy.php @@ -29,12 +29,12 @@ namespace Test\Util\Group; -use OC_Group_Backend; +use OC\Group\Backend; /** * dummy group backend, does not keep state, only for testing use */ -class Dummy extends OC_Group_Backend { +class Dummy extends Backend { private $groups=array(); /** * Try to create a new group