2018-08-11 23:46:28 +02:00
|
|
|
<?php
|
|
|
|
|
2023-02-03 20:41:59 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2018-08-11 23:46:28 +02:00
|
|
|
namespace Engelsystem\Test\Unit\Middleware;
|
|
|
|
|
2018-10-08 19:30:37 +02:00
|
|
|
use Engelsystem\Helpers\Authenticator;
|
2018-08-11 23:46:28 +02:00
|
|
|
use Engelsystem\Http\Request;
|
2024-04-21 21:09:54 +02:00
|
|
|
use Engelsystem\Http\Response;
|
2018-08-11 23:46:28 +02:00
|
|
|
use Engelsystem\Middleware\LegacyMiddleware;
|
2024-04-21 21:09:54 +02:00
|
|
|
use Engelsystem\Test\Unit\TestCase;
|
2019-04-24 10:45:00 +02:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2018-08-11 23:46:28 +02:00
|
|
|
use Psr\Http\Server\RequestHandlerInterface;
|
|
|
|
|
|
|
|
class LegacyMiddlewareTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Middleware\LegacyMiddleware::__construct
|
|
|
|
* @covers \Engelsystem\Middleware\LegacyMiddleware::process
|
|
|
|
*/
|
2024-04-21 21:09:54 +02:00
|
|
|
public function testRegisterNotFound(): void
|
2018-08-11 23:46:28 +02:00
|
|
|
{
|
2024-04-21 21:09:54 +02:00
|
|
|
/** @var RequestHandlerInterface|MockObject $handler */
|
|
|
|
$handler = $this->getMockForAbstractClass(RequestHandlerInterface::class);
|
2018-10-08 19:30:37 +02:00
|
|
|
/** @var Authenticator|MockObject $auth */
|
|
|
|
$auth = $this->createMock(Authenticator::class);
|
2024-04-21 21:09:54 +02:00
|
|
|
$response = new Response();
|
|
|
|
$request = new Request(['p' => 'foo']);
|
|
|
|
$this->app->instance('request', $request);
|
|
|
|
$this->mockTranslator();
|
|
|
|
|
2018-08-11 23:46:28 +02:00
|
|
|
/** @var LegacyMiddleware|MockObject $middleware */
|
|
|
|
$middleware = $this->getMockBuilder(LegacyMiddleware::class)
|
2024-04-21 21:09:54 +02:00
|
|
|
->setConstructorArgs([$this->app, $auth])
|
|
|
|
->onlyMethods(['renderPage'])
|
2018-08-11 23:46:28 +02:00
|
|
|
->getMock();
|
2024-04-21 21:09:54 +02:00
|
|
|
$middleware->expects($this->once())
|
|
|
|
->method('renderPage')
|
|
|
|
->with(404, 'page.404.title', 'page.404.text')
|
|
|
|
->willReturn($response);
|
|
|
|
|
|
|
|
$middleware->process($request, $handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Middleware\LegacyMiddleware::process
|
|
|
|
*/
|
|
|
|
public function testRegisterHasPermission(): void
|
|
|
|
{
|
2018-08-11 23:46:28 +02:00
|
|
|
/** @var RequestHandlerInterface|MockObject $handler */
|
|
|
|
$handler = $this->getMockForAbstractClass(RequestHandlerInterface::class);
|
2024-04-21 21:09:54 +02:00
|
|
|
/** @var Authenticator|MockObject $auth */
|
|
|
|
$auth = $this->createMock(Authenticator::class);
|
|
|
|
$auth->expects($this->exactly(2))
|
|
|
|
->method('can')
|
|
|
|
->withConsecutive(['users.arrive.list'], ['admin_arrive'])
|
|
|
|
->willReturnOnConsecutiveCalls(true, false);
|
|
|
|
$response = new Response();
|
|
|
|
$request = new Request([], [], [], [], [], ['REQUEST_URI' => 'admin-arrive']);
|
|
|
|
$this->app->instance('request', $request);
|
2018-08-11 23:46:28 +02:00
|
|
|
|
2024-04-21 21:09:54 +02:00
|
|
|
/** @var LegacyMiddleware|MockObject $middleware */
|
|
|
|
$middleware = $this->getMockBuilder(LegacyMiddleware::class)
|
|
|
|
->setConstructorArgs([$this->app, $auth])
|
|
|
|
->onlyMethods(['loadPage', 'renderPage'])
|
|
|
|
->getMock();
|
2018-11-21 12:17:28 +01:00
|
|
|
$middleware->expects($this->once())
|
2018-08-11 23:46:28 +02:00
|
|
|
->method('loadPage')
|
2024-04-21 21:09:54 +02:00
|
|
|
->with('admin_arrive')
|
2018-11-21 12:17:28 +01:00
|
|
|
->willReturn(['title', 'content']);
|
2024-04-21 21:09:54 +02:00
|
|
|
$middleware->expects($this->once())
|
2018-08-11 23:46:28 +02:00
|
|
|
->method('renderPage')
|
2024-04-21 21:09:54 +02:00
|
|
|
->with('admin_arrive', 'title', 'content')
|
2018-08-11 23:46:28 +02:00
|
|
|
->willReturn($response);
|
|
|
|
|
|
|
|
$middleware->process($request, $handler);
|
|
|
|
}
|
|
|
|
}
|