Fix Scrutinizer errors about missing user backend
This commit is contained in:
parent
8ab01599a9
commit
875a8acedf
|
@ -17,9 +17,10 @@ class Group extends \PHPUnit_Framework_TestCase {
|
|||
*/
|
||||
protected function getUserManager() {
|
||||
$userManager = $this->getMock('\OC\User\Manager');
|
||||
$user1 = new User('user1', null);
|
||||
$user2 = new User('user2', null);
|
||||
$user3 = new User('user3', null);
|
||||
$backend = $this->getMock('\OC_User_Backend');
|
||||
$user1 = new User('user1', $backend);
|
||||
$user2 = new User('user2', $backend);
|
||||
$user3 = new User('user3', $backend);
|
||||
$userManager->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValueMap(array(
|
||||
|
@ -79,6 +80,7 @@ class Group extends \PHPUnit_Framework_TestCase {
|
|||
public function testInGroupSingleBackend() {
|
||||
$backend = $this->getMock('OC_Group_Database');
|
||||
$userManager = $this->getUserManager();
|
||||
$userBackend = $this->getMock('\OC_User_Backend');
|
||||
$group = new \OC\Group\Group('group1', array($backend), $userManager);
|
||||
|
||||
$backend->expects($this->once())
|
||||
|
@ -86,13 +88,14 @@ class Group extends \PHPUnit_Framework_TestCase {
|
|||
->with('user1', 'group1')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->assertTrue($group->inGroup(new User('user1', null)));
|
||||
$this->assertTrue($group->inGroup(new User('user1', $userBackend)));
|
||||
}
|
||||
|
||||
public function testInGroupMultipleBackends() {
|
||||
$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);
|
||||
|
||||
$backend1->expects($this->once())
|
||||
|
@ -105,12 +108,13 @@ class Group extends \PHPUnit_Framework_TestCase {
|
|||
->with('user1', 'group1')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$this->assertTrue($group->inGroup(new User('user1', null)));
|
||||
$this->assertTrue($group->inGroup(new User('user1', $userBackend)));
|
||||
}
|
||||
|
||||
public function testAddUser() {
|
||||
$backend = $this->getMock('OC_Group_Database');
|
||||
$userManager = $this->getUserManager();
|
||||
$userBackend = $this->getMock('\OC_User_Backend');
|
||||
$group = new \OC\Group\Group('group1', array($backend), $userManager);
|
||||
|
||||
$backend->expects($this->once())
|
||||
|
@ -125,12 +129,13 @@ class Group extends \PHPUnit_Framework_TestCase {
|
|||
->method('addToGroup')
|
||||
->with('user1', 'group1');
|
||||
|
||||
$group->addUser(new User('user1', null));
|
||||
$group->addUser(new User('user1', $userBackend));
|
||||
}
|
||||
|
||||
public function testAddUserAlreadyInGroup() {
|
||||
$backend = $this->getMock('OC_Group_Database');
|
||||
$userManager = $this->getUserManager();
|
||||
$userBackend = $this->getMock('\OC_User_Backend');
|
||||
$group = new \OC\Group\Group('group1', array($backend), $userManager);
|
||||
|
||||
$backend->expects($this->once())
|
||||
|
@ -144,12 +149,13 @@ class Group extends \PHPUnit_Framework_TestCase {
|
|||
$backend->expects($this->never())
|
||||
->method('addToGroup');
|
||||
|
||||
$group->addUser(new User('user1', null));
|
||||
$group->addUser(new User('user1', $userBackend));
|
||||
}
|
||||
|
||||
public function testRemoveUser() {
|
||||
$backend = $this->getMock('OC_Group_Database');
|
||||
$userManager = $this->getUserManager();
|
||||
$userBackend = $this->getMock('\OC_User_Backend');
|
||||
$group = new \OC\Group\Group('group1', array($backend), $userManager);
|
||||
|
||||
$backend->expects($this->once())
|
||||
|
@ -164,12 +170,13 @@ class Group extends \PHPUnit_Framework_TestCase {
|
|||
->method('removeFromGroup')
|
||||
->with('user1', 'group1');
|
||||
|
||||
$group->removeUser(new User('user1', null));
|
||||
$group->removeUser(new User('user1', $userBackend));
|
||||
}
|
||||
|
||||
public function testRemoveUserNotInGroup() {
|
||||
$backend = $this->getMock('OC_Group_Database');
|
||||
$userManager = $this->getUserManager();
|
||||
$userBackend = $this->getMock('\OC_User_Backend');
|
||||
$group = new \OC\Group\Group('group1', array($backend), $userManager);
|
||||
|
||||
$backend->expects($this->once())
|
||||
|
@ -183,13 +190,14 @@ class Group extends \PHPUnit_Framework_TestCase {
|
|||
$backend->expects($this->never())
|
||||
->method('removeFromGroup');
|
||||
|
||||
$group->removeUser(new User('user1', null));
|
||||
$group->removeUser(new User('user1', $userBackend));
|
||||
}
|
||||
|
||||
public function testRemoveUserMultipleBackends() {
|
||||
$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);
|
||||
|
||||
$backend1->expects($this->once())
|
||||
|
@ -216,7 +224,7 @@ class Group extends \PHPUnit_Framework_TestCase {
|
|||
->method('removeFromGroup')
|
||||
->with('user1', 'group1');
|
||||
|
||||
$group->removeUser(new User('user1', null));
|
||||
$group->removeUser(new User('user1', $userBackend));
|
||||
}
|
||||
|
||||
public function testSearchUsers() {
|
||||
|
|
|
@ -294,10 +294,11 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
|||
* @var \OC\User\Manager $userManager
|
||||
*/
|
||||
$userManager = $this->getMock('\OC\User\Manager');
|
||||
$userBackend = $this->getMock('\OC_User_Backend');
|
||||
$manager = new \OC\Group\Manager($userManager);
|
||||
$manager->addBackend($backend);
|
||||
|
||||
$groups = $manager->getUserGroups(new User('user1', null));
|
||||
$groups = $manager->getUserGroups(new User('user1', $userBackend));
|
||||
$this->assertEquals(1, count($groups));
|
||||
$group1 = $groups[0];
|
||||
$this->assertEquals('group1', $group1->getGID());
|
||||
|
@ -332,11 +333,12 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
|||
* @var \OC\User\Manager $userManager
|
||||
*/
|
||||
$userManager = $this->getMock('\OC\User\Manager');
|
||||
$userBackend = $this->getMock('\OC_User_Backend');
|
||||
$manager = new \OC\Group\Manager($userManager);
|
||||
$manager->addBackend($backend1);
|
||||
$manager->addBackend($backend2);
|
||||
|
||||
$groups = $manager->getUserGroups(new User('user1', null));
|
||||
$groups = $manager->getUserGroups(new User('user1', $userBackend));
|
||||
$this->assertEquals(2, count($groups));
|
||||
$group1 = $groups[0];
|
||||
$group2 = $groups[1];
|
||||
|
@ -345,10 +347,12 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
|||
}
|
||||
|
||||
public function testDisplayNamesInGroupMultipleUserBackends() {
|
||||
$user1 = new User('user1', null);
|
||||
$user2 = new User('user2', null);
|
||||
$user3 = new User('user3', null);
|
||||
$user4 = new User('user33', null);
|
||||
$userBackend = $this->getMock('\OC_User_Backend');
|
||||
|
||||
$user1 = new User('user1', $userBackend);
|
||||
$user2 = new User('user2', $userBackend);
|
||||
$user3 = new User('user3', $userBackend);
|
||||
$user4 = new User('user33', $userBackend);
|
||||
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1
|
||||
|
@ -368,6 +372,7 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
|||
* @var \OC\User\Manager $userManager
|
||||
*/
|
||||
$userManager = $this->getMock('\OC\User\Manager');
|
||||
$userBackend = $this->getMock('\OC_User_Backend');
|
||||
$userManager->expects($this->once())
|
||||
->method('search')
|
||||
->with('user3')
|
||||
|
@ -375,12 +380,12 @@ class Manager extends \PHPUnit_Framework_TestCase {
|
|||
|
||||
$userManager->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnCallback(function($uid) {
|
||||
->will($this->returnCallback(function($uid) use ($userBackend) {
|
||||
switch($uid) {
|
||||
case 'user1' : return new User('user1', null);
|
||||
case 'user2' : return new User('user2', null);
|
||||
case 'user3' : return new User('user3', null);
|
||||
case 'user33': return new User('user33', null);
|
||||
case 'user1' : return new User('user1', $userBackend);
|
||||
case 'user2' : return new User('user2', $userBackend);
|
||||
case 'user3' : return new User('user3', $userBackend);
|
||||
case 'user33': return new User('user33', $userBackend);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue