]> BookStack Code Mirror - bookstack/blob - tests/DebugViewTest.php
Applied StyleCI changes
[bookstack] / tests / DebugViewTest.php
1 <?php
2
3 namespace Tests;
4
5 use BookStack\Auth\Access\SocialAuthService;
6
7 class DebugViewTest extends TestCase
8 {
9     public function test_debug_view_shows_expected_details()
10     {
11         config()->set('app.debug', true);
12         $resp = $this->getDebugViewForException(new \InvalidArgumentException('An error occurred during testing'));
13
14         // Error message
15         $resp->assertSeeText('An error occurred during testing');
16         // Exception Class
17         $resp->assertSeeText('InvalidArgumentException');
18         // Stack trace
19         $resp->assertSeeText('#0');
20         $resp->assertSeeText('#1');
21         // Warning message
22         $resp->assertSeeText('WARNING: Application is in debug mode. This mode has the potential to leak');
23         // PHP version
24         $resp->assertSeeText('PHP Version: ' . phpversion());
25         // BookStack version
26         $resp->assertSeeText('BookStack Version: ' . trim(file_get_contents(base_path('version'))));
27         // Dynamic help links
28         $resp->assertElementExists('a[href*="q=' . urlencode('BookStack An error occurred during testing') . '"]');
29         $resp->assertElementExists('a[href*="?q=is%3Aissue+' . urlencode('An error occurred during testing') . '"]');
30     }
31
32     public function test_debug_view_only_shows_when_debug_mode_is_enabled()
33     {
34         config()->set('app.debug', true);
35         $resp = $this->getDebugViewForException(new \InvalidArgumentException('An error occurred during testing'));
36         $resp->assertSeeText('Stack Trace');
37         $resp->assertDontSeeText('An unknown error occurred');
38
39         config()->set('app.debug', false);
40         $resp = $this->getDebugViewForException(new \InvalidArgumentException('An error occurred during testing'));
41         $resp->assertDontSeeText('Stack Trace');
42         $resp->assertSeeText('An unknown error occurred');
43     }
44
45     protected function getDebugViewForException(\Exception $exception): TestResponse
46     {
47         // Fake an error via social auth service used on login page
48         $mockService = $this->mock(SocialAuthService::class);
49         $mockService->shouldReceive('getActiveDrivers')->andThrow($exception);
50
51         return $this->get('/login');
52     }
53 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.