diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-12-16 20:33:13 +0100 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-12-17 17:41:57 +0100 |
commit | 6779bf113d27eca305661c5da67f685ddf2147df (patch) | |
tree | cf483aac5891ce370441298b16be273bfe30be69 /tests | |
parent | 0f535e38665f21ee92d41d19a51adec4459614bc (diff) | |
download | nextcloud-server-6779bf113d27eca305661c5da67f685ddf2147df.tar.gz nextcloud-server-6779bf113d27eca305661c5da67f685ddf2147df.zip |
add isAdmin and isInGroup methods for the group manager
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 |