X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2Ffront%2Fcontroller%2Fvisitor%2FErrorControllerTest.php;h=e18a6fa2faa278c99eb0071766cabd272ecf6036;hb=d9d71b10c3bc70a0881d630b37dc4e918c9e812f;hp=e497bfefb874bfcac6206b32292e785480b1c7b2;hpb=0c6fdbe12bbbb336348666b14b82096f24d5858b;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/front/controller/visitor/ErrorControllerTest.php b/tests/front/controller/visitor/ErrorControllerTest.php index e497bfef..e18a6fa2 100644 --- a/tests/front/controller/visitor/ErrorControllerTest.php +++ b/tests/front/controller/visitor/ErrorControllerTest.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Visitor; -use PHPUnit\Framework\TestCase; use Shaarli\Front\Exception\ShaarliFrontException; +use Shaarli\TestCase; use Slim\Http\Request; use Slim\Http\Response; @@ -50,7 +50,31 @@ class ErrorControllerTest extends TestCase } /** - * Test displaying error with any exception (no debug): only display an error occurred with HTTP 500. + * Test displaying error with any exception (no debug) while logged in: + * display full error details + */ + public function testDisplayAnyExceptionErrorNoDebugLoggedIn(): void + { + $request = $this->createMock(Request::class); + $response = new Response(); + + // Save RainTPL assigned variables + $assignedVariables = []; + $this->assignTemplateVars($assignedVariables); + + $this->container->loginManager->method('isLoggedIn')->willReturn(true); + + $result = ($this->controller)($request, $response, new \Exception('abc')); + + static::assertSame(500, $result->getStatusCode()); + static::assertSame('Error: abc', $assignedVariables['message']); + static::assertContainsPolyfill('Please report it on Github', $assignedVariables['text']); + static::assertArrayHasKey('stacktrace', $assignedVariables); + } + + /** + * Test displaying error with any exception (no debug) while logged out: + * display standard error without detail */ public function testDisplayAnyExceptionErrorNoDebug(): void { @@ -61,10 +85,13 @@ class ErrorControllerTest extends TestCase $assignedVariables = []; $this->assignTemplateVars($assignedVariables); + $this->container->loginManager->method('isLoggedIn')->willReturn(false); + $result = ($this->controller)($request, $response, new \Exception('abc')); static::assertSame(500, $result->getStatusCode()); static::assertSame('An unexpected error occurred.', $assignedVariables['message']); + static::assertArrayNotHasKey('text', $assignedVariables); static::assertArrayNotHasKey('stacktrace', $assignedVariables); } }