summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorblizzz <blizzz@owncloud.com>2014-01-08 10:41:39 -0800
committerblizzz <blizzz@owncloud.com>2014-01-08 10:41:39 -0800
commitd8b8abb429d3d66598a16d25cf55f7dc19e3f996 (patch)
tree085c9d1173d570f02fbf1bc88fb6ec27a674c42a /tests
parent0e7283ef39d7fe2e80585c190d8e1dc2cb511c96 (diff)
parent4585b4ea3f1fd21aabc167102e74a382dfa0cbd8 (diff)
downloadnextcloud-server-d8b8abb429d3d66598a16d25cf55f7dc19e3f996.tar.gz
nextcloud-server-d8b8abb429d3d66598a16d25cf55f7dc19e3f996.zip
Merge pull request #6681 from owncloud/userreport
add command line option to get user number statistics
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/user/manager.php72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/lib/user/manager.php b/tests/lib/user/manager.php
index 00901dd4115..ad1ac9e12f2 100644
--- a/tests/lib/user/manager.php
+++ b/tests/lib/user/manager.php
@@ -346,4 +346,76 @@ class Manager extends \PHPUnit_Framework_TestCase {
$manager->createUser('foo', 'bar');
}
+
+ public function testCountUsersNoBackend() {
+ $manager = new \OC\User\Manager();
+
+ $result = $manager->countUsers();
+ $this->assertTrue(is_array($result));
+ $this->assertTrue(empty($result));
+ }
+
+ public function testCountUsersOneBackend() {
+ /**
+ * @var \OC_User_Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
+ */
+ $backend = $this->getMock('\OC_User_Dummy');
+ $backend->expects($this->once())
+ ->method('countUsers')
+ ->will($this->returnValue(7));
+
+ $backend->expects($this->once())
+ ->method('implementsActions')
+ ->with(\OC_USER_BACKEND_COUNT_USERS)
+ ->will($this->returnValue(true));
+
+ $manager = new \OC\User\Manager();
+ $manager->registerBackend($backend);
+
+ $result = $manager->countUsers();
+ $keys = array_keys($result);
+ $this->assertTrue(strpos($keys[0], 'Mock_OC_User_Dummy') !== false);
+
+ $users = array_shift($result);
+ $this->assertEquals(7, $users);
+ }
+
+ public function testCountUsersTwoBackends() {
+ /**
+ * @var \OC_User_Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
+ */
+ $backend1 = $this->getMock('\OC_User_Dummy');
+ $backend1->expects($this->once())
+ ->method('countUsers')
+ ->will($this->returnValue(7));
+
+ $backend1->expects($this->once())
+ ->method('implementsActions')
+ ->with(\OC_USER_BACKEND_COUNT_USERS)
+ ->will($this->returnValue(true));
+
+ $backend2 = $this->getMock('\OC_User_Dummy');
+ $backend2->expects($this->once())
+ ->method('countUsers')
+ ->will($this->returnValue(16));
+
+ $backend2->expects($this->once())
+ ->method('implementsActions')
+ ->with(\OC_USER_BACKEND_COUNT_USERS)
+ ->will($this->returnValue(true));
+
+ $manager = new \OC\User\Manager();
+ $manager->registerBackend($backend1);
+ $manager->registerBackend($backend2);
+
+ $result = $manager->countUsers();
+ //because the backends have the same class name, only one value expected
+ $this->assertEquals(1, count($result));
+ $keys = array_keys($result);
+ $this->assertTrue(strpos($keys[0], 'Mock_OC_User_Dummy') !== false);
+
+ $users = array_shift($result);
+ //users from backends shall be summed up
+ $this->assertEquals(7+16, $users);
+ }
}