mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
Added testing to cover debug view
This commit is contained in:
parent
9b8bb49a33
commit
ffa4377e65
@ -12,18 +12,15 @@ class WhoopsBookStackPrettyHandler extends Handler
|
|||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
// TODO - Assistance View
|
|
||||||
// Docs links
|
|
||||||
// Discord Links
|
|
||||||
// Github Issue Links (With pre-filled search?)
|
|
||||||
|
|
||||||
$exception = $this->getException();
|
$exception = $this->getException();
|
||||||
|
|
||||||
echo view('errors.debug', [
|
echo view('errors.debug', [
|
||||||
'error' => $exception->getMessage(),
|
'error' => $exception->getMessage(),
|
||||||
'errorClass' => get_class($exception),
|
'errorClass' => get_class($exception),
|
||||||
'trace' => $exception->getTraceAsString(),
|
'trace' => $exception->getTraceAsString(),
|
||||||
'environment' => $this->getEnvironment(),
|
'environment' => $this->getEnvironment(),
|
||||||
])->render();
|
])->render();
|
||||||
|
|
||||||
return Handler::QUIT;
|
return Handler::QUIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
54
tests/DebugViewTest.php
Normal file
54
tests/DebugViewTest.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests;
|
||||||
|
|
||||||
|
use BookStack\Auth\Access\SocialAuthService;
|
||||||
|
|
||||||
|
class DebugViewTest extends TestCase
|
||||||
|
{
|
||||||
|
public function test_debug_view_shows_expected_details()
|
||||||
|
{
|
||||||
|
config()->set('app.debug', true);
|
||||||
|
$resp = $this->getDebugViewForException(new \InvalidArgumentException('An error occurred during testing'));
|
||||||
|
|
||||||
|
// Error message
|
||||||
|
$resp->assertSeeText('An error occurred during testing');
|
||||||
|
// Exception Class
|
||||||
|
$resp->assertSeeText('InvalidArgumentException');
|
||||||
|
// Stack trace
|
||||||
|
$resp->assertSeeText('#0');
|
||||||
|
$resp->assertSeeText('#1');
|
||||||
|
// Warning message
|
||||||
|
$resp->assertSeeText('WARNING: Application is in debug mode. This mode has the potential to leak');
|
||||||
|
// PHP version
|
||||||
|
$resp->assertSeeText('PHP Version: ' . phpversion());
|
||||||
|
// BookStack version
|
||||||
|
$resp->assertSeeText('BookStack Version: ' . trim(file_get_contents(base_path('version'))));
|
||||||
|
// Dynamic help links
|
||||||
|
$resp->assertElementExists('a[href*="q=' . urlencode('BookStack An error occurred during testing') . '"]');
|
||||||
|
$resp->assertElementExists('a[href*="?q=is%3Aissue+' . urlencode('An error occurred during testing') . '"]');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_debug_view_only_shows_when_debug_mode_is_enabled()
|
||||||
|
{
|
||||||
|
config()->set('app.debug', true);
|
||||||
|
$resp = $this->getDebugViewForException(new \InvalidArgumentException('An error occurred during testing'));
|
||||||
|
$resp->assertSeeText('Stack Trace');
|
||||||
|
$resp->assertDontSeeText('An unknown error occurred');
|
||||||
|
|
||||||
|
config()->set('app.debug', false);
|
||||||
|
$resp = $this->getDebugViewForException(new \InvalidArgumentException('An error occurred during testing'));
|
||||||
|
$resp->assertDontSeeText('Stack Trace');
|
||||||
|
$resp->assertSeeText('An unknown error occurred');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected function getDebugViewForException(\Exception $exception): TestResponse
|
||||||
|
{
|
||||||
|
// Fake an error via social auth service used on login page
|
||||||
|
$mockService = $this->mock(SocialAuthService::class);
|
||||||
|
$mockService->shouldReceive('getActiveDrivers')->andThrow($exception);
|
||||||
|
return $this->get('/login');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user