aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/front/controller/visitor/ErrorControllerTest.php
diff options
context:
space:
mode:
authoryude <yudesleepy@gmail.com>2021-01-04 18:51:10 +0900
committerGitHub <noreply@github.com>2021-01-04 18:51:10 +0900
commite6754f2154a79abd8e5e64bd923f6984aa9ad44b (patch)
treef074119530bb59ef155938ea367f719f1e4b70f1 /tests/front/controller/visitor/ErrorControllerTest.php
parent5256b4287021342a9f8868967b2a77e481314331 (diff)
parented4ee8f0297941ac83300389b7de6a293312d20e (diff)
downloadShaarli-e6754f2154a79abd8e5e64bd923f6984aa9ad44b.tar.gz
Shaarli-e6754f2154a79abd8e5e64bd923f6984aa9ad44b.tar.zst
Shaarli-e6754f2154a79abd8e5e64bd923f6984aa9ad44b.zip
Merge pull request #2 from shaarli/master
Merge fork source
Diffstat (limited to 'tests/front/controller/visitor/ErrorControllerTest.php')
-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}