|
|
|
@ -25,7 +25,7 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
$app = new Application(); |
|
|
|
|
$this->container = $app->getContainer(); |
|
|
|
|
$this->container['AppName'] = 'settings'; |
|
|
|
|
$this->container['GroupManager'] = $this->getMockBuilder('\OCP\IGroupManager') |
|
|
|
|
$this->container['GroupManager'] = $this->getMockBuilder('\OC\Group\Manager') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$this->container['UserManager'] = $this->getMockBuilder('\OCP\IUserManager') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
@ -33,8 +33,6 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$this->container['L10N'] = $this->getMockBuilder('\OCP\IL10N') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$this->container['SubAdminFactory'] = $this->getMockBuilder('\OC\Settings\Factory\SubAdminFactory') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$this->container['Config'] = $this->getMockBuilder('\OCP\IConfig') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$this->container['L10N'] |
|
|
|
@ -62,7 +60,7 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
$foo = $this->getMockBuilder('\OC\User\User') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$foo |
|
|
|
|
->expects($this->exactly(4)) |
|
|
|
|
->expects($this->exactly(3)) |
|
|
|
|
->method('getUID') |
|
|
|
|
->will($this->returnValue('foo')); |
|
|
|
|
$foo |
|
|
|
@ -82,7 +80,7 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
$admin = $this->getMockBuilder('\OC\User\User') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$admin |
|
|
|
|
->expects($this->exactly(4)) |
|
|
|
|
->expects($this->exactly(3)) |
|
|
|
|
->method('getUID') |
|
|
|
|
->will($this->returnValue('admin')); |
|
|
|
|
$admin |
|
|
|
@ -104,7 +102,7 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
$bar = $this->getMockBuilder('\OC\User\User') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$bar |
|
|
|
|
->expects($this->exactly(4)) |
|
|
|
|
->expects($this->exactly(3)) |
|
|
|
|
->method('getUID') |
|
|
|
|
->will($this->returnValue('bar')); |
|
|
|
|
$bar |
|
|
|
@ -153,21 +151,29 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
404, 'admin@bar.com', |
|
|
|
|
2323, 'bar@dummy.com')); |
|
|
|
|
|
|
|
|
|
$this->container['SubAdminFactory'] |
|
|
|
|
->expects($this->at(0)) |
|
|
|
|
->method('getSubAdminsOfGroups') |
|
|
|
|
->with('foo') |
|
|
|
|
$subadmin = $this->getMockBuilder('\OC\SubAdmin') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$subadmin |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdminsGroups') |
|
|
|
|
->with($foo) |
|
|
|
|
->will($this->returnValue([])); |
|
|
|
|
$this->container['SubAdminFactory'] |
|
|
|
|
->expects($this->at(1)) |
|
|
|
|
->method('getSubAdminsOfGroups') |
|
|
|
|
->with('admin') |
|
|
|
|
$subadmin |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdminsGroups') |
|
|
|
|
->with($admin) |
|
|
|
|
->will($this->returnValue([])); |
|
|
|
|
$this->container['SubAdminFactory'] |
|
|
|
|
->expects($this->at(2)) |
|
|
|
|
->method('getSubAdminsOfGroups') |
|
|
|
|
->with('bar') |
|
|
|
|
$subadmin |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdminsGroups') |
|
|
|
|
->with($bar) |
|
|
|
|
->will($this->returnValue([])); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdmin') |
|
|
|
|
->will($this->returnValue($subadmin)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$expectedResponse = new DataResponse( |
|
|
|
|
array( |
|
|
|
@ -218,10 +224,6 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
|
|
|
|
|
$user = $this->getMockBuilder('\OC\User\User') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$user |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('getUID') |
|
|
|
|
->will($this->returnValue('username')); |
|
|
|
|
$this->container['UserSession'] |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('getUser') |
|
|
|
@ -230,7 +232,7 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
$foo = $this->getMockBuilder('\OC\User\User') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$foo |
|
|
|
|
->expects($this->exactly(4)) |
|
|
|
|
->expects($this->exactly(3)) |
|
|
|
|
->method('getUID') |
|
|
|
|
->will($this->returnValue('foo')); |
|
|
|
|
$foo |
|
|
|
@ -250,7 +252,7 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
$admin = $this->getMockBuilder('\OC\User\User') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$admin |
|
|
|
|
->expects($this->exactly(4)) |
|
|
|
|
->expects($this->exactly(3)) |
|
|
|
|
->method('getUID') |
|
|
|
|
->will($this->returnValue('admin')); |
|
|
|
|
$admin |
|
|
|
@ -272,7 +274,7 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
$bar = $this->getMockBuilder('\OC\User\User') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$bar |
|
|
|
|
->expects($this->exactly(4)) |
|
|
|
|
->expects($this->exactly(3)) |
|
|
|
|
->method('getUID') |
|
|
|
|
->will($this->returnValue('bar')); |
|
|
|
|
$bar |
|
|
|
@ -291,59 +293,90 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
->will($this->returnValue('\Test\Util\User\Dummy')); |
|
|
|
|
|
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->at(0)) |
|
|
|
|
->expects($this->at(2)) |
|
|
|
|
->method('displayNamesInGroup') |
|
|
|
|
->with('SubGroup1', 'pattern') |
|
|
|
|
->with('SubGroup2', 'pattern') |
|
|
|
|
->will($this->returnValue(['foo' => 'M. Foo', 'admin' => 'S. Admin'])); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->at(1)) |
|
|
|
|
->method('displayNamesInGroup') |
|
|
|
|
->with('SubGroup2', 'pattern') |
|
|
|
|
->with('SubGroup1', 'pattern') |
|
|
|
|
->will($this->returnValue(['bar' => 'B. Ar'])); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->exactly(3)) |
|
|
|
|
->method('getUserGroupIds') |
|
|
|
|
->will($this->onConsecutiveCalls( |
|
|
|
|
['admin', 'SubGroup1', 'testGroup'], |
|
|
|
|
['SubGroup2', 'SubGroup1'], |
|
|
|
|
['SubGroup2', 'Foo'], |
|
|
|
|
['admin', 'SubGroup1', 'testGroup'] |
|
|
|
|
['SubGroup2', 'Foo'] |
|
|
|
|
)); |
|
|
|
|
$this->container['UserManager'] |
|
|
|
|
->expects($this->at(0)) |
|
|
|
|
->method('get') |
|
|
|
|
->with('foo') |
|
|
|
|
->will($this->returnValue($foo)); |
|
|
|
|
->with('bar') |
|
|
|
|
->will($this->returnValue($bar)); |
|
|
|
|
$this->container['UserManager'] |
|
|
|
|
->expects($this->at(1)) |
|
|
|
|
->method('get') |
|
|
|
|
->with('admin') |
|
|
|
|
->will($this->returnValue($admin)); |
|
|
|
|
->with('foo') |
|
|
|
|
->will($this->returnValue($foo)); |
|
|
|
|
$this->container['UserManager'] |
|
|
|
|
->expects($this->at(2)) |
|
|
|
|
->method('get') |
|
|
|
|
->with('bar') |
|
|
|
|
->will($this->returnValue($bar)); |
|
|
|
|
->with('admin') |
|
|
|
|
->will($this->returnValue($admin)); |
|
|
|
|
$this->container['Config'] |
|
|
|
|
->expects($this->exactly(6)) |
|
|
|
|
->method('getUserValue') |
|
|
|
|
->will($this->onConsecutiveCalls( |
|
|
|
|
2323, 'bar@dummy.com', |
|
|
|
|
1024, 'foo@bar.com', |
|
|
|
|
404, 'admin@bar.com', |
|
|
|
|
2323, 'bar@dummy.com' |
|
|
|
|
404, 'admin@bar.com' |
|
|
|
|
)); |
|
|
|
|
|
|
|
|
|
$this->container['SubAdminFactory'] |
|
|
|
|
->method('getSubAdminsOfGroups') |
|
|
|
|
->will($this->returnValueMap([ |
|
|
|
|
['username' , ['SubGroup1', 'SubGroup2']], |
|
|
|
|
['foo', []], |
|
|
|
|
['admin', []], |
|
|
|
|
['bar', []], |
|
|
|
|
])); |
|
|
|
|
$subgroup1 = $this->getMockBuilder('\OCP\IGroup') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$subgroup1->expects($this->any()) |
|
|
|
|
->method('getGID') |
|
|
|
|
->will($this->returnValue('SubGroup1')); |
|
|
|
|
$subgroup2 = $this->getMockBuilder('\OCP\IGroup') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$subgroup2->expects($this->any()) |
|
|
|
|
->method('getGID') |
|
|
|
|
->will($this->returnValue('SubGroup2')); |
|
|
|
|
$subadmin = $this->getMockBuilder('\OC\SubAdmin') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$subadmin |
|
|
|
|
->expects($this->at(0)) |
|
|
|
|
->method('getSubAdminsGroups') |
|
|
|
|
->will($this->returnValue([$subgroup1, $subgroup2])); |
|
|
|
|
$subadmin |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdminsGroups') |
|
|
|
|
->will($this->returnValue([])); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdmin') |
|
|
|
|
->will($this->returnValue($subadmin)); |
|
|
|
|
|
|
|
|
|
$expectedResponse = new DataResponse( |
|
|
|
|
[ |
|
|
|
|
0 => [ |
|
|
|
|
'name' => 'bar', |
|
|
|
|
'displayname' => 'B. Ar', |
|
|
|
|
'groups' => ['SubGroup1'], |
|
|
|
|
'subadmin' => [], |
|
|
|
|
'quota' => 2323, |
|
|
|
|
'storageLocation' => '/home/bar', |
|
|
|
|
'lastLogin' => 3999000, |
|
|
|
|
'backend' => '\Test\Util\User\Dummy', |
|
|
|
|
'email' => 'bar@dummy.com', |
|
|
|
|
'isRestoreDisabled' => false, |
|
|
|
|
], |
|
|
|
|
1=> [ |
|
|
|
|
'name' => 'foo', |
|
|
|
|
'displayname' => 'M. Foo', |
|
|
|
|
'groups' => ['SubGroup2', 'SubGroup1'], |
|
|
|
@ -355,7 +388,7 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
'email' => 'foo@bar.com', |
|
|
|
|
'isRestoreDisabled' => false, |
|
|
|
|
], |
|
|
|
|
1 => [ |
|
|
|
|
2 => [ |
|
|
|
|
'name' => 'admin', |
|
|
|
|
'displayname' => 'S. Admin', |
|
|
|
|
'groups' => ['SubGroup2'], |
|
|
|
@ -367,18 +400,6 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
'email' => 'admin@bar.com', |
|
|
|
|
'isRestoreDisabled' => false, |
|
|
|
|
], |
|
|
|
|
2 => [ |
|
|
|
|
'name' => 'bar', |
|
|
|
|
'displayname' => 'B. Ar', |
|
|
|
|
'groups' => ['SubGroup1'], |
|
|
|
|
'subadmin' => [], |
|
|
|
|
'quota' => 2323, |
|
|
|
|
'storageLocation' => '/home/bar', |
|
|
|
|
'lastLogin' => 3999000, |
|
|
|
|
'backend' => '\Test\Util\User\Dummy', |
|
|
|
|
'email' => 'bar@dummy.com', |
|
|
|
|
'isRestoreDisabled' => false, |
|
|
|
|
], |
|
|
|
|
] |
|
|
|
|
); |
|
|
|
|
|
|
|
|
@ -396,7 +417,7 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
$foo = $this->getMockBuilder('\OC\User\User') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$foo |
|
|
|
|
->expects($this->exactly(4)) |
|
|
|
|
->expects($this->exactly(3)) |
|
|
|
|
->method('getUID') |
|
|
|
|
->will($this->returnValue('foo')); |
|
|
|
|
$foo |
|
|
|
@ -416,7 +437,7 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
$admin = $this->getMockBuilder('\OC\User\User') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$admin |
|
|
|
|
->expects($this->exactly(4)) |
|
|
|
|
->expects($this->exactly(3)) |
|
|
|
|
->method('getUID') |
|
|
|
|
->will($this->returnValue('admin')); |
|
|
|
|
$admin |
|
|
|
@ -438,7 +459,7 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
$bar = $this->getMockBuilder('\OC\User\User') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$bar |
|
|
|
|
->expects($this->exactly(4)) |
|
|
|
|
->expects($this->exactly(3)) |
|
|
|
|
->method('getUID') |
|
|
|
|
->will($this->returnValue('bar')); |
|
|
|
|
$bar |
|
|
|
@ -472,22 +493,16 @@ 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') |
|
|
|
|
$subadmin = $this->getMockBuilder('\OC\SubAdmin') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$subadmin->expects($this->any()) |
|
|
|
|
->method('getSubAdminsGroups') |
|
|
|
|
->will($this->returnValue([])); |
|
|
|
|
$this->container['SubAdminFactory'] |
|
|
|
|
->expects($this->at(2)) |
|
|
|
|
->method('getSubAdminsOfGroups') |
|
|
|
|
->with('bar') |
|
|
|
|
->will($this->returnValue([])); |
|
|
|
|
|
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdmin') |
|
|
|
|
->will($this->returnValue($subadmin)); |
|
|
|
|
|
|
|
|
|
$expectedResponse = new DataResponse( |
|
|
|
|
array( |
|
|
|
@ -539,7 +554,7 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
$user = $this->getMockBuilder('\OC\User\User') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$user |
|
|
|
|
->expects($this->exactly(4)) |
|
|
|
|
->expects($this->exactly(3)) |
|
|
|
|
->method('getUID') |
|
|
|
|
->will($this->returnValue('foo')); |
|
|
|
|
$user |
|
|
|
@ -569,11 +584,16 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
->with('') |
|
|
|
|
->will($this->returnValue([$user])); |
|
|
|
|
|
|
|
|
|
$this->container['SubAdminFactory'] |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('getSubAdminsOfGroups') |
|
|
|
|
->with('foo') |
|
|
|
|
$subadmin = $this->getMockBuilder('\OC\SubAdmin') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$subadmin->expects($this->once()) |
|
|
|
|
->method('getSubAdminsGroups') |
|
|
|
|
->will($this->returnValue([])); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdmin') |
|
|
|
|
->will($this->returnValue($subadmin)); |
|
|
|
|
|
|
|
|
|
$expectedResponse = new DataResponse( |
|
|
|
|
array( |
|
|
|
@ -634,11 +654,18 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
->method('createUser') |
|
|
|
|
->will($this->onConsecutiveCalls($user)); |
|
|
|
|
|
|
|
|
|
$this->container['SubAdminFactory'] |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('getSubAdminsOfGroups') |
|
|
|
|
->with('foo') |
|
|
|
|
$subadmin = $this->getMockBuilder('\OC\SubAdmin') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$subadmin |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdminsGroups') |
|
|
|
|
->with($user) |
|
|
|
|
->will($this->returnValue([])); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdmin') |
|
|
|
|
->will($this->returnValue($subadmin)); |
|
|
|
|
|
|
|
|
|
$expectedResponse = new DataResponse( |
|
|
|
|
array( |
|
|
|
@ -663,47 +690,45 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
$this->container['IsAdmin'] = false; |
|
|
|
|
$user = $this->getMockBuilder('\OC\User\User') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$user |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('getUID') |
|
|
|
|
->will($this->returnValue('username')); |
|
|
|
|
$this->container['UserSession'] |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('getUser') |
|
|
|
|
->will($this->returnValue($user)); |
|
|
|
|
|
|
|
|
|
$user = $this->getMockBuilder('\OC\User\User') |
|
|
|
|
$newUser = $this->getMockBuilder('\OC\User\User') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$user |
|
|
|
|
$newUser |
|
|
|
|
->method('getUID') |
|
|
|
|
->will($this->returnValue('foo')); |
|
|
|
|
$newUser |
|
|
|
|
->method('getHome') |
|
|
|
|
->will($this->returnValue('/home/user')); |
|
|
|
|
$user |
|
|
|
|
$newUser |
|
|
|
|
->method('getHome') |
|
|
|
|
->will($this->returnValue('/home/user')); |
|
|
|
|
$user |
|
|
|
|
->method('getUID') |
|
|
|
|
->will($this->returnValue('foo')); |
|
|
|
|
$user |
|
|
|
|
$newUser |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('getBackendClassName') |
|
|
|
|
->will($this->returnValue('bar')); |
|
|
|
|
$user = $this->getMockBuilder('\OC\User\User') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$subGroup1 = $this->getMockBuilder('\OCP\IGroup') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$subGroup1 |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('addUser') |
|
|
|
|
->with($user); |
|
|
|
|
->with($newUser); |
|
|
|
|
$subGroup2 = $this->getMockBuilder('\OCP\IGroup') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$subGroup2 |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('addUser') |
|
|
|
|
->with($user); |
|
|
|
|
->with($newUser); |
|
|
|
|
|
|
|
|
|
$this->container['UserManager'] |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('createUser') |
|
|
|
|
->will($this->onConsecutiveCalls($user)); |
|
|
|
|
->will($this->returnValue($newUser)); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->exactly(2)) |
|
|
|
|
->method('get') |
|
|
|
@ -714,12 +739,21 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
->with($user) |
|
|
|
|
->will($this->onConsecutiveCalls(['SubGroup1', 'SubGroup2'])); |
|
|
|
|
|
|
|
|
|
$this->container['SubAdminFactory'] |
|
|
|
|
->method('getSubAdminsOfGroups') |
|
|
|
|
->will($this->returnValueMap([ |
|
|
|
|
['username', ['SubGroup1', 'SubGroup2']], |
|
|
|
|
['foo', []], |
|
|
|
|
])); |
|
|
|
|
$subadmin = $this->getMockBuilder('\OC\SubAdmin') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$subadmin |
|
|
|
|
->expects($this->at(0)) |
|
|
|
|
->method('getSubAdminsGroups') |
|
|
|
|
->will($this->returnValue([$subGroup1, $subGroup2])); |
|
|
|
|
$subadmin |
|
|
|
|
->expects($this->at(1)) |
|
|
|
|
->method('getSubAdminsGroups') |
|
|
|
|
->will($this->returnValue([])); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdmin') |
|
|
|
|
->will($this->returnValue($subadmin)); |
|
|
|
|
|
|
|
|
|
$expectedResponse = new DataResponse( |
|
|
|
|
array( |
|
|
|
@ -727,7 +761,7 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
'groups' => ['SubGroup1', 'SubGroup2'], |
|
|
|
|
'storageLocation' => '/home/user', |
|
|
|
|
'backend' => 'bar', |
|
|
|
|
'lastLogin' => null, |
|
|
|
|
'lastLogin' => 0, |
|
|
|
|
'displayname' => null, |
|
|
|
|
'quota' => null, |
|
|
|
|
'subadmin' => [], |
|
|
|
@ -790,11 +824,18 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
->with($user) |
|
|
|
|
->will($this->onConsecutiveCalls(array('NewGroup', 'ExistingGroup'))); |
|
|
|
|
|
|
|
|
|
$this->container['SubAdminFactory'] |
|
|
|
|
$subadmin = $this->getMockBuilder('\OC\SubAdmin') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$subadmin |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('getSubAdminsOfGroups') |
|
|
|
|
->with('foo') |
|
|
|
|
->method('getSubAdminsGroups') |
|
|
|
|
->with($user) |
|
|
|
|
->will($this->returnValue([])); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdmin') |
|
|
|
|
->will($this->returnValue($subadmin)); |
|
|
|
|
|
|
|
|
|
$expectedResponse = new DataResponse( |
|
|
|
|
array( |
|
|
|
@ -819,63 +860,77 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
$this->container['IsAdmin'] = false; |
|
|
|
|
$user = $this->getMockBuilder('\OC\User\User') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$user |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('getUID') |
|
|
|
|
->will($this->returnValue('username')); |
|
|
|
|
$this->container['UserSession'] |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('getUser') |
|
|
|
|
->will($this->returnValue($user)); |
|
|
|
|
|
|
|
|
|
$user = $this->getMockBuilder('\OC\User\User') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$user |
|
|
|
|
$newUser = $this->getMockBuilder('\OC\User\User') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$newUser |
|
|
|
|
->method('getHome') |
|
|
|
|
->will($this->returnValue('/home/user')); |
|
|
|
|
$user |
|
|
|
|
$newUser |
|
|
|
|
->method('getHome') |
|
|
|
|
->will($this->returnValue('/home/user')); |
|
|
|
|
$user |
|
|
|
|
$newUser |
|
|
|
|
->method('getUID') |
|
|
|
|
->will($this->returnValue('foo')); |
|
|
|
|
$user |
|
|
|
|
$newUser |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('getBackendClassName') |
|
|
|
|
->will($this->returnValue('bar')); |
|
|
|
|
$subGroup1 = $this->getMockBuilder('\OCP\IGroup') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$subGroup1 |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getGID') |
|
|
|
|
->will($this->returnValue('SubGroup1')); |
|
|
|
|
$subGroup1 |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('addUser') |
|
|
|
|
->with($user); |
|
|
|
|
$subGroup2 = $this->getMockBuilder('\OCP\IGroup') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$subGroup2 |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('addUser') |
|
|
|
|
->with($user); |
|
|
|
|
|
|
|
|
|
$this->container['UserManager'] |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('createUser') |
|
|
|
|
->will($this->onConsecutiveCalls($user)); |
|
|
|
|
->will($this->returnValue($newUser)); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->exactly(2)) |
|
|
|
|
->expects($this->at(0)) |
|
|
|
|
->method('get') |
|
|
|
|
->will($this->onConsecutiveCalls($subGroup1, $subGroup2)); |
|
|
|
|
->with('SubGroup1') |
|
|
|
|
->will($this->returnValue($subGroup1)); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->at(4)) |
|
|
|
|
->method('get') |
|
|
|
|
->with('SubGroup1') |
|
|
|
|
->will($this->returnValue($subGroup1)); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('getUserGroupIds') |
|
|
|
|
->with($user) |
|
|
|
|
->will($this->onConsecutiveCalls(['SubGroup1'])); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('getUserGroupIds') |
|
|
|
|
->with($newUser) |
|
|
|
|
->will($this->onConsecutiveCalls(['SubGroup1'])); |
|
|
|
|
|
|
|
|
|
$this->container['SubAdminFactory'] |
|
|
|
|
->method('getSubAdminsOfGroups') |
|
|
|
|
->will($this->returnValueMap([ |
|
|
|
|
['username', ['SubGroup1', 'SubGroup2']], |
|
|
|
|
['foo', []], |
|
|
|
|
])); |
|
|
|
|
$subadmin = $this->getMockBuilder('\OC\SubAdmin') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$subadmin->expects($this->at(1)) |
|
|
|
|
->method('getSubAdminsGroups') |
|
|
|
|
->with($user) |
|
|
|
|
->will($this->returnValue([$subGroup1])); |
|
|
|
|
$subadmin->expects($this->at(2)) |
|
|
|
|
->method('getSubAdminsGroups') |
|
|
|
|
->with($newUser) |
|
|
|
|
->will($this->returnValue([])); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdmin') |
|
|
|
|
->will($this->returnValue($subadmin)); |
|
|
|
|
|
|
|
|
|
$expectedResponse = new DataResponse( |
|
|
|
|
array( |
|
|
|
@ -883,7 +938,7 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
'groups' => ['SubGroup1'], |
|
|
|
|
'storageLocation' => '/home/user', |
|
|
|
|
'backend' => 'bar', |
|
|
|
|
'lastLogin' => null, |
|
|
|
|
'lastLogin' => 0, |
|
|
|
|
'displayname' => null, |
|
|
|
|
'quota' => null, |
|
|
|
|
'subadmin' => [], |
|
|
|
@ -915,15 +970,10 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
|
|
|
|
|
public function testCreateUnsuccessfulSubAdmin() { |
|
|
|
|
$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 |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getUID') |
|
|
|
|
->will($this->returnValue('username')); |
|
|
|
|
$this->container['UserSession'] |
|
|
|
@ -935,6 +985,30 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
->method('createUser') |
|
|
|
|
->will($this->throwException(new \Exception())); |
|
|
|
|
|
|
|
|
|
$subgroup1 = $this->getMockBuilder('\OCP\IGroup') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$subgroup1->expects($this->once()) |
|
|
|
|
->method('getGID') |
|
|
|
|
->will($this->returnValue('SubGroup1')); |
|
|
|
|
$subgroup2 = $this->getMockBuilder('\OCP\IGroup') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$subgroup2->expects($this->once()) |
|
|
|
|
->method('getGID') |
|
|
|
|
->will($this->returnValue('SubGroup2')); |
|
|
|
|
$subadmin = $this->getMockBuilder('\OC\SubAdmin') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$subadmin->expects($this->once()) |
|
|
|
|
->method('getSubAdminsGroups') |
|
|
|
|
->with($user) |
|
|
|
|
->will($this->returnValue([$subgroup1, $subgroup2])); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdmin') |
|
|
|
|
->will($this->returnValue($subadmin)); |
|
|
|
|
|
|
|
|
|
$expectedResponse = new DataResponse( |
|
|
|
|
[ |
|
|
|
|
'message' => 'Unable to create user.' |
|
|
|
@ -1035,11 +1109,6 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
|
|
|
|
|
public function testDestroySubAdmin() { |
|
|
|
|
$this->container['IsAdmin'] = false; |
|
|
|
|
$this->container['SubAdminFactory'] |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('isUserAccessible') |
|
|
|
|
->with('myself', 'UserToDelete') |
|
|
|
|
->will($this->returnValue(true)); |
|
|
|
|
$user = $this->getMockBuilder('\OC\User\User') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$user |
|
|
|
@ -1066,6 +1135,18 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
->with('UserToDelete') |
|
|
|
|
->will($this->returnValue($toDeleteUser)); |
|
|
|
|
|
|
|
|
|
$subadmin = $this->getMockBuilder('\OC\SubAdmin') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$subadmin->expects($this->once()) |
|
|
|
|
->method('isUserAccessible') |
|
|
|
|
->with($user, $toDeleteUser) |
|
|
|
|
->will($this->returnValue(true)); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdmin') |
|
|
|
|
->will($this->returnValue($subadmin)); |
|
|
|
|
|
|
|
|
|
$expectedResponse = new DataResponse( |
|
|
|
|
[ |
|
|
|
|
'status' => 'success', |
|
|
|
@ -1117,11 +1198,6 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
|
|
|
|
|
public function testDestroyUnsuccessfulSubAdmin() { |
|
|
|
|
$this->container['IsAdmin'] = false; |
|
|
|
|
$this->container['SubAdminFactory'] |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('isUserAccessible') |
|
|
|
|
->with('myself', 'UserToDelete') |
|
|
|
|
->will($this->returnValue(true)); |
|
|
|
|
$user = $this->getMockBuilder('\OC\User\User') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$user |
|
|
|
@ -1146,6 +1222,18 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
->with('UserToDelete') |
|
|
|
|
->will($this->returnValue($toDeleteUser)); |
|
|
|
|
|
|
|
|
|
$subadmin = $this->getMockBuilder('\OC\SubAdmin') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$subadmin->expects($this->once()) |
|
|
|
|
->method('isUserAccessible') |
|
|
|
|
->with($user, $toDeleteUser) |
|
|
|
|
->will($this->returnValue(true)); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdmin') |
|
|
|
|
->will($this->returnValue($subadmin)); |
|
|
|
|
|
|
|
|
|
$expectedResponse = new DataResponse( |
|
|
|
|
[ |
|
|
|
|
'status' => 'error', |
|
|
|
@ -1161,11 +1249,7 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
|
|
|
|
|
public function testDestroyNotAccessibleToSubAdmin() { |
|
|
|
|
$this->container['IsAdmin'] = false; |
|
|
|
|
$this->container['SubAdminFactory'] |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('isUserAccessible') |
|
|
|
|
->with('myself', 'UserToDelete') |
|
|
|
|
->will($this->returnValue(false)); |
|
|
|
|
|
|
|
|
|
$user = $this->getMockBuilder('\OC\User\User') |
|
|
|
|
->disableOriginalConstructor()->getMock(); |
|
|
|
|
$user |
|
|
|
@ -1186,6 +1270,18 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
->with('UserToDelete') |
|
|
|
|
->will($this->returnValue($toDeleteUser)); |
|
|
|
|
|
|
|
|
|
$subadmin = $this->getMockBuilder('\OC\SubAdmin') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$subadmin->expects($this->once()) |
|
|
|
|
->method('isUserAccessible') |
|
|
|
|
->with($user, $toDeleteUser) |
|
|
|
|
->will($this->returnValue(false)); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdmin') |
|
|
|
|
->will($this->returnValue($subadmin)); |
|
|
|
|
|
|
|
|
|
$expectedResponse = new DataResponse( |
|
|
|
|
[ |
|
|
|
|
'status' => 'error', |
|
|
|
@ -1294,7 +1390,17 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('createUser') |
|
|
|
|
->will($this->onConsecutiveCalls($user)); |
|
|
|
|
|
|
|
|
|
$subadmin = $this->getMockBuilder('\OC\SubAdmin') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$subadmin->expects($this->once()) |
|
|
|
|
->method('getSubAdminsGroups') |
|
|
|
|
->with($user) |
|
|
|
|
->will($this->returnValue([])); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdmin') |
|
|
|
|
->will($this->returnValue($subadmin)); |
|
|
|
|
|
|
|
|
|
$response = $this->container['UsersController']->create('foo', 'password', [], 'validMail@Adre.ss'); |
|
|
|
|
$this->assertEquals(Http::STATUS_CREATED, $response->getStatus()); |
|
|
|
@ -1344,10 +1450,17 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
|
|
|
|
|
list($user, $expectedResult) = $this->mockUser(); |
|
|
|
|
|
|
|
|
|
$this->container['SubAdminFactory'] |
|
|
|
|
->method('getSubAdminsOfGroups') |
|
|
|
|
->with($user->getUID()) |
|
|
|
|
$subadmin = $this->getMockBuilder('\OC\SubAdmin') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$subadmin->expects($this->once()) |
|
|
|
|
->method('getSubAdminsGroups') |
|
|
|
|
->with($user) |
|
|
|
|
->will($this->returnValue([])); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdmin') |
|
|
|
|
->will($this->returnValue($subadmin)); |
|
|
|
|
|
|
|
|
|
$result = self::invokePrivate($this->container['UsersController'], 'formatUserForIndex', [$user]); |
|
|
|
|
$this->assertEquals($expectedResult, $result); |
|
|
|
@ -1386,10 +1499,17 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
) |
|
|
|
|
->will($this->returnValue('1')); |
|
|
|
|
|
|
|
|
|
$this->container['SubAdminFactory'] |
|
|
|
|
->method('getSubAdminsOfGroups') |
|
|
|
|
->with($user->getUID()) |
|
|
|
|
$subadmin = $this->getMockBuilder('\OC\SubAdmin') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$subadmin->expects($this->once()) |
|
|
|
|
->method('getSubAdminsGroups') |
|
|
|
|
->with($user) |
|
|
|
|
->will($this->returnValue([])); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdmin') |
|
|
|
|
->will($this->returnValue($subadmin)); |
|
|
|
|
|
|
|
|
|
$result = self::invokePrivate($this->container['UsersController'], 'formatUserForIndex', [$user]); |
|
|
|
|
$this->assertEquals($expectedResult, $result); |
|
|
|
@ -1409,10 +1529,17 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
|
|
|
|
|
$expectedResult['isRestoreDisabled'] = true; |
|
|
|
|
|
|
|
|
|
$this->container['SubAdminFactory'] |
|
|
|
|
->method('getSubAdminsOfGroups') |
|
|
|
|
->with($user->getUID()) |
|
|
|
|
$subadmin = $this->getMockBuilder('\OC\SubAdmin') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$subadmin->expects($this->once()) |
|
|
|
|
->method('getSubAdminsGroups') |
|
|
|
|
->with($user) |
|
|
|
|
->will($this->returnValue([])); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdmin') |
|
|
|
|
->will($this->returnValue($subadmin)); |
|
|
|
|
|
|
|
|
|
$result = self::invokePrivate($this->container['UsersController'], 'formatUserForIndex', [$user]); |
|
|
|
|
$this->assertEquals($expectedResult, $result); |
|
|
|
@ -1453,15 +1580,25 @@ class UsersControllerTest extends \Test\TestCase { |
|
|
|
|
|
|
|
|
|
$expectedResult['isRestoreDisabled'] = true; |
|
|
|
|
|
|
|
|
|
$this->container['SubAdminFactory'] |
|
|
|
|
->method('getSubAdminsOfGroups') |
|
|
|
|
->with($user->getUID()) |
|
|
|
|
$subadmin = $this->getMockBuilder('\OC\SubAdmin') |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$subadmin->expects($this->once()) |
|
|
|
|
->method('getSubAdminsGroups') |
|
|
|
|
->with($user) |
|
|
|
|
->will($this->returnValue([])); |
|
|
|
|
$this->container['GroupManager'] |
|
|
|
|
->expects($this->any()) |
|
|
|
|
->method('getSubAdmin') |
|
|
|
|
->will($this->returnValue($subadmin)); |
|
|
|
|
|
|
|
|
|
$result = self::invokePrivate($this->container['UsersController'], 'formatUserForIndex', [$user]); |
|
|
|
|
$this->assertEquals($expectedResult, $result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public function setEmailAddressData() { |
|
|
|
|
return [ |
|
|
|
|
/* mailAddress, isValid, expectsUpdate, expectsDelete, canChangeDisplayName, responseCode */ |
|
|
|
|