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\Middleware;
|
2013-08-17 13:16:48 +04:00
|
|
|
|
|
|
|
use OC\AppFramework\Http\Request;
|
2015-02-10 15:02:48 +03:00
|
|
|
use OCP\AppFramework\Http\Response;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\AppFramework\Middleware;
|
2017-10-24 16:26:53 +03:00
|
|
|
use OCP\IConfig;
|
2013-08-17 13:16:48 +04:00
|
|
|
|
2020-04-10 15:19:56 +03:00
|
|
|
class ChildMiddleware extends Middleware {
|
|
|
|
};
|
2013-08-17 13:16:48 +04:00
|
|
|
|
|
|
|
|
2014-11-11 01:30:38 +03:00
|
|
|
class MiddlewareTest extends \Test\TestCase {
|
2013-08-17 13:16:48 +04:00
|
|
|
|
2013-08-21 02:41:20 +04:00
|
|
|
/**
|
|
|
|
* @var Middleware
|
|
|
|
*/
|
2013-08-17 13:16:48 +04:00
|
|
|
private $middleware;
|
|
|
|
private $controller;
|
|
|
|
private $exception;
|
|
|
|
private $api;
|
2015-02-10 15:02:48 +03:00
|
|
|
/** @var Response */
|
|
|
|
private $response;
|
2013-08-17 13:16:48 +04:00
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2014-11-11 01:30:38 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
2013-08-17 13:16:48 +04:00
|
|
|
$this->middleware = new ChildMiddleware();
|
|
|
|
|
2016-07-10 15:17:26 +03:00
|
|
|
$this->api = $this->getMockBuilder('OC\AppFramework\DependencyInjection\DIContainer')
|
2014-05-28 04:12:01 +04:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2013-08-17 13:16:48 +04:00
|
|
|
|
2016-07-10 15:17:26 +03:00
|
|
|
$this->controller = $this->getMockBuilder('OCP\AppFramework\Controller')
|
|
|
|
->setMethods([])
|
|
|
|
->setConstructorArgs([
|
2015-02-09 13:41:48 +03:00
|
|
|
$this->api,
|
2015-02-10 15:02:48 +03:00
|
|
|
new Request(
|
|
|
|
[],
|
2016-07-10 15:17:26 +03:00
|
|
|
$this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(),
|
2017-10-24 16:26:53 +03:00
|
|
|
$this->getMockBuilder(IConfig::class)->getMock()
|
2015-02-10 15:02:48 +03:00
|
|
|
)
|
2016-07-10 15:17:26 +03:00
|
|
|
])->getMock();
|
2013-08-17 13:16:48 +04:00
|
|
|
$this->exception = new \Exception();
|
2016-07-10 15:17:26 +03:00
|
|
|
$this->response = $this->getMockBuilder('OCP\AppFramework\Http\Response')->getMock();
|
2013-08-17 13:16:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testBeforeController() {
|
2013-08-21 02:41:20 +04:00
|
|
|
$this->middleware->beforeController($this->controller, null);
|
|
|
|
$this->assertNull(null);
|
2013-08-17 13:16:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testAfterExceptionRaiseAgainWhenUnhandled() {
|
2018-01-24 20:10:16 +03:00
|
|
|
$this->expectException(\Exception::class);
|
|
|
|
$this->middleware->afterException($this->controller, null, $this->exception);
|
2013-08-17 13:16:48 +04: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);
|
|
|
|
}
|
|
|
|
}
|