5 use BookStack\Auth\Access\SocialAuthService;
6 use Illuminate\Testing\TestResponse;
8 class DebugViewTest extends TestCase
10 public function test_debug_view_shows_expected_details()
12 config()->set('app.debug', true);
13 $resp = $this->getDebugViewForException(new \InvalidArgumentException('An error occurred during testing'));
16 $resp->assertSeeText('An error occurred during testing');
18 $resp->assertSeeText('InvalidArgumentException');
20 $resp->assertSeeText('#0');
21 $resp->assertSeeText('#1');
23 $resp->assertSeeText('WARNING: Application is in debug mode. This mode has the potential to leak');
25 $resp->assertSeeText('PHP Version: ' . phpversion());
27 $resp->assertSeeText('BookStack Version: ' . trim(file_get_contents(base_path('version'))));
29 $this->withHtml($resp)->assertElementExists('a[href*="q=' . urlencode('BookStack An error occurred during testing') . '"]');
30 $this->withHtml($resp)->assertElementExists('a[href*="?q=is%3Aissue+' . urlencode('An error occurred during testing') . '"]');
33 public function test_debug_view_only_shows_when_debug_mode_is_enabled()
35 config()->set('app.debug', true);
36 $resp = $this->getDebugViewForException(new \InvalidArgumentException('An error occurred during testing'));
37 $resp->assertSeeText('Stack Trace');
38 $resp->assertDontSeeText('An unknown error occurred');
40 config()->set('app.debug', false);
41 $resp = $this->getDebugViewForException(new \InvalidArgumentException('An error occurred during testing'));
42 $resp->assertDontSeeText('Stack Trace');
43 $resp->assertSeeText('An unknown error occurred');
46 protected function getDebugViewForException(\Exception $exception): TestResponse
48 // Fake an error via social auth service used on login page
49 $mockService = $this->mock(SocialAuthService::class);
50 $mockService->shouldReceive('getActiveDrivers')->andThrow($exception);
52 return $this->get('/login');