0
0
Fork 0
mirror of https://github.com/nextcloud/server.git synced 2025-04-30 20:10:40 +00:00
nextcloud_server/tests/lib/AppFramework/Middleware/MiddlewareTest.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
2 KiB
PHP
Raw Permalink Normal View History

2013-08-17 11:16:48 +02:00
<?php
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-or-later
2013-08-17 11:16:48 +02:00
*/
2016-05-18 18:40:34 +02:00
namespace Test\AppFramework\Middleware;
2013-08-17 11:16:48 +02:00
use OC\AppFramework\DependencyInjection\DIContainer;
2013-08-17 11:16:48 +02:00
use OC\AppFramework\Http\Request;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Middleware;
use OCP\IConfig;
use OCP\IRequestId;
2013-08-17 11:16:48 +02:00
class ChildMiddleware extends Middleware {
};
class MiddlewareTest extends \Test\TestCase {
/**
* @var Middleware
*/
2013-08-17 11:16:48 +02:00
private $middleware;
private $controller;
private $exception;
private $api;
/** @var Response */
private $response;
2013-08-17 11:16:48 +02:00
protected function setUp(): void {
parent::setUp();
2013-08-17 11:16:48 +02:00
$this->middleware = new ChildMiddleware();
$this->api = $this->getMockBuilder(DIContainer::class)
->disableOriginalConstructor()
->getMock();
2013-08-17 11:16:48 +02:00
$this->controller = $this->getMockBuilder(Controller::class)
->setMethods([])
->setConstructorArgs([
$this->api,
new Request(
[],
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
)
])->getMock();
2013-08-17 11:16:48 +02:00
$this->exception = new \Exception();
$this->response = $this->getMockBuilder(Response::class)->getMock();
2013-08-17 11:16:48 +02:00
}
public function testBeforeController(): void {
$this->middleware->beforeController($this->controller, '');
$this->assertNull(null);
2013-08-17 11:16:48 +02:00
}
public function testAfterExceptionRaiseAgainWhenUnhandled(): void {
$this->expectException(\Exception::class);
$this->middleware->afterException($this->controller, '', $this->exception);
2013-08-17 11:16:48 +02:00
}
public function testAfterControllerReturnResponseWhenUnhandled(): void {
$response = $this->middleware->afterController($this->controller, '', $this->response);
2013-08-17 11:16:48 +02:00
$this->assertEquals($this->response, $response);
}
public function testBeforeOutputReturnOutputhenUnhandled(): void {
$output = $this->middleware->beforeOutput($this->controller, '', 'test');
2013-08-17 11:16:48 +02:00
$this->assertEquals('test', $output);
}
}