summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2014-12-08 15:32:59 +0100
committerLukas Reschke <lukas@owncloud.com>2014-12-08 15:32:59 +0100
commit8b3e3890628fa00d50c94af1131cbe3cd63e4a12 (patch)
treea07a6c8ae9353aa5dcc37e0510ecf5004b0cb42f /tests
parent3a49411051b3ad194b7296658c9177cbee82a74d (diff)
downloadnextcloud-server-8b3e3890628fa00d50c94af1131cbe3cd63e4a12.tar.gz
nextcloud-server-8b3e3890628fa00d50c94af1131cbe3cd63e4a12.zip
Add statuscodes
Diffstat (limited to 'tests')
-rw-r--r--tests/settings/controller/groupscontrollertest.php43
-rw-r--r--tests/settings/controller/userscontrollertest.php53
2 files changed, 86 insertions, 10 deletions
diff --git a/tests/settings/controller/groupscontrollertest.php b/tests/settings/controller/groupscontrollertest.php
index ac4619cfdb3..003fb70b811 100644
--- a/tests/settings/controller/groupscontrollertest.php
+++ b/tests/settings/controller/groupscontrollertest.php
@@ -11,6 +11,7 @@ namespace OC\Settings\Controller;
use OC\Group\Group;
use \OC\Settings\Application;
+use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
/**
@@ -145,7 +146,15 @@ class GroupsControllerTest extends \Test\TestCase {
->with('ExistingGroup')
->will($this->returnValue(true));
- $expectedResponse = new DataResponse(array('status' => 'error', 'data' => array('message' => 'Group already exists.')));
+ $expectedResponse = new DataResponse(
+ array(
+ 'status' => 'error',
+ 'data' => array(
+ 'message' => 'Group already exists.'
+ )
+ ),
+ Http::STATUS_CONFLICT
+ );
$response = $this->groupsController->create('ExistingGroup');
$this->assertEquals($expectedResponse, $response);
}
@@ -162,7 +171,13 @@ class GroupsControllerTest extends \Test\TestCase {
->with('NewGroup')
->will($this->returnValue(true));
- $expectedResponse = new DataResponse(array('status' => 'success', 'data' => array('groupname' => 'NewGroup')));
+ $expectedResponse = new DataResponse(
+ array(
+ 'status' => 'success',
+ 'data' => array('groupname' => 'NewGroup')
+ ),
+ Http::STATUS_CREATED
+ );
$response = $this->groupsController->create('NewGroup');
$this->assertEquals($expectedResponse, $response);
}
@@ -179,7 +194,13 @@ class GroupsControllerTest extends \Test\TestCase {
->with('NewGroup')
->will($this->returnValue(false));
- $expectedResponse = new DataResponse(array('status' => 'error', 'data' => array('message' => 'Unable to add group.')));
+ $expectedResponse = new DataResponse(
+ array(
+ 'status' => 'error',
+ 'data' => array('message' => 'Unable to add group.')
+ ),
+ Http::STATUS_FORBIDDEN
+ );
$response = $this->groupsController->create('NewGroup');
$this->assertEquals($expectedResponse, $response);
}
@@ -197,7 +218,13 @@ class GroupsControllerTest extends \Test\TestCase {
->method('delete')
->will($this->returnValue(true));
- $expectedResponse = new DataResponse(array('status' => 'success', 'data' => array('groupname' => 'ExistingGroup')));
+ $expectedResponse = new DataResponse(
+ array(
+ 'status' => 'success',
+ 'data' => array('groupname' => 'ExistingGroup')
+ ),
+ Http::STATUS_NO_CONTENT
+ );
$response = $this->groupsController->destroy('ExistingGroup');
$this->assertEquals($expectedResponse, $response);
}
@@ -209,7 +236,13 @@ class GroupsControllerTest extends \Test\TestCase {
->with('ExistingGroup')
->will($this->returnValue(null));
- $expectedResponse = new DataResponse(array('status' => 'error', 'data' => array('message' => 'Unable to delete group.')));
+ $expectedResponse = new DataResponse(
+ array(
+ 'status' => 'error',
+ 'data' => array('message' => 'Unable to delete group.')
+ ),
+ Http::STATUS_FORBIDDEN
+ );
$response = $this->groupsController->destroy('ExistingGroup');
$this->assertEquals($expectedResponse, $response);
}
diff --git a/tests/settings/controller/userscontrollertest.php b/tests/settings/controller/userscontrollertest.php
index 8aee2b2dd5a..0f1dfb4e685 100644
--- a/tests/settings/controller/userscontrollertest.php
+++ b/tests/settings/controller/userscontrollertest.php
@@ -10,6 +10,7 @@
namespace OC\Settings\Controller;
use \OC\Settings\Application;
+use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
/**
@@ -158,7 +159,8 @@ class UsersControllerTest extends \Test\TestCase {
'groups' => null,
'storageLocation' => '/home/user'
)
- )
+ ),
+ Http::STATUS_CREATED
);
$response = $this->usersController->create('foo', 'password', array());
$this->assertEquals($expectedResponse, $response);
@@ -217,7 +219,8 @@ class UsersControllerTest extends \Test\TestCase {
'groups' => array('NewGroup', 'ExistingGroup'),
'storageLocation' => '/home/user'
)
- )
+ ),
+ Http::STATUS_CREATED
);
$response = $this->usersController->create('foo', 'password', array('NewGroup', 'ExistingGroup'));
$this->assertEquals($expectedResponse, $response);
@@ -238,7 +241,8 @@ class UsersControllerTest extends \Test\TestCase {
'data' => array(
'message' => 'Unable to create user.'
)
- )
+ ),
+ Http::STATUS_FORBIDDEN
);
$response = $this->usersController->create('foo', 'password', array());
$this->assertEquals($expectedResponse, $response);
@@ -265,7 +269,8 @@ class UsersControllerTest extends \Test\TestCase {
'data' => array(
'message' => 'Unable to delete user.'
)
- )
+ ),
+ Http::STATUS_FORBIDDEN
);
$response = $this->usersController->destroy('myself');
$this->assertEquals($expectedResponse, $response);
@@ -302,7 +307,45 @@ class UsersControllerTest extends \Test\TestCase {
'data' => array(
'username' => 'UserToDelete'
)
- )
+ ),
+ Http::STATUS_NO_CONTENT
+ );
+ $response = $this->usersController->destroy('UserToDelete');
+ $this->assertEquals($expectedResponse, $response);
+ }
+ /**
+ * TODO: Since the function uses the static OC_Subadmin class it can't be mocked
+ * to test for subadmins. Thus the test always assumes you have admin permissions...
+ */
+ public function testDestroyUnsuccessful() {
+ $user = $this->getMockBuilder('\OC\User\User')
+ ->disableOriginalConstructor()->getMock();
+ $user
+ ->expects($this->once())
+ ->method('getUID')
+ ->will($this->returnValue('Admin'));
+ $toDeleteUser = $this->getMockBuilder('\OC\User\User')
+ ->disableOriginalConstructor()->getMock();
+ $toDeleteUser
+ ->expects($this->once())
+ ->method('delete')
+ ->will($this->returnValue(false));
+ $this->container['UserSession']
+ ->method('getUser')
+ ->will($this->returnValue($user));
+ $this->container['UserManager']
+ ->method('get')
+ ->with('UserToDelete')
+ ->will($this->returnValue($toDeleteUser));
+
+ $expectedResponse = new DataResponse(
+ array(
+ 'status' => 'error',
+ 'data' => array(
+ 'message' => 'Unable to delete user.'
+ )
+ ),
+ Http::STATUS_FORBIDDEN
);
$response = $this->usersController->destroy('UserToDelete');
$this->assertEquals($expectedResponse, $response);