Skip to content

Commit 8d0b451

Browse files
committed
[stable10] Data is not properly set in case of OCS Result object - now with tests
1 parent 3ed9e47 commit 8d0b451

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

lib/public/AppFramework/OCSController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ public function __construct($appName,
8484
private function buildOCSResponse($format, $data) {
8585
if ($data instanceof Result) {
8686
$headers = $data->getHeaders();
87+
$d = $data->getData();
8788
$data = $data->getMeta();
8889
$data['headers'] = $headers;
90+
$data['data'] = $d;
8991
}
9092
if ($data instanceof DataResponse) {
9193
$data = $data->getData();

tests/lib/AppFramework/Controller/OCSControllerTest.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
namespace Test\AppFramework\Controller;
2626

2727
use OC\AppFramework\Http\Request;
28+
use OC\OCS\Result;
2829
use OCP\AppFramework\Http\DataResponse;
2930
use OCP\AppFramework\OCSController;
3031
use OCP\IConfig;
@@ -135,8 +136,11 @@ public function testXMLDataResponse() {
135136
$this->assertEquals($expected, $out);
136137
}
137138

138-
139-
public function testJSON() {
139+
/**
140+
* @dataProvider providesData
141+
* @param $params
142+
*/
143+
public function testJSON($params) {
140144
$controller = new ChildOCSController('app', new Request(
141145
[
142146
'urlParams' => [
@@ -152,17 +156,24 @@ public function testJSON() {
152156
));
153157
$expected = '{"ocs":{"meta":{"status":"failure","statuscode":400,"message":"OK",' .
154158
'"totalitems":"","itemsperpage":""},"data":{"test":"hi"}}}';
155-
$params = [
156-
'data' => [
157-
'test' => 'hi'
158-
],
159-
'statuscode' => 400
160-
];
161159

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

164+
public function providesData() {
165+
return [
166+
'array' => [[
167+
'data' => [
168+
'test' => 'hi'
169+
],
170+
'statuscode' => 400]
171+
],
172+
'ocs-resuls' => [new Result([
173+
'test' => 'hi'
174+
], 400, 'OK')]
175+
];
176+
}
166177

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

0 commit comments

Comments
 (0)