summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-11-04 10:28:56 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-11-04 10:28:56 +0100
commitb162761124aed3673eac22212d95e1311fa919a9 (patch)
treec960209600b98c796b8a3c0e66e1370d7fc1c636 /tests
parented0da94d3bdb47d57ee7a274f7e55ffa4e008f64 (diff)
parent18f0bafd88cd8f3baac9dae893b0c3deaaea7e15 (diff)
downloadnextcloud-server-b162761124aed3673eac22212d95e1311fa919a9.tar.gz
nextcloud-server-b162761124aed3673eac22212d95e1311fa919a9.zip
Merge pull request #20157 from owncloud/users-fixeveryonecount
Fix everyone count for subadmins
Diffstat (limited to 'tests')
-rw-r--r--tests/settings/controller/userscontrollertest.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/settings/controller/userscontrollertest.php b/tests/settings/controller/userscontrollertest.php
index e30a98447ae..f4b05671ce8 100644
--- a/tests/settings/controller/userscontrollertest.php
+++ b/tests/settings/controller/userscontrollertest.php
@@ -1677,4 +1677,73 @@ class UsersControllerTest extends \Test\TestCase {
$this->assertSame($responseCode, $response->getStatus());
}
+ public function testStatsAdmin() {
+ $this->container['IsAdmin'] = true;
+
+ $this->container['UserManager']
+ ->expects($this->at(0))
+ ->method('countUsers')
+ ->will($this->returnValue([128, 44]));
+
+ $expectedResponse = new DataResponse(
+ [
+ 'totalUsers' => 172
+ ]
+ );
+ $response = $this->container['UsersController']->stats();
+ $this->assertEquals($expectedResponse, $response);
+ }
+
+ /**
+ * Tests that the subadmin stats return unique users, even
+ * when a user appears in several groups.
+ */
+ public function testStatsSubAdmin() {
+ $this->container['IsAdmin'] = false;
+
+ $user = $this->getMockBuilder('\OC\User\User')
+ ->disableOriginalConstructor()->getMock();
+
+ $this->container['UserSession']
+ ->expects($this->once())
+ ->method('getUser')
+ ->will($this->returnValue($user));
+
+ $group1 = $this->getMockBuilder('\OC\Group\Group')
+ ->disableOriginalConstructor()->getMock();
+ $group1
+ ->expects($this->once())
+ ->method('getUsers')
+ ->will($this->returnValue(['foo' => 'M. Foo', 'admin' => 'S. Admin']));
+
+ $group2 = $this->getMockBuilder('\OC\Group\Group')
+ ->disableOriginalConstructor()->getMock();
+ $group2
+ ->expects($this->once())
+ ->method('getUsers')
+ ->will($this->returnValue(['bar' => 'B. Ar']));
+
+ $subadmin = $this->getMockBuilder('\OC\SubAdmin')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $subadmin
+ ->expects($this->at(0))
+ ->method('getSubAdminsGroups')
+ ->will($this->returnValue([$group1, $group2]));
+
+ $this->container['GroupManager']
+ ->expects($this->any())
+ ->method('getSubAdmin')
+ ->will($this->returnValue($subadmin));
+
+ $expectedResponse = new DataResponse(
+ [
+ 'totalUsers' => 3
+ ]
+ );
+
+ $response = $this->container['UsersController']->stats();
+ $this->assertEquals($expectedResponse, $response);
+ }
+
}