summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2014-02-27 21:04:44 +0100
committerBart Visscher <bartv@thisnet.nl>2014-02-27 21:04:44 +0100
commit3116bede68b07efc3a3bc6c991edf191c918565b (patch)
treeb221b68197ef4cad28191c6d8bbee44b0864ec6a /tests
parentcb37a2716a75013dd79f8830a6d074e5afebb767 (diff)
downloadnextcloud-server-3116bede68b07efc3a3bc6c991edf191c918565b.tar.gz
nextcloud-server-3116bede68b07efc3a3bc6c991edf191c918565b.zip
Add unit tests for getUserGroups with addUser and removeUser
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/group/manager.php94
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/lib/group/manager.php b/tests/lib/group/manager.php
index 90f0e1b35e2..c39a7d6f33a 100644
--- a/tests/lib/group/manager.php
+++ b/tests/lib/group/manager.php
@@ -343,4 +343,98 @@ class Manager extends \PHPUnit_Framework_TestCase {
$this->assertEquals('group1', $group1->getGID());
$this->assertEquals('group2', $group2->getGID());
}
+
+ public function testGetUserGroupsWithAddUser() {
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend
+ */
+ $backend = $this->getMock('\OC_Group_Database');
+ $expectedGroups = array();
+ $backend->expects($this->any())
+ ->method('getUserGroups')
+ ->with('user1')
+ ->will($this->returnCallback(function () use (&$expectedGroups) {
+ return $expectedGroups;
+ }));
+ $backend->expects($this->any())
+ ->method('groupExists')
+ ->with('group1')
+ ->will($this->returnValue(true));
+ $backend->expects($this->once())
+ ->method('implementsActions')
+ ->will($this->returnValue(true));
+
+ /**
+ * @var \OC\User\Manager $userManager
+ */
+ $userManager = $this->getMock('\OC\User\Manager');
+ $manager = new \OC\Group\Manager($userManager);
+ $manager->addBackend($backend);
+
+ // prime cache
+ $user1 = new User('user1', null);
+ $groups = $manager->getUserGroups($user1);
+ $this->assertEquals(array(), $groups);
+
+ // add user
+ $group = $manager->get('group1');
+ $group->addUser($user1);
+ $expectedGroups = array('group1');
+
+ // check result
+ $groups = $manager->getUserGroups($user1);
+ $this->assertEquals(1, count($groups));
+ $group1 = $groups[0];
+ $this->assertEquals('group1', $group1->getGID());
+ }
+
+ public function testGetUserGroupsWithRemoveUser() {
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject | \OC_Group_Backend $backend
+ */
+ $backend = $this->getMock('\OC_Group_Database');
+ $expectedGroups = array('group1');
+ $backend->expects($this->any())
+ ->method('getUserGroups')
+ ->with('user1')
+ ->will($this->returnCallback(function () use (&$expectedGroups) {
+ return $expectedGroups;
+ }));
+ $backend->expects($this->any())
+ ->method('groupExists')
+ ->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())
+ ->method('removeFromGroup')
+ ->will($this->returnValue(true));
+
+ /**
+ * @var \OC\User\Manager $userManager
+ */
+ $userManager = $this->getMock('\OC\User\Manager');
+ $manager = new \OC\Group\Manager($userManager);
+ $manager->addBackend($backend);
+
+ // prime cache
+ $user1 = new User('user1', null);
+ $groups = $manager->getUserGroups($user1);
+ $this->assertEquals(1, count($groups));
+ $group1 = $groups[0];
+ $this->assertEquals('group1', $group1->getGID());
+
+ // remove user
+ $group = $manager->get('group1');
+ $group->removeUser($user1);
+ $expectedGroups = array();
+
+ // check result
+ $groups = $manager->getUserGroups($user1);
+ $this->assertEquals(array(), $groups);
+ }
}