aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/appframework/controller
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-05-06 16:29:19 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-05-11 17:54:08 +0200
commit80648da43197c91ed52f36cee8bc818038b88eb6 (patch)
treeea604192691d7b74857ed639311185de0d93504c /tests/lib/appframework/controller
parenta252f59cd436d2c005755955bc93ab44544df766 (diff)
downloadnextcloud-server-80648da43197c91ed52f36cee8bc818038b88eb6.tar.gz
nextcloud-server-80648da43197c91ed52f36cee8bc818038b88eb6.zip
implement most of the basic stuff that was suggested in #8290
Diffstat (limited to 'tests/lib/appframework/controller')
-rw-r--r--tests/lib/appframework/controller/ControllerTest.php55
1 files changed, 54 insertions, 1 deletions
diff --git a/tests/lib/appframework/controller/ControllerTest.php b/tests/lib/appframework/controller/ControllerTest.php
index b6c83125da1..4785c686f27 100644
--- a/tests/lib/appframework/controller/ControllerTest.php
+++ b/tests/lib/appframework/controller/ControllerTest.php
@@ -26,9 +26,31 @@ namespace OCP\AppFramework;
use OC\AppFramework\Http\Request;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\AppFramework\Http\JSONResponse;
+use OCP\AppFramework\Http\IResponseSerializer;
-class ChildController extends Controller {};
+class ToUpperCaseSerializer implements IResponseSerializer {
+ public function serialize($response) {
+ return array(strtoupper($response));
+ }
+}
+
+class ChildController extends Controller {
+ public function custom($in) {
+ $this->registerFormatter('json', function ($response) {
+ return new JSONResponse(array(strlen($response)));
+ });
+
+ return $in;
+ }
+
+ public function serializer($in) {
+ $this->registerSerializer(new ToUpperCaseSerializer());
+
+ return $in;
+ }
+};
class ControllerTest extends \PHPUnit_Framework_TestCase {
@@ -129,4 +151,35 @@ class ControllerTest extends \PHPUnit_Framework_TestCase {
}
+ /**
+ * @expectedException \DomainException
+ */
+ public function testFormatResonseInvalidFormat() {
+ $this->controller->formatResponse(null, 'test');
+ }
+
+
+ public function testFormat() {
+ $response = $this->controller->formatResponse(array('hi'), 'json');
+
+ $this->assertEquals(array('hi'), $response->getData());
+ }
+
+
+ public function testCustomFormatter() {
+ $response = $this->controller->custom('hi');
+ $response = $this->controller->formatResponse($response, 'json');
+
+ $this->assertEquals(array(2), $response->getData());
+ }
+
+
+ public function testCustomSerializer() {
+ $response = $this->controller->serializer('hi');
+ $response = $this->controller->formatResponse($response, 'json');
+
+ $this->assertEquals(array('HI'), $response->getData());
+ }
+
+
}