summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--settings/controller/userscontroller.php2
-rw-r--r--tests/settings/controller/userscontrollertest.php108
2 files changed, 94 insertions, 16 deletions
diff --git a/settings/controller/userscontroller.php b/settings/controller/userscontroller.php
index d9b6ba7f721..ddabd308a50 100644
--- a/settings/controller/userscontroller.php
+++ b/settings/controller/userscontroller.php
@@ -167,7 +167,7 @@ class UsersController extends Controller {
'name' => $user->getUID(),
'displayname' => $user->getDisplayName(),
'groups' => (empty($userGroups)) ? $this->groupManager->getUserGroupIds($user) : $userGroups,
- 'subadmin' => \OC_SubAdmin::getSubAdminsGroups($user->getUID()),
+ 'subadmin' => $this->subAdminFactory->getSubAdminsOfGroups($user->getUID()),
'quota' => $this->config->getUserValue($user->getUID(), 'files', 'quota', 'default'),
'storageLocation' => $user->getHome(),
'lastLogin' => $user->getLastLogin() * 1000,
diff --git a/tests/settings/controller/userscontrollertest.php b/tests/settings/controller/userscontrollertest.php
index 6fab43d6a16..408ddc45589 100644
--- a/tests/settings/controller/userscontrollertest.php
+++ b/tests/settings/controller/userscontrollertest.php
@@ -153,6 +153,22 @@ class UsersControllerTest extends \Test\TestCase {
404, 'admin@bar.com',
2323, 'bar@dummy.com'));
+ $this->container['SubAdminFactory']
+ ->expects($this->at(0))
+ ->method('getSubAdminsOfGroups')
+ ->with('foo')
+ ->will($this->returnValue([]));
+ $this->container['SubAdminFactory']
+ ->expects($this->at(1))
+ ->method('getSubAdminsOfGroups')
+ ->with('admin')
+ ->will($this->returnValue([]));
+ $this->container['SubAdminFactory']
+ ->expects($this->at(2))
+ ->method('getSubAdminsOfGroups')
+ ->with('bar')
+ ->will($this->returnValue([]));
+
$expectedResponse = new DataResponse(
array(
0 => array(
@@ -199,11 +215,6 @@ class UsersControllerTest extends \Test\TestCase {
public function testIndexSubAdmin() {
$this->container['IsAdmin'] = false;
- $this->container['SubAdminFactory']
- ->expects($this->once())
- ->method('getSubAdminsOfGroups')
- ->with('username')
- ->will($this->returnValue(['SubGroup1', 'SubGroup2']));
$user = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
@@ -321,6 +332,15 @@ class UsersControllerTest extends \Test\TestCase {
2323, 'bar@dummy.com'
));
+ $this->container['SubAdminFactory']
+ ->method('getSubAdminsOfGroups')
+ ->will($this->returnValueMap([
+ ['username' , ['SubGroup1', 'SubGroup2']],
+ ['foo', []],
+ ['admin', []],
+ ['bar', []],
+ ]));
+
$expectedResponse = new DataResponse(
[
0 => [
@@ -452,6 +472,23 @@ class UsersControllerTest extends \Test\TestCase {
404, 'admin@bar.com',
2323, 'bar@dummy.com'));
+ $this->container['SubAdminFactory']
+ ->expects($this->at(0))
+ ->method('getSubAdminsOfGroups')
+ ->with('foo')
+ ->will($this->returnValue([]));
+ $this->container['SubAdminFactory']
+ ->expects($this->at(1))
+ ->method('getSubAdminsOfGroups')
+ ->with('admin')
+ ->will($this->returnValue([]));
+ $this->container['SubAdminFactory']
+ ->expects($this->at(2))
+ ->method('getSubAdminsOfGroups')
+ ->with('bar')
+ ->will($this->returnValue([]));
+
+
$expectedResponse = new DataResponse(
array(
0 => array(
@@ -532,6 +569,12 @@ class UsersControllerTest extends \Test\TestCase {
->with('')
->will($this->returnValue([$user]));
+ $this->container['SubAdminFactory']
+ ->expects($this->once())
+ ->method('getSubAdminsOfGroups')
+ ->with('foo')
+ ->will($this->returnValue([]));
+
$expectedResponse = new DataResponse(
array(
0 => array(
@@ -591,6 +634,11 @@ class UsersControllerTest extends \Test\TestCase {
->method('createUser')
->will($this->onConsecutiveCalls($user));
+ $this->container['SubAdminFactory']
+ ->expects($this->once())
+ ->method('getSubAdminsOfGroups')
+ ->with('foo')
+ ->will($this->returnValue([]));
$expectedResponse = new DataResponse(
array(
@@ -613,11 +661,6 @@ class UsersControllerTest extends \Test\TestCase {
public function testCreateSuccessfulWithoutGroupSubAdmin() {
$this->container['IsAdmin'] = false;
- $this->container['SubAdminFactory']
- ->expects($this->once())
- ->method('getSubAdminsOfGroups')
- ->with('username')
- ->will($this->returnValue(['SubGroup1', 'SubGroup2']));
$user = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$user
@@ -671,6 +714,13 @@ class UsersControllerTest extends \Test\TestCase {
->with($user)
->will($this->onConsecutiveCalls(['SubGroup1', 'SubGroup2']));
+ $this->container['SubAdminFactory']
+ ->method('getSubAdminsOfGroups')
+ ->will($this->returnValueMap([
+ ['username', ['SubGroup1', 'SubGroup2']],
+ ['foo', []],
+ ]));
+
$expectedResponse = new DataResponse(
array(
'name' => 'foo',
@@ -740,6 +790,12 @@ class UsersControllerTest extends \Test\TestCase {
->with($user)
->will($this->onConsecutiveCalls(array('NewGroup', 'ExistingGroup')));
+ $this->container['SubAdminFactory']
+ ->expects($this->once())
+ ->method('getSubAdminsOfGroups')
+ ->with('foo')
+ ->will($this->returnValue([]));
+
$expectedResponse = new DataResponse(
array(
'name' => 'foo',
@@ -761,11 +817,6 @@ class UsersControllerTest extends \Test\TestCase {
public function testCreateSuccessfulWithGroupSubAdmin() {
$this->container['IsAdmin'] = false;
- $this->container['SubAdminFactory']
- ->expects($this->once())
- ->method('getSubAdminsOfGroups')
- ->with('username')
- ->will($this->returnValue(['SubGroup1', 'SubGroup2']));
$user = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$user
@@ -819,6 +870,13 @@ class UsersControllerTest extends \Test\TestCase {
->with($user)
->will($this->onConsecutiveCalls(['SubGroup1']));
+ $this->container['SubAdminFactory']
+ ->method('getSubAdminsOfGroups')
+ ->will($this->returnValueMap([
+ ['username', ['SubGroup1', 'SubGroup2']],
+ ['foo', []],
+ ]));
+
$expectedResponse = new DataResponse(
array(
'name' => 'foo',
@@ -1286,6 +1344,11 @@ class UsersControllerTest extends \Test\TestCase {
list($user, $expectedResult) = $this->mockUser();
+ $this->container['SubAdminFactory']
+ ->method('getSubAdminsOfGroups')
+ ->with($user->getUID())
+ ->will($this->returnValue([]));
+
$result = self::invokePrivate($this->container['UsersController'], 'formatUserForIndex', [$user]);
$this->assertEquals($expectedResult, $result);
}
@@ -1323,6 +1386,11 @@ class UsersControllerTest extends \Test\TestCase {
)
->will($this->returnValue('1'));
+ $this->container['SubAdminFactory']
+ ->method('getSubAdminsOfGroups')
+ ->with($user->getUID())
+ ->will($this->returnValue([]));
+
$result = self::invokePrivate($this->container['UsersController'], 'formatUserForIndex', [$user]);
$this->assertEquals($expectedResult, $result);
}
@@ -1341,6 +1409,11 @@ class UsersControllerTest extends \Test\TestCase {
$expectedResult['isRestoreDisabled'] = true;
+ $this->container['SubAdminFactory']
+ ->method('getSubAdminsOfGroups')
+ ->with($user->getUID())
+ ->will($this->returnValue([]));
+
$result = self::invokePrivate($this->container['UsersController'], 'formatUserForIndex', [$user]);
$this->assertEquals($expectedResult, $result);
}
@@ -1380,6 +1453,11 @@ class UsersControllerTest extends \Test\TestCase {
$expectedResult['isRestoreDisabled'] = true;
+ $this->container['SubAdminFactory']
+ ->method('getSubAdminsOfGroups')
+ ->with($user->getUID())
+ ->will($this->returnValue([]));
+
$result = self::invokePrivate($this->container['UsersController'], 'formatUserForIndex', [$user]);
$this->assertEquals($expectedResult, $result);
}