]> BookStack Code Mirror - bookstack/blob - tests/ErrorTest.php
Fix Crowdin name in the language_request issue template
[bookstack] / tests / ErrorTest.php
1 <?php
2
3 namespace Tests;
4
5 use BookStack\Entities\Models\Book;
6 use Illuminate\Support\Facades\Log;
7
8 class ErrorTest extends TestCase
9 {
10     public function test_404_page_does_not_show_login()
11     {
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';
17         $editor->save();
18
19         $this->actingAs($editor);
20         $notFound = $this->get('/fgfdngldfnotfound');
21         $notFound->assertStatus(404);
22         $notFound->assertDontSeeText('Log in');
23         $notFound->assertSeeText('tester');
24     }
25
26     public function test_item_not_found_does_not_get_logged_to_file()
27     {
28         $this->actingAs($this->getViewer());
29         $handler = $this->withTestLogger();
30         $book = Book::query()->first();
31
32         // Ensure we're seeing errors
33         Log::error('cat');
34         $this->assertTrue($handler->hasErrorThatContains('cat'));
35
36         $this->get('/books/arandomnotfouindbook');
37         $this->get($book->getUrl('/chapter/arandomnotfouindchapter'));
38         $this->get($book->getUrl('/chapter/arandomnotfouindpages'));
39
40         $this->assertCount(1, $handler->getRecords());
41     }
42
43     public function test_access_to_non_existing_image_location_provides_404_response()
44     {
45         $resp = $this->actingAs($this->getViewer())->get('/uploads/images/gallery/2021-05/anonexistingimage.png');
46         $resp->assertStatus(404);
47         $resp->assertSeeText('Image Not Found');
48     }
49 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.