5 use BookStack\Entities\Models\Book;
6 use Illuminate\Support\Facades\Log;
8 class ErrorTest extends TestCase
10 public function test_404_page_does_not_show_login()
12 // Due to middleware being handled differently this will not fail
13 // if our custom, middleware-loaded handler fails but this is here
14 // as a reminder and as a general check in the event of other issues.
15 $editor = $this->getEditor();
16 $editor->name = 'tester';
19 $this->actingAs($editor);
20 $notFound = $this->get('/fgfdngldfnotfound');
21 $notFound->assertStatus(404);
22 $notFound->assertDontSeeText('Log in');
23 $notFound->assertSeeText('tester');
26 public function test_item_not_found_does_not_get_logged_to_file()
28 $this->actingAs($this->getViewer());
29 $handler = $this->withTestLogger();
30 $book = Book::query()->first();
32 // Ensure we're seeing errors
34 $this->assertTrue($handler->hasErrorThatContains('cat'));
36 $this->get('/books/arandomnotfouindbook');
37 $this->get($book->getUrl('/chapter/arandomnotfouindchapter'));
38 $this->get($book->getUrl('/chapter/arandomnotfouindpages'));
40 $this->assertCount(1, $handler->getRecords());
43 public function test_access_to_non_existing_image_location_provides_404_response()
45 $resp = $this->actingAs($this->getViewer())->get('/uploads/images/gallery/2021-05/anonexistingimage.png');
46 $resp->assertStatus(404);
47 $resp->assertSeeText('Image Not Found');