2013-08-17 09:16:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ownCloud - App Framework
|
|
|
|
*
|
|
|
|
* @author Bernhard Posselt
|
2014-05-06 20:25:05 +00:00
|
|
|
* @copyright 2012 Bernhard Posselt <dev@bernhard-posselt.com>
|
2013-08-17 09:16:48 +00: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 16:40:34 +00:00
|
|
|
namespace Test\AppFramework\Middleware;
|
2013-08-17 09:16:48 +00:00
|
|
|
|
|
|
|
use OC\AppFramework\Http\Request;
|
2013-10-05 14:59:06 +00:00
|
|
|
use OCP\AppFramework\Middleware;
|
2015-02-10 12:02:48 +00:00
|
|
|
use OCP\AppFramework\Http\Response;
|
2017-10-24 13:26:53 +00:00
|
|
|
use OCP\IConfig;
|
2013-08-17 09:16:48 +00:00
|
|
|
|
|
|
|
class ChildMiddleware extends Middleware {};
|
|
|
|
|
|
|
|
|
2014-11-10 22:30:38 +00:00
|
|
|
class MiddlewareTest extends \Test\TestCase {
|
2013-08-17 09:16:48 +00:00
|
|
|
|
2013-08-20 22:41:20 +00:00
|
|
|
/**
|
|
|
|
* @var Middleware
|
|
|
|
*/
|
2013-08-17 09:16:48 +00:00
|
|
|
private $middleware;
|
|
|
|
private $controller;
|
|
|
|
private $exception;
|
|
|
|
private $api;
|
2015-02-10 12:02:48 +00:00
|
|
|
/** @var Response */
|
|
|
|
private $response;
|
2013-08-17 09:16:48 +00:00
|
|
|
|
|
|
|
protected function setUp(){
|
2014-11-10 22:30:38 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
2013-08-17 09:16:48 +00:00
|
|
|
$this->middleware = new ChildMiddleware();
|
|
|
|
|
2016-07-10 12:17:26 +00:00
|
|
|
$this->api = $this->getMockBuilder('OC\AppFramework\DependencyInjection\DIContainer')
|
2014-05-28 00:12:01 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2013-08-17 09:16:48 +00:00
|
|
|
|
2016-07-10 12:17:26 +00:00
|
|
|
$this->controller = $this->getMockBuilder('OCP\AppFramework\Controller')
|
|
|
|
->setMethods([])
|
|
|
|
->setConstructorArgs([
|
2015-02-09 10:41:48 +00:00
|
|
|
$this->api,
|
2015-02-10 12:02:48 +00:00
|
|
|
new Request(
|
|
|
|
[],
|
2016-07-10 12:17:26 +00:00
|
|
|
$this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(),
|
2017-10-24 13:26:53 +00:00
|
|
|
$this->getMockBuilder(IConfig::class)->getMock()
|
2015-02-10 12:02:48 +00:00
|
|
|
)
|
2016-07-10 12:17:26 +00:00
|
|
|
])->getMock();
|
2013-08-17 09:16:48 +00:00
|
|
|
$this->exception = new \Exception();
|
2016-07-10 12:17:26 +00:00
|
|
|
$this->response = $this->getMockBuilder('OCP\AppFramework\Http\Response')->getMock();
|
2013-08-17 09:16:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testBeforeController() {
|
2013-08-20 22:41:20 +00:00
|
|
|
$this->middleware->beforeController($this->controller, null);
|
|
|
|
$this->assertNull(null);
|
2013-08-17 09:16:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testAfterExceptionRaiseAgainWhenUnhandled() {
|
2018-01-24 17:10:16 +00:00
|
|
|
$this->expectException(\Exception::class);
|
|
|
|
$this->middleware->afterException($this->controller, null, $this->exception);
|
2013-08-17 09:16:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testAfterControllerReturnResponseWhenUnhandled() {
|
|
|
|
$response = $this->middleware->afterController($this->controller, null, $this->response);
|
|
|
|
|
|
|
|
$this->assertEquals($this->response, $response);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testBeforeOutputReturnOutputhenUnhandled() {
|
|
|
|
$output = $this->middleware->beforeOutput($this->controller, null, 'test');
|
|
|
|
|
|
|
|
$this->assertEquals('test', $output);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|