5 use Illuminate\Foundation\Http\Middleware\ValidatePostSize;
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->users->editor();
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_404_page_does_not_non_visible_content()
28 $editor = $this->users->editor();
29 $book = $this->entities->book();
31 $this->actingAs($editor)->get($book->getUrl())->assertOk();
33 $this->permissions->disableEntityInheritedPermissions($book);
35 $this->actingAs($editor)->get($book->getUrl())->assertNotFound();
38 public function test_404_page_shows_visible_content_within_non_visible_parent()
40 $editor = $this->users->editor();
41 $book = $this->entities->book();
42 $page = $book->pages()->first();
44 $this->actingAs($editor)->get($page->getUrl())->assertOk();
46 $this->permissions->disableEntityInheritedPermissions($book);
47 $this->permissions->addEntityPermission($page, ['view'], $editor->roles()->first());
49 $resp = $this->actingAs($editor)->get($book->getUrl());
50 $resp->assertNotFound();
51 $resp->assertSee($page->name);
52 $resp->assertDontSee($book->name);
55 public function test_item_not_found_does_not_get_logged_to_file()
57 $this->actingAs($this->users->viewer());
58 $handler = $this->withTestLogger();
59 $book = $this->entities->book();
61 // Ensure we're seeing errors
63 $this->assertTrue($handler->hasErrorThatContains('cat'));
65 $this->get('/books/arandomnotfouindbook');
66 $this->get($book->getUrl('/chapter/arandomnotfouindchapter'));
67 $this->get($book->getUrl('/chapter/arandomnotfouindpages'));
69 $this->assertCount(1, $handler->getRecords());
72 public function test_access_to_non_existing_image_location_provides_404_response()
74 $resp = $this->actingAs($this->users->viewer())->get('/uploads/images/gallery/2021-05/anonexistingimage.png');
75 $resp->assertStatus(404);
76 $resp->assertSeeText('Image Not Found');
79 public function test_posts_above_php_limit_shows_friendly_error()
81 // Fake super large JSON request
82 $resp = $this->asEditor()->call('GET', '/books', [], [], [], [
83 'CONTENT_LENGTH' => '10000000000',
84 'HTTP_ACCEPT' => 'application/json',
87 $resp->assertStatus(413);
88 $resp->assertJson(['error' => 'The server cannot receive the provided amount of data. Try again with less data or a smaller file.']);