3 declare(strict_types
=1);
5 namespace Shaarli\Front\Controller\Visitor
;
9 use Slim\Http\Response
;
12 class ErrorNotFoundControllerTest
extends TestCase
14 use FrontControllerMockHelper
;
16 /** @var ErrorNotFoundController */
17 protected $controller;
19 public function setUp(): void
21 $this->createContainer();
23 $this->controller
= new ErrorNotFoundController($this->container
);
27 * Test displaying 404 error
29 public function testDisplayNotFoundError(): void
31 $request = $this->createMock(Request
::class);
32 $request->expects(static::once())->method('getRequestTarget')->willReturn('/');
33 $request->method('getUri')->willReturnCallback(function (): Uri
{
34 $uri = $this->createMock(Uri
::class);
35 $uri->method('getBasePath')->willReturn('/subfolder');
40 $response = new Response();
42 // Save RainTPL assigned variables
43 $assignedVariables = [];
44 $this->assignTemplateVars($assignedVariables);
46 $result = ($this->controller
)(
51 static::assertSame(404, $result->getStatusCode());
52 static::assertSame('404', (string) $result->getBody());
53 static::assertSame('Requested page could not be found.', $assignedVariables['error_message']);
57 * Test displaying 404 error from REST API
59 public function testDisplayNotFoundErrorFromAPI(): void
61 $request = $this->createMock(Request
::class);
62 $request->expects(static::once())->method('getRequestTarget')->willReturn('/sufolder/api/v1/links');
63 $request->method('getUri')->willReturnCallback(function (): Uri
{
64 $uri = $this->createMock(Uri
::class);
65 $uri->method('getBasePath')->willReturn('/subfolder');
70 $response = new Response();
72 // Save RainTPL assigned variables
73 $assignedVariables = [];
74 $this->assignTemplateVars($assignedVariables);
76 $result = ($this->controller
)($request, $response);
78 static::assertSame(404, $result->getStatusCode());
79 static::assertSame([], $assignedVariables);