Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/public/AppFramework/OCSController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ public function __construct($appName,
private function buildOCSResponse($format, $data) {
if ($data instanceof Result) {
$headers = $data->getHeaders();
$d = $data->getData();
$data = $data->getMeta();
$data['headers'] = $headers;
$data['data'] = $d;
}
if ($data instanceof DataResponse) {
$data = $data->getData();
Expand Down
27 changes: 19 additions & 8 deletions tests/lib/AppFramework/Controller/OCSControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
namespace Test\AppFramework\Controller;

use OC\AppFramework\Http\Request;
use OC\OCS\Result;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\IConfig;
Expand Down Expand Up @@ -135,8 +136,11 @@ public function testXMLDataResponse() {
$this->assertEquals($expected, $out);
}


public function testJSON() {
/**
* @dataProvider providesData
* @param $params
*/
public function testJSON($params) {
$controller = new ChildOCSController('app', new Request(
[
'urlParams' => [
Expand All @@ -152,17 +156,24 @@ public function testJSON() {
));
$expected = '{"ocs":{"meta":{"status":"failure","statuscode":400,"message":"OK",' .
'"totalitems":"","itemsperpage":""},"data":{"test":"hi"}}}';
$params = [
'data' => [
'test' => 'hi'
],
'statuscode' => 400
];

$out = $controller->buildResponse($params, 'json')->render();
$this->assertEquals($expected, $out);
}

public function providesData() {
return [
'array' => [[
'data' => [
'test' => 'hi'
],
'statuscode' => 400]
],
'ocs-resuls' => [new Result([
'test' => 'hi'
], 400, 'OK')]
];
}

public function testStatusCodeMapping() {
$configMock = $this->createMock(IConfig::class);
Expand Down