aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/front/controller
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-11-05 19:45:41 +0100
committerArthurHoaro <arthur@hoa.ro>2020-11-05 19:55:17 +0100
commitcfdd2094407e61f371c02117c8c66916a6d1d807 (patch)
tree5f3083c9b8d7078dbb1e9986db4fb7f6f8b6266b /tests/front/controller
parent48df9f45b8c4b2995c1e04146071628668531b37 (diff)
downloadShaarli-cfdd2094407e61f371c02117c8c66916a6d1d807.tar.gz
Shaarli-cfdd2094407e61f371c02117c8c66916a6d1d807.tar.zst
Shaarli-cfdd2094407e61f371c02117c8c66916a6d1d807.zip
Display error details even with dev.debug set to false
It makes more sense to display the error even if it's unexpected. Only for logged in users. Fixes #1606
Diffstat (limited to 'tests/front/controller')
-rw-r--r--tests/front/controller/visitor/ErrorControllerTest.php29
1 files changed, 28 insertions, 1 deletions
diff --git a/tests/front/controller/visitor/ErrorControllerTest.php b/tests/front/controller/visitor/ErrorControllerTest.php
index 75408cf4..e18a6fa2 100644
--- a/tests/front/controller/visitor/ErrorControllerTest.php
+++ b/tests/front/controller/visitor/ErrorControllerTest.php
@@ -50,7 +50,31 @@ class ErrorControllerTest extends TestCase
50 } 50 }
51 51
52 /** 52 /**
53 * Test displaying error with any exception (no debug): only display an error occurred with HTTP 500. 53 * Test displaying error with any exception (no debug) while logged in:
54 * display full error details
55 */
56 public function testDisplayAnyExceptionErrorNoDebugLoggedIn(): void
57 {
58 $request = $this->createMock(Request::class);
59 $response = new Response();
60
61 // Save RainTPL assigned variables
62 $assignedVariables = [];
63 $this->assignTemplateVars($assignedVariables);
64
65 $this->container->loginManager->method('isLoggedIn')->willReturn(true);
66
67 $result = ($this->controller)($request, $response, new \Exception('abc'));
68
69 static::assertSame(500, $result->getStatusCode());
70 static::assertSame('Error: abc', $assignedVariables['message']);
71 static::assertContainsPolyfill('Please report it on Github', $assignedVariables['text']);
72 static::assertArrayHasKey('stacktrace', $assignedVariables);
73 }
74
75 /**
76 * Test displaying error with any exception (no debug) while logged out:
77 * display standard error without detail
54 */ 78 */
55 public function testDisplayAnyExceptionErrorNoDebug(): void 79 public function testDisplayAnyExceptionErrorNoDebug(): void
56 { 80 {
@@ -61,10 +85,13 @@ class ErrorControllerTest extends TestCase
61 $assignedVariables = []; 85 $assignedVariables = [];
62 $this->assignTemplateVars($assignedVariables); 86 $this->assignTemplateVars($assignedVariables);
63 87
88 $this->container->loginManager->method('isLoggedIn')->willReturn(false);
89
64 $result = ($this->controller)($request, $response, new \Exception('abc')); 90 $result = ($this->controller)($request, $response, new \Exception('abc'));
65 91
66 static::assertSame(500, $result->getStatusCode()); 92 static::assertSame(500, $result->getStatusCode());
67 static::assertSame('An unexpected error occurred.', $assignedVariables['message']); 93 static::assertSame('An unexpected error occurred.', $assignedVariables['message']);
94 static::assertArrayNotHasKey('text', $assignedVariables);
68 static::assertArrayNotHasKey('stacktrace', $assignedVariables); 95 static::assertArrayNotHasKey('stacktrace', $assignedVariables);
69 } 96 }
70} 97}