diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/group/manager.php | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/lib/group/manager.php b/tests/lib/group/manager.php index f72ea8e912f..e3462caf806 100644 --- a/tests/lib/group/manager.php +++ b/tests/lib/group/manager.php @@ -304,6 +304,78 @@ class Manager extends \Test\TestCase { $this->assertEquals('group1', $group1->getGID()); } + public function testInGroup() { + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + */ + $backend = $this->getMock('\OC_Group_Database'); + $backend->expects($this->once()) + ->method('getUserGroups') + ->with('user1') + ->will($this->returnValue(array('group1', 'admin', 'group2'))); + $backend->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); + + /** + * @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); + + $this->assertTrue($manager->isInGroup('user1', 'group1')); + } + + public function testIsAdmin() { + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + */ + $backend = $this->getMock('\OC_Group_Database'); + $backend->expects($this->once()) + ->method('getUserGroups') + ->with('user1') + ->will($this->returnValue(array('group1', 'admin', 'group2'))); + $backend->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); + + /** + * @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); + + $this->assertTrue($manager->isAdmin('user1')); + } + + public function testNotAdmin() { + /** + * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend + */ + $backend = $this->getMock('\OC_Group_Database'); + $backend->expects($this->once()) + ->method('getUserGroups') + ->with('user1') + ->will($this->returnValue(array('group1', 'group2'))); + $backend->expects($this->any()) + ->method('groupExists') + ->will($this->returnValue(true)); + + /** + * @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); + + $this->assertFalse($manager->isAdmin('user1')); + } + public function testGetUserGroupsMultipleBackends() { /** * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend1 |