diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-03-02 19:52:43 +0100 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-03-08 17:13:50 +0100 |
commit | 9440e9bb1e9079e9b6217788e89a398cc272320c (patch) | |
tree | 5715061b813d30ffdb0e18f23fba3e5502ec4af4 /tests/Settings/Controller | |
parent | e6a7a9f251cd77a7b571716bbc679687a548cc47 (diff) | |
download | nextcloud-server-9440e9bb1e9079e9b6217788e89a398cc272320c.tar.gz nextcloud-server-9440e9bb1e9079e9b6217788e89a398cc272320c.zip |
Fixed Controller Test
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'tests/Settings/Controller')
-rw-r--r-- | tests/Settings/Controller/GroupsControllerTest.php | 51 | ||||
-rw-r--r-- | tests/Settings/Controller/UsersControllerTest.php | 146 |
2 files changed, 144 insertions, 53 deletions
diff --git a/tests/Settings/Controller/GroupsControllerTest.php b/tests/Settings/Controller/GroupsControllerTest.php index ecbfa9ea05e..d43d4faf218 100644 --- a/tests/Settings/Controller/GroupsControllerTest.php +++ b/tests/Settings/Controller/GroupsControllerTest.php @@ -67,6 +67,9 @@ class GroupsControllerTest extends \Test\TestCase { ->method('getGID') ->will($this->returnValue('firstGroup')); $firstGroup + ->method('getDisplayName') + ->will($this->returnValue('First group')); + $firstGroup ->method('count') ->will($this->returnValue(12)); $secondGroup = $this->getMockBuilder(Group::class) @@ -75,6 +78,9 @@ class GroupsControllerTest extends \Test\TestCase { ->method('getGID') ->will($this->returnValue('secondGroup')); $secondGroup + ->method('getDisplayName') + ->will($this->returnValue('Second group')); + $secondGroup ->method('count') ->will($this->returnValue(25)); $thirdGroup = $this->getMockBuilder(Group::class) @@ -83,6 +89,9 @@ class GroupsControllerTest extends \Test\TestCase { ->method('getGID') ->will($this->returnValue('thirdGroup')); $thirdGroup + ->method('getDisplayName') + ->will($this->returnValue('Third group')); + $thirdGroup ->method('count') ->will($this->returnValue(14)); $fourthGroup = $this->getMockBuilder(Group::class) @@ -91,6 +100,9 @@ class GroupsControllerTest extends \Test\TestCase { ->method('getGID') ->will($this->returnValue('admin')); $fourthGroup + ->method('getDisplayName') + ->will($this->returnValue('Admin')); + $fourthGroup ->method('count') ->will($this->returnValue(18)); /** @var \OC\Group\Group[] $groups */ @@ -119,7 +131,7 @@ class GroupsControllerTest extends \Test\TestCase { 'adminGroups' => array( 0 => array( 'id' => 'admin', - 'name' => 'admin', + 'name' => 'Admin', 'usercount' => 0,//User count disabled 18, ) ), @@ -127,17 +139,17 @@ class GroupsControllerTest extends \Test\TestCase { array( 0 => array( 'id' => 'firstGroup', - 'name' => 'firstGroup', + 'name' => 'First group', 'usercount' => 0,//User count disabled 12, ), 1 => array( 'id' => 'secondGroup', - 'name' => 'secondGroup', + 'name' => 'Second group', 'usercount' => 0,//User count disabled 25, ), 2 => array( 'id' => 'thirdGroup', - 'name' => 'thirdGroup', + 'name' => 'Third group', 'usercount' => 0,//User count disabled 14, ), ) @@ -159,6 +171,9 @@ class GroupsControllerTest extends \Test\TestCase { ->method('getGID') ->will($this->returnValue('firstGroup')); $firstGroup + ->method('getDisplayName') + ->will($this->returnValue('First group')); + $firstGroup ->method('count') ->will($this->returnValue(12)); $secondGroup = $this->getMockBuilder(Group::class) @@ -167,6 +182,9 @@ class GroupsControllerTest extends \Test\TestCase { ->method('getGID') ->will($this->returnValue('secondGroup')); $secondGroup + ->method('getDisplayName') + ->will($this->returnValue('Second group')); + $secondGroup ->method('count') ->will($this->returnValue(25)); $thirdGroup = $this->getMockBuilder(Group::class) @@ -175,6 +193,9 @@ class GroupsControllerTest extends \Test\TestCase { ->method('getGID') ->will($this->returnValue('thirdGroup')); $thirdGroup + ->method('getDisplayName') + ->will($this->returnValue('Third group')); + $thirdGroup ->method('count') ->will($this->returnValue(14)); $fourthGroup = $this->getMockBuilder(Group::class) @@ -183,6 +204,9 @@ class GroupsControllerTest extends \Test\TestCase { ->method('getGID') ->will($this->returnValue('admin')); $fourthGroup + ->method('getDisplayName') + ->will($this->returnValue('Admin')); + $fourthGroup ->method('count') ->will($this->returnValue(18)); /** @var \OC\Group\Group[] $groups */ @@ -212,7 +236,7 @@ class GroupsControllerTest extends \Test\TestCase { 'adminGroups' => array( 0 => array( 'id' => 'admin', - 'name' => 'admin', + 'name' => 'Admin', 'usercount' => 18, ) ), @@ -220,17 +244,17 @@ class GroupsControllerTest extends \Test\TestCase { array( 0 => array( 'id' => 'secondGroup', - 'name' => 'secondGroup', + 'name' => 'Second group', 'usercount' => 25, ), 1 => array( 'id' => 'thirdGroup', - 'name' => 'thirdGroup', + 'name' => 'Third group', 'usercount' => 14, ), 2 => array( 'id' => 'firstGroup', - 'name' => 'firstGroup', + 'name' => 'First group', 'usercount' => 12, ), ) @@ -259,6 +283,8 @@ class GroupsControllerTest extends \Test\TestCase { } public function testCreateSuccessful() { + $group = $this->getMockBuilder(Group::class) + ->disableOriginalConstructor()->getMock(); $this->groupManager ->expects($this->once()) ->method('groupExists') @@ -268,7 +294,11 @@ class GroupsControllerTest extends \Test\TestCase { ->expects($this->once()) ->method('createGroup') ->with('NewGroup') - ->will($this->returnValue(true)); + ->will($this->returnValue($group)); + $group + ->expects($this->once()) + ->method('getDisplayName') + ->will($this->returnValue('NewGroup')); $expectedResponse = new DataResponse( array( @@ -315,6 +345,9 @@ class GroupsControllerTest extends \Test\TestCase { ->expects($this->once()) ->method('delete') ->will($this->returnValue(true)); + $group + ->method('getDisplayName') + ->will($this->returnValue('ExistingGroup')); $expectedResponse = new DataResponse( array( diff --git a/tests/Settings/Controller/UsersControllerTest.php b/tests/Settings/Controller/UsersControllerTest.php index 1b59f15efb0..165431516ed 100644 --- a/tests/Settings/Controller/UsersControllerTest.php +++ b/tests/Settings/Controller/UsersControllerTest.php @@ -206,7 +206,7 @@ class UsersControllerTest extends \Test\TestCase { $foo ->expects($this->exactly(2)) ->method('getQuota') - ->will($this->returnValue('1024')); + ->will($this->returnValue(1024)); $foo ->method('getLastLogin') ->will($this->returnValue(500)); @@ -236,7 +236,7 @@ class UsersControllerTest extends \Test\TestCase { $admin ->expects($this->exactly(2)) ->method('getQuota') - ->will($this->returnValue('404')); + ->will($this->returnValue(404)); $admin ->expects($this->once()) ->method('getLastLogin') @@ -268,7 +268,7 @@ class UsersControllerTest extends \Test\TestCase { $bar ->expects($this->exactly(2)) ->method('getQuota') - ->will($this->returnValue('2323')); + ->will($this->returnValue(2323)); $bar ->method('getLastLogin') ->will($this->returnValue(3999)); @@ -296,8 +296,20 @@ class UsersControllerTest extends \Test\TestCase { ->will($this->returnValue(array('foo' => 'M. Foo', 'admin' => 'S. Admin', 'bar' => 'B. Ar'))); $this->groupManager ->expects($this->exactly(3)) - ->method('getUserGroupIds') - ->will($this->onConsecutiveCalls(array('Users', 'Support'), array('admins', 'Support'), array('External Users'))); + ->method('getUserGroupNames') + ->will($this->onConsecutiveCalls( + array( + 'Users' => array('displayName' => 'Users'), + 'Support' => array('displayName' => 'Support') + ), + array( + 'admins' => array('displayName' => 'admins'), + 'Support' => array('displayName' => 'Support') + ), + array( + 'External Users' => array('displayName' => 'External Users') + ) + )); $this->userManager ->expects($this->at(0)) ->method('get') @@ -319,17 +331,17 @@ class UsersControllerTest extends \Test\TestCase { ->getMock(); $subadmin ->expects($this->any()) - ->method('getSubAdminsGroups') + ->method('getSubAdminsGroupsName') ->with($foo) ->will($this->returnValue([])); $subadmin ->expects($this->any()) - ->method('getSubAdminsGroups') + ->method('getSubAdminsGroupsName') ->with($admin) ->will($this->returnValue([])); $subadmin ->expects($this->any()) - ->method('getSubAdminsGroups') + ->method('getSubAdminsGroupsName') ->with($bar) ->will($this->returnValue([])); $this->groupManager @@ -347,10 +359,13 @@ class UsersControllerTest extends \Test\TestCase { 0 => array( 'name' => 'foo', 'displayname' => 'M. Foo', - 'groups' => array('Users', 'Support'), + 'groups' => array( + 'Users' => array('displayName' => 'Users'), + 'Support' => array('displayName' => 'Support') + ), 'subadmin' => array(), 'quota' => 1024, - 'quota_bytes' => 1024, + 'quota_bytes' => 1024.0, 'storageLocation' => '/home/foo', 'lastLogin' => 500000, 'backend' => 'OC_User_Database', @@ -363,10 +378,13 @@ class UsersControllerTest extends \Test\TestCase { 1 => array( 'name' => 'admin', 'displayname' => 'S. Admin', - 'groups' => array('admins', 'Support'), + 'groups' => array( + 'admins' => array('displayName' => 'admins'), + 'Support' => array('displayName' => 'Support') + ), 'subadmin' => array(), 'quota' => 404, - 'quota_bytes' => 404, + 'quota_bytes' => 404.0, 'storageLocation' => '/home/admin', 'lastLogin' => 12000, 'backend' => Dummy::class, @@ -379,10 +397,12 @@ class UsersControllerTest extends \Test\TestCase { 2 => array( 'name' => 'bar', 'displayname' => 'B. Ar', - 'groups' => array('External Users'), + 'groups' => array( + 'External Users' => array('displayName' => 'External Users') + ), 'subadmin' => array(), 'quota' => 2323, - 'quota_bytes' => 2323, + 'quota_bytes' => 2323.0, 'storageLocation' => '/home/bar', 'lastLogin' => 3999000, 'backend' => Dummy::class, @@ -555,6 +575,10 @@ class UsersControllerTest extends \Test\TestCase { ->will($this->returnValue([$subgroup1, $subgroup2])); $subadmin ->expects($this->any()) + ->method('getSubAdminsGroupsName') + ->will($this->returnValue([])); + $subadmin + ->expects($this->any()) ->method('getSubAdminsGroups') ->will($this->returnValue([])); $this->groupManager @@ -574,8 +598,8 @@ class UsersControllerTest extends \Test\TestCase { 'displayname' => 'B. Ar', 'groups' => ['SubGroup1'], 'subadmin' => [], - 'quota' => 2323, - 'quota_bytes' => 2323, + 'quota' => '2323', + 'quota_bytes' => 2323.0, 'storageLocation' => '/home/bar', 'lastLogin' => 3999000, 'backend' => Dummy::class, @@ -590,8 +614,8 @@ class UsersControllerTest extends \Test\TestCase { 'displayname' => 'M. Foo', 'groups' => ['SubGroup2', 'SubGroup1'], 'subadmin' => [], - 'quota' => 1024, - 'quota_bytes' => 1024, + 'quota' => '1024', + 'quota_bytes' => 1024.0, 'storageLocation' => '/home/foo', 'lastLogin' => 500000, 'backend' => 'OC_User_Database', @@ -606,8 +630,8 @@ class UsersControllerTest extends \Test\TestCase { 'displayname' => 'S. Admin', 'groups' => ['SubGroup2'], 'subadmin' => [], - 'quota' => 404, - 'quota_bytes' => 404, + 'quota' => '404', + 'quota_bytes' => 404.0, 'storageLocation' => '/home/admin', 'lastLogin' => 12000, 'backend' => Dummy::class, @@ -731,14 +755,26 @@ class UsersControllerTest extends \Test\TestCase { ->will($this->returnValue([$foo, $admin, $bar])); $this->groupManager ->expects($this->exactly(3)) - ->method('getUserGroupIds') - ->will($this->onConsecutiveCalls(array('Users', 'Support'), array('admins', 'Support'), array('External Users'))); + ->method('getUserGroupNames') + ->will($this->onConsecutiveCalls( + array( + 'Users' => array('displayName' => 'Users'), + 'Support' => array('displayName' => 'Support') + ), + array( + 'admins' => array('displayName' => 'admins'), + 'Support' => array('displayName' => 'Support') + ), + array( + 'External Users' => array('displayName' => 'External Users') + ) + )); $subadmin = $this->getMockBuilder(SubAdmin::class) ->disableOriginalConstructor() ->getMock(); $subadmin->expects($this->any()) - ->method('getSubAdminsGroups') + ->method('getSubAdminsGroupsName') ->will($this->returnValue([])); $this->groupManager ->expects($this->any()) @@ -755,7 +791,10 @@ class UsersControllerTest extends \Test\TestCase { 0 => array( 'name' => 'foo', 'displayname' => 'M. Foo', - 'groups' => array('Users', 'Support'), + 'groups' => array( + 'Users' => array('displayName' => 'Users'), + 'Support' => array('displayName' => 'Support') + ), 'subadmin' => array(), 'quota' => 1024, 'quota_bytes' => 1024, @@ -771,7 +810,10 @@ class UsersControllerTest extends \Test\TestCase { 1 => array( 'name' => 'admin', 'displayname' => 'S. Admin', - 'groups' => array('admins', 'Support'), + 'groups' => array( + 'admins' => array('displayName' => 'admins'), + 'Support' => array('displayName' => 'Support') + ), 'subadmin' => array(), 'quota' => 404, 'quota_bytes' => 404, @@ -787,7 +829,9 @@ class UsersControllerTest extends \Test\TestCase { 2 => array( 'name' => 'bar', 'displayname' => 'B. Ar', - 'groups' => array('External Users'), + 'groups' => array( + 'External Users' => array('displayName' => 'External Users') + ), 'subadmin' => array(), 'quota' => 2323, 'quota_bytes' => 2323, @@ -857,7 +901,7 @@ class UsersControllerTest extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); $subadmin->expects($this->once()) - ->method('getSubAdminsGroups') + ->method('getSubAdminsGroupsName') ->will($this->returnValue([])); $this->groupManager ->expects($this->any()) @@ -944,7 +988,7 @@ class UsersControllerTest extends \Test\TestCase { ->getMock(); $subadmin ->expects($this->any()) - ->method('getSubAdminsGroups') + ->method('getSubAdminsGroupsName') ->with($user) ->will($this->returnValue([])); $this->groupManager @@ -1022,16 +1066,21 @@ class UsersControllerTest extends \Test\TestCase { ->will($this->onConsecutiveCalls($newGroup)); $this->groupManager ->expects($this->once()) - ->method('getUserGroupIds') + ->method('getUserGroupNames') ->with($user) - ->will($this->onConsecutiveCalls(array('NewGroup', 'ExistingGroup'))); + ->will($this->onConsecutiveCalls( + array( + 'NewGroup' => array('displayName' => 'NewGroup'), + 'ExistingGroup' => array('displayName' => 'ExistingGroup') + ) + )); $subadmin = $this->getMockBuilder(SubAdmin::class) ->disableOriginalConstructor() ->getMock(); $subadmin ->expects($this->once()) - ->method('getSubAdminsGroups') + ->method('getSubAdminsGroupsName') ->with($user) ->will($this->returnValue([])); $this->groupManager @@ -1042,7 +1091,10 @@ class UsersControllerTest extends \Test\TestCase { $expectedResponse = new DataResponse( array( 'name' => 'foo', - 'groups' => array('NewGroup', 'ExistingGroup'), + 'groups' => array( + 'NewGroup' => array('displayName' => 'NewGroup'), + 'ExistingGroup' => array('displayName' => 'ExistingGroup') + ), 'storageLocation' => '/home/user', 'backend' => 'bar', 'lastLogin' => null, @@ -1100,18 +1152,20 @@ class UsersControllerTest extends \Test\TestCase { ->will($this->returnValue($newUser)); $this->groupManager ->expects($this->once()) - ->method('getUserGroupIds') + ->method('getUserGroupNames') ->with($user) - ->will($this->onConsecutiveCalls(['SubGroup1'])); + ->will($this->onConsecutiveCalls(array('SubGroup1' => + array('displayName' => 'SubGroup1') + ))); $this->groupManager ->expects($this->once()) - ->method('getUserGroupIds') + ->method('getUserGroupNames') ->with($newUser) ->will($this->onConsecutiveCalls(['SubGroup1'])); $subadmin = $this->createMock(\OC\SubAdmin::class); $subadmin->expects($this->atLeastOnce()) - ->method('getSubAdminsGroups') + ->method('getSubAdminsGroupsName') ->with($user) ->willReturnMap([ [$user, [$subGroup1]], @@ -1135,7 +1189,7 @@ class UsersControllerTest extends \Test\TestCase { $expectedResponse = new DataResponse( array( 'name' => 'foo', - 'groups' => ['SubGroup1'], + 'groups' => array('SubGroup1' => array('displayName' => 'SubGroup1')), 'storageLocation' => '/home/user', 'backend' => 'bar', 'lastLogin' => 0, @@ -1563,7 +1617,7 @@ class UsersControllerTest extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); $subadmin->expects($this->once()) - ->method('getSubAdminsGroups') + ->method('getSubAdminsGroupsName') ->with($user) ->will($this->returnValue([])); $this->groupManager @@ -1629,7 +1683,7 @@ class UsersControllerTest extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); $subadmin->expects($this->once()) - ->method('getSubAdminsGroups') + ->method('getSubAdminsGroupsName') ->with($user) ->will($this->returnValue([])); $this->groupManager @@ -1676,7 +1730,7 @@ class UsersControllerTest extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); $subadmin->expects($this->once()) - ->method('getSubAdminsGroups') + ->method('getSubAdminsGroupsName') ->with($user) ->will($this->returnValue([])); $this->groupManager @@ -1714,7 +1768,7 @@ class UsersControllerTest extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); $subadmin->expects($this->once()) - ->method('getSubAdminsGroups') + ->method('getSubAdminsGroupsName') ->with($user) ->will($this->returnValue([])); $this->groupManager @@ -1771,7 +1825,7 @@ class UsersControllerTest extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); $subadmin->expects($this->once()) - ->method('getSubAdminsGroups') + ->method('getSubAdminsGroupsName') ->with($user) ->will($this->returnValue([])); $this->groupManager @@ -1793,7 +1847,7 @@ class UsersControllerTest extends \Test\TestCase { ->disableOriginalConstructor() ->getMock(); $subadmin->expects($this->once()) - ->method('getSubAdminsGroups') + ->method('getSubAdminsGroupsName') ->with($user) ->will($this->returnValue([])); $this->groupManager @@ -1860,6 +1914,10 @@ class UsersControllerTest extends \Test\TestCase { ->getMock(); $subadmin ->expects($this->at(0)) + ->method('getSubAdminsGroupsName') + ->will($this->returnValue([$group1, $group2])); + $subadmin + ->expects($this->at(0)) ->method('getSubAdminsGroups') ->will($this->returnValue([$group1, $group2])); @@ -2430,7 +2488,7 @@ class UsersControllerTest extends \Test\TestCase { ->getMock(); $subadmin ->expects($this->any()) - ->method('getSubAdminsGroups') + ->method('getSubAdminsGroupsName') ->with($user) ->will($this->returnValue([])); $this->groupManager |