aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2014-05-19 01:21:37 +0200
committerMorris Jobke <hey@morrisjobke.de>2014-05-19 01:21:37 +0200
commit804020bb6d7822a7010c3b8f95c25c2521b09a45 (patch)
treed8d0ec22414b17358d98a6665a5977e332aa7f18 /tests/lib
parentdb9cfaa56dfaedf628755a7678249d24ad9f1ea5 (diff)
parentf569c721a64486d0e7c7e307ed77ac0caed2dc2d (diff)
downloadnextcloud-server-804020bb6d7822a7010c3b8f95c25c2521b09a45.tar.gz
nextcloud-server-804020bb6d7822a7010c3b8f95c25c2521b09a45.zip
Merge pull request #7363 from owncloud/optimize-startup-queries
Optimize some queries that are always executed when loading base.php
Diffstat (limited to 'tests/lib')
-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 061c9e7ea34..6799a598d42 100644
--- a/tests/lib/group/manager.php
+++ b/tests/lib/group/manager.php
@@ -398,4 +398,98 @@ class Manager extends \PHPUnit_Framework_TestCase {
$this->assertEquals(1, count($users));
$this->assertTrue(isset($users['user33']));
}
+
+ 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);
+ }
}