]> BookStack Code Mirror - bookstack/blob - tests/ErrorTest.php
Added shortcut input controls to make custom shortcuts work
[bookstack] / tests / ErrorTest.php
1 <?php
2
3 namespace Tests;
4
5 use Illuminate\Support\Facades\Log;
6
7 class ErrorTest extends TestCase
8 {
9     public function test_404_page_does_not_show_login()
10     {
11         // Due to middleware being handled differently this will not fail
12         // if our custom, middleware-loaded handler fails but this is here
13         // as a reminder and as a general check in the event of other issues.
14         $editor = $this->getEditor();
15         $editor->name = 'tester';
16         $editor->save();
17
18         $this->actingAs($editor);
19         $notFound = $this->get('/fgfdngldfnotfound');
20         $notFound->assertStatus(404);
21         $notFound->assertDontSeeText('Log in');
22         $notFound->assertSeeText('tester');
23     }
24
25     public function test_item_not_found_does_not_get_logged_to_file()
26     {
27         $this->actingAs($this->getViewer());
28         $handler = $this->withTestLogger();
29         $book = $this->entities->book();
30
31         // Ensure we're seeing errors
32         Log::error('cat');
33         $this->assertTrue($handler->hasErrorThatContains('cat'));
34
35         $this->get('/books/arandomnotfouindbook');
36         $this->get($book->getUrl('/chapter/arandomnotfouindchapter'));
37         $this->get($book->getUrl('/chapter/arandomnotfouindpages'));
38
39         $this->assertCount(1, $handler->getRecords());
40     }
41
42     public function test_access_to_non_existing_image_location_provides_404_response()
43     {
44         $resp = $this->actingAs($this->getViewer())->get('/uploads/images/gallery/2021-05/anonexistingimage.png');
45         $resp->assertStatus(404);
46         $resp->assertSeeText('Image Not Found');
47     }
48 }