2013-08-17 13:16:48 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ownCloud - App Framework
|
|
|
|
*
|
|
|
|
* @author Bernhard Posselt
|
2014-05-07 00:25:05 +04:00
|
|
|
* @copyright 2012 Bernhard Posselt <dev@bernhard-posselt.com>
|
2013-08-17 13:16:48 +04:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-05-18 19:40:34 +03:00
|
|
|
namespace Test\AppFramework\Http;
|
2013-08-17 13:16:48 +04:00
|
|
|
|
2016-05-18 19:40:34 +03:00
|
|
|
use OC\AppFramework\Http\Dispatcher;
|
|
|
|
use OC\AppFramework\Http\Request;
|
2018-02-21 12:54:17 +03:00
|
|
|
use OC\AppFramework\Middleware\MiddlewareDispatcher;
|
2014-05-06 18:29:19 +04:00
|
|
|
use OC\AppFramework\Utility\ControllerMethodReflector;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\AppFramework\Controller;
|
2013-10-23 07:57:34 +04:00
|
|
|
use OCP\AppFramework\Http;
|
2014-10-28 18:34:04 +03:00
|
|
|
use OCP\AppFramework\Http\DataResponse;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\AppFramework\Http\JSONResponse;
|
2018-02-21 12:54:17 +03:00
|
|
|
use OCP\AppFramework\Http\Response;
|
2017-10-24 16:26:53 +03:00
|
|
|
use OCP\IConfig;
|
2014-05-06 18:29:19 +04:00
|
|
|
|
|
|
|
class TestController extends Controller {
|
2015-02-10 15:02:48 +03:00
|
|
|
/**
|
|
|
|
* @param string $appName
|
|
|
|
* @param \OCP\IRequest $request
|
|
|
|
*/
|
2014-05-06 18:29:19 +04:00
|
|
|
public function __construct($appName, $request) {
|
|
|
|
parent::__construct($appName, $request);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $int
|
|
|
|
* @param bool $bool
|
2015-02-10 15:02:48 +03:00
|
|
|
* @param int $test
|
|
|
|
* @param int $test2
|
|
|
|
* @return array
|
2014-05-06 18:29:19 +04:00
|
|
|
*/
|
2014-05-13 12:40:49 +04:00
|
|
|
public function exec($int, $bool, $test=4, $test2=1) {
|
2014-05-06 22:25:41 +04:00
|
|
|
$this->registerResponder('text', function($in) {
|
2014-05-06 18:29:19 +04:00
|
|
|
return new JSONResponse(array('text' => $in));
|
|
|
|
});
|
2014-05-13 12:40:49 +04:00
|
|
|
return array($int, $bool, $test, $test2);
|
2014-05-06 18:29:19 +04:00
|
|
|
}
|
2014-10-28 18:34:04 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $int
|
|
|
|
* @param bool $bool
|
2015-02-10 15:02:48 +03:00
|
|
|
* @param int $test
|
|
|
|
* @param int $test2
|
|
|
|
* @return DataResponse
|
2014-10-28 18:34:04 +03:00
|
|
|
*/
|
|
|
|
public function execDataResponse($int, $bool, $test=4, $test2=1) {
|
|
|
|
return new DataResponse(array(
|
|
|
|
'text' => array($int, $bool, $test, $test2)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2014-05-06 18:29:19 +04:00
|
|
|
}
|
2013-08-17 13:16:48 +04:00
|
|
|
|
|
|
|
|
2014-11-11 01:30:38 +03:00
|
|
|
class DispatcherTest extends \Test\TestCase {
|
2018-02-21 12:54:17 +03:00
|
|
|
/** @var MiddlewareDispatcher */
|
2013-08-17 13:16:48 +04:00
|
|
|
private $middlewareDispatcher;
|
2018-02-21 12:54:17 +03:00
|
|
|
/** @var Dispatcher */
|
2013-08-17 13:16:48 +04:00
|
|
|
private $dispatcher;
|
|
|
|
private $controllerMethod;
|
|
|
|
private $response;
|
2015-02-10 15:02:48 +03:00
|
|
|
private $request;
|
2013-08-17 13:16:48 +04:00
|
|
|
private $lastModified;
|
|
|
|
private $etag;
|
|
|
|
private $http;
|
2014-05-06 18:29:19 +04:00
|
|
|
private $reflector;
|
2013-08-17 13:16:48 +04:00
|
|
|
|
|
|
|
protected function setUp() {
|
2014-11-11 01:30:38 +03:00
|
|
|
parent::setUp();
|
2013-08-17 13:16:48 +04:00
|
|
|
$this->controllerMethod = 'test';
|
|
|
|
|
2013-10-07 13:25:50 +04:00
|
|
|
$app = $this->getMockBuilder(
|
|
|
|
'OC\AppFramework\DependencyInjection\DIContainer')
|
2013-08-17 13:16:48 +04:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$request = $this->getMockBuilder(
|
|
|
|
'\OC\AppFramework\Http\Request')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$this->http = $this->getMockBuilder(
|
2013-10-23 07:57:34 +04:00
|
|
|
'\OC\AppFramework\Http')
|
2013-08-17 13:16:48 +04:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$this->middlewareDispatcher = $this->getMockBuilder(
|
|
|
|
'\OC\AppFramework\Middleware\MiddlewareDispatcher')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-07-10 15:17:26 +03:00
|
|
|
$this->controller = $this->getMockBuilder(
|
|
|
|
'\OCP\AppFramework\Controller')
|
|
|
|
->setMethods([$this->controllerMethod])
|
|
|
|
->setConstructorArgs([$app, $request])
|
|
|
|
->getMock();
|
2014-10-28 18:34:04 +03:00
|
|
|
|
2014-05-06 18:29:19 +04:00
|
|
|
$this->request = $this->getMockBuilder(
|
|
|
|
'\OC\AppFramework\Http\Request')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$this->reflector = new ControllerMethodReflector();
|
|
|
|
|
2013-08-17 13:16:48 +04:00
|
|
|
$this->dispatcher = new Dispatcher(
|
2018-02-21 12:54:17 +03:00
|
|
|
$this->http,
|
|
|
|
$this->middlewareDispatcher,
|
|
|
|
$this->reflector,
|
2014-05-06 18:29:19 +04:00
|
|
|
$this->request
|
|
|
|
);
|
2014-10-28 18:34:04 +03:00
|
|
|
|
2018-02-21 12:54:17 +03:00
|
|
|
$this->response = $this->createMock(Response::class);
|
2013-08-17 13:16:48 +04:00
|
|
|
|
|
|
|
$this->lastModified = new \DateTime(null, new \DateTimeZone('GMT'));
|
|
|
|
$this->etag = 'hi';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-19 12:31:54 +04:00
|
|
|
/**
|
|
|
|
* @param string $out
|
|
|
|
* @param string $httpHeaders
|
|
|
|
*/
|
2014-10-28 18:34:04 +03:00
|
|
|
private function setMiddlewareExpectations($out=null,
|
2013-08-17 13:16:48 +04:00
|
|
|
$httpHeaders=null, $responseHeaders=array(),
|
|
|
|
$ex=false, $catchEx=true) {
|
|
|
|
|
|
|
|
if($ex) {
|
|
|
|
$exception = new \Exception();
|
|
|
|
$this->middlewareDispatcher->expects($this->once())
|
|
|
|
->method('beforeController')
|
2014-10-28 18:34:04 +03:00
|
|
|
->with($this->equalTo($this->controller),
|
2013-08-17 13:16:48 +04:00
|
|
|
$this->equalTo($this->controllerMethod))
|
|
|
|
->will($this->throwException($exception));
|
|
|
|
if($catchEx) {
|
|
|
|
$this->middlewareDispatcher->expects($this->once())
|
|
|
|
->method('afterException')
|
2014-10-28 18:34:04 +03:00
|
|
|
->with($this->equalTo($this->controller),
|
2013-08-17 13:16:48 +04:00
|
|
|
$this->equalTo($this->controllerMethod),
|
|
|
|
$this->equalTo($exception))
|
|
|
|
->will($this->returnValue($this->response));
|
|
|
|
} else {
|
|
|
|
$this->middlewareDispatcher->expects($this->once())
|
|
|
|
->method('afterException')
|
2014-10-28 18:34:04 +03:00
|
|
|
->with($this->equalTo($this->controller),
|
2013-08-17 13:16:48 +04:00
|
|
|
$this->equalTo($this->controllerMethod),
|
|
|
|
$this->equalTo($exception))
|
2018-02-21 12:54:17 +03:00
|
|
|
->willThrowException($exception);
|
2013-08-17 13:16:48 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->middlewareDispatcher->expects($this->once())
|
|
|
|
->method('beforeController')
|
2014-10-28 18:34:04 +03:00
|
|
|
->with($this->equalTo($this->controller),
|
2013-08-17 13:16:48 +04:00
|
|
|
$this->equalTo($this->controllerMethod));
|
|
|
|
$this->controller->expects($this->once())
|
|
|
|
->method($this->controllerMethod)
|
|
|
|
->will($this->returnValue($this->response));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->response->expects($this->once())
|
|
|
|
->method('render')
|
|
|
|
->will($this->returnValue($out));
|
|
|
|
$this->response->expects($this->once())
|
|
|
|
->method('getStatus')
|
|
|
|
->will($this->returnValue(Http::STATUS_OK));
|
|
|
|
$this->response->expects($this->once())
|
|
|
|
->method('getLastModified')
|
|
|
|
->will($this->returnValue($this->lastModified));
|
|
|
|
$this->response->expects($this->once())
|
|
|
|
->method('getETag')
|
|
|
|
->will($this->returnValue($this->etag));
|
|
|
|
$this->response->expects($this->once())
|
|
|
|
->method('getHeaders')
|
|
|
|
->will($this->returnValue($responseHeaders));
|
|
|
|
$this->http->expects($this->once())
|
|
|
|
->method('getStatusHeader')
|
2014-10-28 18:34:04 +03:00
|
|
|
->with($this->equalTo(Http::STATUS_OK),
|
2013-08-17 13:16:48 +04:00
|
|
|
$this->equalTo($this->lastModified),
|
|
|
|
$this->equalTo($this->etag))
|
|
|
|
->will($this->returnValue($httpHeaders));
|
2014-10-28 18:34:04 +03:00
|
|
|
|
2013-08-17 13:16:48 +04:00
|
|
|
$this->middlewareDispatcher->expects($this->once())
|
|
|
|
->method('afterController')
|
2014-10-28 18:34:04 +03:00
|
|
|
->with($this->equalTo($this->controller),
|
2013-08-17 13:16:48 +04:00
|
|
|
$this->equalTo($this->controllerMethod),
|
|
|
|
$this->equalTo($this->response))
|
|
|
|
->will($this->returnValue($this->response));
|
|
|
|
|
|
|
|
$this->middlewareDispatcher->expects($this->once())
|
|
|
|
->method('afterController')
|
2014-10-28 18:34:04 +03:00
|
|
|
->with($this->equalTo($this->controller),
|
2013-08-17 13:16:48 +04:00
|
|
|
$this->equalTo($this->controllerMethod),
|
|
|
|
$this->equalTo($this->response))
|
|
|
|
->will($this->returnValue($this->response));
|
|
|
|
|
|
|
|
$this->middlewareDispatcher->expects($this->once())
|
|
|
|
->method('beforeOutput')
|
2014-10-28 18:34:04 +03:00
|
|
|
->with($this->equalTo($this->controller),
|
2013-08-17 13:16:48 +04:00
|
|
|
$this->equalTo($this->controllerMethod),
|
|
|
|
$this->equalTo($out))
|
2014-10-28 18:34:04 +03:00
|
|
|
->will($this->returnValue($out));
|
2013-08-17 13:16:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testDispatcherReturnsArrayWith2Entries() {
|
2018-02-21 12:54:17 +03:00
|
|
|
$this->setMiddlewareExpectations('');
|
2013-08-17 13:16:48 +04:00
|
|
|
|
2018-02-21 12:54:17 +03:00
|
|
|
$response = $this->dispatcher->dispatch($this->controller, $this->controllerMethod);
|
2013-08-17 13:16:48 +04:00
|
|
|
$this->assertNull($response[0]);
|
|
|
|
$this->assertEquals(array(), $response[1]);
|
|
|
|
$this->assertNull($response[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testHeadersAndOutputAreReturned(){
|
|
|
|
$out = 'yo';
|
|
|
|
$httpHeaders = 'Http';
|
|
|
|
$responseHeaders = array('hell' => 'yeah');
|
2014-05-06 18:29:19 +04:00
|
|
|
$this->setMiddlewareExpectations($out, $httpHeaders, $responseHeaders);
|
2013-08-17 13:16:48 +04:00
|
|
|
|
2014-10-28 18:34:04 +03:00
|
|
|
$response = $this->dispatcher->dispatch($this->controller,
|
2013-08-17 13:16:48 +04:00
|
|
|
$this->controllerMethod);
|
|
|
|
|
|
|
|
$this->assertEquals($httpHeaders, $response[0]);
|
|
|
|
$this->assertEquals($responseHeaders, $response[1]);
|
2014-11-27 16:19:00 +03:00
|
|
|
$this->assertEquals($out, $response[3]);
|
2013-08-17 13:16:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testExceptionCallsAfterException() {
|
|
|
|
$out = 'yo';
|
|
|
|
$httpHeaders = 'Http';
|
|
|
|
$responseHeaders = array('hell' => 'yeah');
|
2014-10-28 18:34:04 +03:00
|
|
|
$this->setMiddlewareExpectations($out, $httpHeaders, $responseHeaders, true);
|
2013-08-17 13:16:48 +04:00
|
|
|
|
2014-10-28 18:34:04 +03:00
|
|
|
$response = $this->dispatcher->dispatch($this->controller,
|
2013-08-17 13:16:48 +04:00
|
|
|
$this->controllerMethod);
|
|
|
|
|
|
|
|
$this->assertEquals($httpHeaders, $response[0]);
|
|
|
|
$this->assertEquals($responseHeaders, $response[1]);
|
2014-11-27 16:19:00 +03:00
|
|
|
$this->assertEquals($out, $response[3]);
|
2013-08-17 13:16:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testExceptionThrowsIfCanNotBeHandledByAfterException() {
|
|
|
|
$out = 'yo';
|
|
|
|
$httpHeaders = 'Http';
|
2018-02-21 12:54:17 +03:00
|
|
|
$responseHeaders = ['hell' => 'yeah'];
|
2014-05-06 18:29:19 +04:00
|
|
|
$this->setMiddlewareExpectations($out, $httpHeaders, $responseHeaders, true, false);
|
2013-08-17 13:16:48 +04:00
|
|
|
|
2018-01-24 20:10:16 +03:00
|
|
|
$this->expectException(\Exception::class);
|
2018-02-21 12:54:17 +03:00
|
|
|
$this->dispatcher->dispatch(
|
|
|
|
$this->controller,
|
|
|
|
$this->controllerMethod
|
|
|
|
);
|
2013-08-17 13:16:48 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-05-06 18:29:19 +04:00
|
|
|
|
|
|
|
private function dispatcherPassthrough() {
|
|
|
|
$this->middlewareDispatcher->expects($this->once())
|
|
|
|
->method('beforeController');
|
|
|
|
$this->middlewareDispatcher->expects($this->once())
|
|
|
|
->method('afterController')
|
|
|
|
->will($this->returnCallback(function($a, $b, $in) {
|
|
|
|
return $in;
|
|
|
|
}));
|
|
|
|
$this->middlewareDispatcher->expects($this->once())
|
|
|
|
->method('beforeOutput')
|
|
|
|
->will($this->returnCallback(function($a, $b, $in) {
|
|
|
|
return $in;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2014-05-13 12:40:49 +04:00
|
|
|
|
2014-05-06 18:29:19 +04:00
|
|
|
public function testControllerParametersInjected() {
|
2015-02-09 13:41:48 +03:00
|
|
|
$this->request = new Request(
|
|
|
|
[
|
|
|
|
'post' => [
|
2014-05-06 18:29:19 +04:00
|
|
|
'int' => '3',
|
|
|
|
'bool' => 'false'
|
2015-02-09 13:41:48 +03:00
|
|
|
],
|
|
|
|
'method' => 'POST'
|
|
|
|
],
|
2016-07-10 15:17:26 +03:00
|
|
|
$this->getMockBuilder('\OCP\Security\ISecureRandom')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock(),
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->getMockBuilder(IConfig::class)
|
2016-07-10 15:17:26 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock()
|
2015-02-09 13:41:48 +03:00
|
|
|
);
|
2014-05-06 18:29:19 +04:00
|
|
|
$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');
|
|
|
|
|
2014-11-27 16:19:00 +03:00
|
|
|
$this->assertEquals('[3,true,4,1]', $response[3]);
|
2014-05-13 12:40:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testControllerParametersInjectedDefaultOverwritten() {
|
2015-02-09 13:41:48 +03:00
|
|
|
$this->request = new Request(
|
|
|
|
[
|
|
|
|
'post' => [
|
|
|
|
'int' => '3',
|
|
|
|
'bool' => 'false',
|
|
|
|
'test2' => 7
|
|
|
|
],
|
|
|
|
'method' => 'POST',
|
|
|
|
],
|
2016-07-10 15:17:26 +03:00
|
|
|
$this->getMockBuilder('\OCP\Security\ISecureRandom')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock(),
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->getMockBuilder(IConfig::class)
|
2016-07-10 15:17:26 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock()
|
2015-02-09 13:41:48 +03:00
|
|
|
);
|
2014-05-13 12:40:49 +04:00
|
|
|
$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');
|
|
|
|
|
2014-11-27 16:19:00 +03:00
|
|
|
$this->assertEquals('[3,true,4,7]', $response[3]);
|
2014-05-06 18:29:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-13 12:40:49 +04:00
|
|
|
|
2014-05-06 18:29:19 +04:00
|
|
|
public function testResponseTransformedByUrlFormat() {
|
2015-02-09 13:41:48 +03:00
|
|
|
$this->request = new Request(
|
|
|
|
[
|
|
|
|
'post' => [
|
|
|
|
'int' => '3',
|
|
|
|
'bool' => 'false'
|
|
|
|
],
|
|
|
|
'urlParams' => [
|
|
|
|
'format' => 'text'
|
|
|
|
],
|
|
|
|
'method' => 'GET'
|
|
|
|
],
|
2016-07-10 15:17:26 +03:00
|
|
|
$this->getMockBuilder('\OCP\Security\ISecureRandom')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock(),
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->getMockBuilder(IConfig::class)
|
2016-07-10 15:17:26 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock()
|
2015-02-09 13:41:48 +03:00
|
|
|
);
|
2014-05-06 18:29:19 +04:00
|
|
|
$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');
|
|
|
|
|
2014-11-27 16:19:00 +03:00
|
|
|
$this->assertEquals('{"text":[3,false,4,1]}', $response[3]);
|
2014-05-06 18:29:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-28 18:34:04 +03:00
|
|
|
public function testResponseTransformsDataResponse() {
|
2015-02-09 13:41:48 +03:00
|
|
|
$this->request = new Request(
|
|
|
|
[
|
|
|
|
'post' => [
|
|
|
|
'int' => '3',
|
|
|
|
'bool' => 'false'
|
|
|
|
],
|
|
|
|
'urlParams' => [
|
|
|
|
'format' => 'json'
|
|
|
|
],
|
|
|
|
'method' => 'GET'
|
|
|
|
],
|
2016-07-10 15:17:26 +03:00
|
|
|
$this->getMockBuilder('\OCP\Security\ISecureRandom')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock(),
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->getMockBuilder(IConfig::class)
|
2016-07-10 15:17:26 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock()
|
2015-02-09 13:41:48 +03:00
|
|
|
);
|
2014-10-28 18:34:04 +03:00
|
|
|
$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, 'execDataResponse');
|
|
|
|
|
2014-11-27 16:19:00 +03:00
|
|
|
$this->assertEquals('{"text":[3,false,4,1]}', $response[3]);
|
2014-10-28 18:34:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-06 18:29:19 +04:00
|
|
|
public function testResponseTransformedByAcceptHeader() {
|
2015-02-09 13:41:48 +03:00
|
|
|
$this->request = new Request(
|
|
|
|
[
|
|
|
|
'post' => [
|
|
|
|
'int' => '3',
|
|
|
|
'bool' => 'false'
|
|
|
|
],
|
|
|
|
'server' => [
|
|
|
|
'HTTP_ACCEPT' => 'application/text, test',
|
|
|
|
'HTTP_CONTENT_TYPE' => 'application/x-www-form-urlencoded'
|
|
|
|
],
|
|
|
|
'method' => 'PUT'
|
|
|
|
],
|
2016-07-10 15:17:26 +03:00
|
|
|
$this->getMockBuilder('\OCP\Security\ISecureRandom')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock(),
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->getMockBuilder(IConfig::class)
|
2016-07-10 15:17:26 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock()
|
2015-02-09 13:41:48 +03:00
|
|
|
);
|
2014-05-06 18:29:19 +04:00
|
|
|
$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');
|
|
|
|
|
2014-11-27 16:19:00 +03:00
|
|
|
$this->assertEquals('{"text":[3,false,4,1]}', $response[3]);
|
2014-05-06 18:29:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testResponsePrimarilyTransformedByParameterFormat() {
|
2015-02-09 13:41:48 +03:00
|
|
|
$this->request = new Request(
|
|
|
|
[
|
|
|
|
'post' => [
|
|
|
|
'int' => '3',
|
|
|
|
'bool' => 'false'
|
|
|
|
],
|
|
|
|
'get' => [
|
|
|
|
'format' => 'text'
|
|
|
|
],
|
|
|
|
'server' => [
|
|
|
|
'HTTP_ACCEPT' => 'application/json, test'
|
|
|
|
],
|
|
|
|
'method' => 'POST'
|
|
|
|
],
|
2016-07-10 15:17:26 +03:00
|
|
|
$this->getMockBuilder('\OCP\Security\ISecureRandom')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock(),
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->getMockBuilder(IConfig::class)
|
2016-07-10 15:17:26 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock()
|
2015-02-09 13:41:48 +03:00
|
|
|
);
|
2014-05-06 18:29:19 +04:00
|
|
|
$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');
|
|
|
|
|
2014-11-27 16:19:00 +03:00
|
|
|
$this->assertEquals('{"text":[3,true,4,1]}', $response[3]);
|
2014-05-06 18:29:19 +04:00
|
|
|
}
|
|
|
|
|
2014-05-13 12:40:49 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-17 13:16:48 +04:00
|
|
|
}
|