summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-05-13 10:40:49 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-05-13 10:40:49 +0200
commita152e320f6aa98774950eb088588cd16387226f8 (patch)
tree4af5190252e9229dd90c84213fcad07950f65822 /tests
parentc06063255f8d93b32452e19819f39cb53d5d4ae3 (diff)
downloadnextcloud-server-a152e320f6aa98774950eb088588cd16387226f8.tar.gz
nextcloud-server-a152e320f6aa98774950eb088588cd16387226f8.zip
make it possible to omit parameters and use the default parameters from the controller method
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/appframework/http/DispatcherTest.php40
-rw-r--r--tests/lib/appframework/utility/ControllerMethodReflectorTest.php6
2 files changed, 37 insertions, 9 deletions
diff --git a/tests/lib/appframework/http/DispatcherTest.php b/tests/lib/appframework/http/DispatcherTest.php
index 2aef2911e2c..8117eec2075 100644
--- a/tests/lib/appframework/http/DispatcherTest.php
+++ b/tests/lib/appframework/http/DispatcherTest.php
@@ -40,11 +40,11 @@ class TestController extends Controller {
* @param int $int
* @param bool $bool
*/
- public function exec($int, $bool) {
+ public function exec($int, $bool, $test=4, $test2=1) {
$this->registerResponder('text', function($in) {
return new JSONResponse(array('text' => $in));
});
- return array($int, $bool);
+ return array($int, $bool, $test, $test2);
}
}
@@ -262,6 +262,7 @@ class DispatcherTest extends \PHPUnit_Framework_TestCase {
}));
}
+
public function testControllerParametersInjected() {
$this->request = new Request(array(
'post' => array(
@@ -280,10 +281,34 @@ class DispatcherTest extends \PHPUnit_Framework_TestCase {
$this->dispatcherPassthrough();
$response = $this->dispatcher->dispatch($controller, 'exec');
- $this->assertEquals('[3,true]', $response[2]);
+ $this->assertEquals('[3,true,4,1]', $response[2]);
+ }
+
+
+ public function testControllerParametersInjectedDefaultOverwritten() {
+ $this->request = new Request(array(
+ 'post' => array(
+ 'int' => '3',
+ 'bool' => 'false',
+ 'test2' => 7
+ ),
+ 'method' => 'POST'
+ ));
+ $this->dispatcher = new Dispatcher(
+ $this->http, $this->middlewareDispatcher, $this->reflector,
+ $this->request
+ );
+ $controller = new TestController('app', $this->request);
+
+ // reflector is supposed to be called once
+ $this->dispatcherPassthrough();
+ $response = $this->dispatcher->dispatch($controller, 'exec');
+
+ $this->assertEquals('[3,true,4,7]', $response[2]);
}
+
public function testResponseTransformedByUrlFormat() {
$this->request = new Request(array(
'post' => array(
@@ -305,7 +330,7 @@ class DispatcherTest extends \PHPUnit_Framework_TestCase {
$this->dispatcherPassthrough();
$response = $this->dispatcher->dispatch($controller, 'exec');
- $this->assertEquals('{"text":[3,false]}', $response[2]);
+ $this->assertEquals('{"text":[3,false,4,1]}', $response[2]);
}
@@ -331,7 +356,7 @@ class DispatcherTest extends \PHPUnit_Framework_TestCase {
$this->dispatcherPassthrough();
$response = $this->dispatcher->dispatch($controller, 'exec');
- $this->assertEquals('{"text":[3,false]}', $response[2]);
+ $this->assertEquals('{"text":[3,false,4,1]}', $response[2]);
}
@@ -359,7 +384,10 @@ class DispatcherTest extends \PHPUnit_Framework_TestCase {
$this->dispatcherPassthrough();
$response = $this->dispatcher->dispatch($controller, 'exec');
- $this->assertEquals('{"text":[3,true]}', $response[2]);
+ $this->assertEquals('{"text":[3,true,4,1]}', $response[2]);
}
+
+
+
}
diff --git a/tests/lib/appframework/utility/ControllerMethodReflectorTest.php b/tests/lib/appframework/utility/ControllerMethodReflectorTest.php
index cccc7688884..8939a203edb 100644
--- a/tests/lib/appframework/utility/ControllerMethodReflectorTest.php
+++ b/tests/lib/appframework/utility/ControllerMethodReflectorTest.php
@@ -88,7 +88,7 @@ class ControllerMethodReflectorTest extends \PHPUnit_Framework_TestCase {
}
- public function arguments($arg, $arg2) {}
+ public function arguments($arg, $arg2='hi') {}
public function testReflectParameters() {
$reader = new ControllerMethodReflector();
$reader->reflect(
@@ -96,7 +96,7 @@ class ControllerMethodReflectorTest extends \PHPUnit_Framework_TestCase {
'arguments'
);
- $this->assertEquals(array('arg', 'arg2'), $reader->getParameters());
+ $this->assertEquals(array('arg' => null, 'arg2' => 'hi'), $reader->getParameters());
}
@@ -108,7 +108,7 @@ class ControllerMethodReflectorTest extends \PHPUnit_Framework_TestCase {
'arguments2'
);
- $this->assertEquals(array('arg',), $reader->getParameters());
+ $this->assertEquals(array('arg' => null), $reader->getParameters());
}