Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Mar 12, 2018
1 parent ae369e8 commit b9926ec
Showing 1 changed file with 43 additions and 13 deletions.
56 changes: 43 additions & 13 deletions tests/Settings/Controller/GroupsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OC\User\User;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IRequest;
Expand Down Expand Up @@ -66,6 +67,9 @@ public function testIndexSortByName() {
$firstGroup
->method('getGID')
->will($this->returnValue('firstGroup'));
$firstGroup
->method('getDisplayName')
->will($this->returnValue('1st group'));
$firstGroup
->method('count')
->will($this->returnValue(12));
Expand All @@ -74,6 +78,9 @@ public function testIndexSortByName() {
$secondGroup
->method('getGID')
->will($this->returnValue('secondGroup'));
$secondGroup
->method('getDisplayName')
->will($this->returnValue('2nd group'));
$secondGroup
->method('count')
->will($this->returnValue(25));
Expand All @@ -82,6 +89,9 @@ public function testIndexSortByName() {
$thirdGroup
->method('getGID')
->will($this->returnValue('thirdGroup'));
$thirdGroup
->method('getDisplayName')
->will($this->returnValue('3rd group'));
$thirdGroup
->method('count')
->will($this->returnValue(14));
Expand All @@ -90,6 +100,9 @@ public function testIndexSortByName() {
$fourthGroup
->method('getGID')
->will($this->returnValue('admin'));
$fourthGroup
->method('getDisplayName')
->will($this->returnValue('Administrators'));
$fourthGroup
->method('count')
->will($this->returnValue(18));
Expand Down Expand Up @@ -119,25 +132,25 @@ public function testIndexSortByName() {
'adminGroups' => array(
0 => array(
'id' => 'admin',
'name' => 'admin',
'name' => 'Administrators',
'usercount' => 0,//User count disabled 18,
)
),
'groups' =>
array(
0 => array(
'id' => 'firstGroup',
'name' => 'firstGroup',
'name' => '1st group',
'usercount' => 0,//User count disabled 12,
),
1 => array(
'id' => 'secondGroup',
'name' => 'secondGroup',
'name' => '2nd group',
'usercount' => 0,//User count disabled 25,
),
2 => array(
'id' => 'thirdGroup',
'name' => 'thirdGroup',
'name' => '3rd group',
'usercount' => 0,//User count disabled 14,
),
)
Expand All @@ -158,6 +171,9 @@ public function testIndexSortbyCount() {
$firstGroup
->method('getGID')
->will($this->returnValue('firstGroup'));
$firstGroup
->method('getDisplayName')
->will($this->returnValue('1st group'));
$firstGroup
->method('count')
->will($this->returnValue(12));
Expand All @@ -166,6 +182,9 @@ public function testIndexSortbyCount() {
$secondGroup
->method('getGID')
->will($this->returnValue('secondGroup'));
$secondGroup
->method('getDisplayName')
->will($this->returnValue('2nd group'));
$secondGroup
->method('count')
->will($this->returnValue(25));
Expand All @@ -174,6 +193,9 @@ public function testIndexSortbyCount() {
$thirdGroup
->method('getGID')
->will($this->returnValue('thirdGroup'));
$thirdGroup
->method('getDisplayName')
->will($this->returnValue('3rd group'));
$thirdGroup
->method('count')
->will($this->returnValue(14));
Expand All @@ -182,6 +204,9 @@ public function testIndexSortbyCount() {
$fourthGroup
->method('getGID')
->will($this->returnValue('admin'));
$fourthGroup
->method('getDisplayName')
->will($this->returnValue('Administrators'));
$fourthGroup
->method('count')
->will($this->returnValue(18));
Expand Down Expand Up @@ -212,25 +237,25 @@ public function testIndexSortbyCount() {
'adminGroups' => array(
0 => array(
'id' => 'admin',
'name' => 'admin',
'name' => 'Administrators',
'usercount' => 18,
)
),
'groups' =>
array(
0 => array(
'id' => 'secondGroup',
'name' => 'secondGroup',
'name' => '2nd group',
'usercount' => 25,
),
1 => array(
'id' => 'thirdGroup',
'name' => 'thirdGroup',
'name' => '3rd group',
'usercount' => 14,
),
2 => array(
'id' => 'firstGroup',
'name' => 'firstGroup',
'name' => '1st group',
'usercount' => 12,
),
)
Expand Down Expand Up @@ -264,15 +289,19 @@ public function testCreateSuccessful() {
->method('groupExists')
->with('NewGroup')
->will($this->returnValue(false));

$group = $this->createMock(IGroup::class);
$group->method('getDisplayName')
->willReturn('New group');
$this->groupManager
->expects($this->once())
->method('createGroup')
->with('NewGroup')
->will($this->returnValue(true));
->willReturn($group);

$expectedResponse = new DataResponse(
array(
'groupname' => 'NewGroup'
'groupname' => 'New group'
),
Http::STATUS_CREATED
);
Expand Down Expand Up @@ -304,13 +333,14 @@ public function testCreateUnsuccessful() {
}

public function testDestroySuccessful() {
$group = $this->getMockBuilder(Group::class)
->disableOriginalConstructor()->getMock();
$group = $this->createMock(IGroup::class);
$this->groupManager
->expects($this->once())
->method('get')
->with('ExistingGroup')
->will($this->returnValue($group));
$group->method('getDisplayName')
->willReturn('Existing group');
$group
->expects($this->once())
->method('delete')
Expand All @@ -319,7 +349,7 @@ public function testDestroySuccessful() {
$expectedResponse = new DataResponse(
array(
'status' => 'success',
'data' => array('groupname' => 'ExistingGroup')
'data' => array('groupname' => 'Existing group')
),
Http::STATUS_NO_CONTENT
);
Expand Down

0 comments on commit b9926ec

Please sign in to comment.