diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-10-29 16:40:39 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-10-29 17:41:49 +0100 |
commit | 781bca2437628d2f932abd60c5dcec0ece4504e3 (patch) | |
tree | 9729ae043ff4061570e95f127db82a4197b5ee62 /tests | |
parent | 73d9699be9d2a343b0573dc6a5bcc65f5f9c7303 (diff) | |
download | nextcloud-server-781bca2437628d2f932abd60c5dcec0ece4504e3.tar.gz nextcloud-server-781bca2437628d2f932abd60c5dcec0ece4504e3.zip |
Fix everyone count for subadmins
Also moved the logic to the UsersController
Diffstat (limited to 'tests')
-rw-r--r-- | tests/settings/controller/userscontrollertest.php | 69 |
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); + } + } |