]> BookStack Code Mirror - bookstack/blob - tests/DebugViewTest.php
Sorting: Added tests to cover AssignSortSetCommand
[bookstack] / tests / DebugViewTest.php
1 <?php
2
3 namespace Tests;
4
5 use BookStack\Access\SocialDriverManager;
6 use Illuminate\Testing\TestResponse;
7
8 class DebugViewTest extends TestCase
9 {
10     public function test_debug_view_shows_expected_details()
11     {
12         config()->set('app.debug', true);
13         $resp = $this->getDebugViewForException(new \InvalidArgumentException('An error occurred during testing'));
14
15         // Error message
16         $resp->assertSeeText('An error occurred during testing');
17         // Exception Class
18         $resp->assertSeeText('InvalidArgumentException');
19         // Stack trace
20         $resp->assertSeeText('#0');
21         $resp->assertSeeText('#1');
22         // Warning message
23         $resp->assertSeeText('WARNING: Application is in debug mode. This mode has the potential to leak');
24         // PHP version
25         $resp->assertSeeText('PHP Version: ' . phpversion());
26         // BookStack version
27         $resp->assertSeeText('BookStack Version: ' . trim(file_get_contents(base_path('version'))));
28         // Dynamic help links
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') . '"]');
31     }
32
33     public function test_debug_view_only_shows_when_debug_mode_is_enabled()
34     {
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');
39
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');
44     }
45
46     protected function getDebugViewForException(\Exception $exception): TestResponse
47     {
48         // Fake an error via social auth service used on login page
49         $mockService = $this->mock(SocialDriverManager::class);
50         $mockService->shouldReceive('getActive')->andThrow($exception);
51
52         return $this->get('/login');
53     }
54 }