Migrated much test entity usage via find/replace

This commit is contained in:
Dan Brown 2022-09-29 17:31:38 +01:00
parent 068a8a068c
commit b56f7355aa
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
45 changed files with 264 additions and 384 deletions

View File

@ -46,7 +46,7 @@ class AuditLogTest extends TestCase
{ {
$admin = $this->getAdmin(); $admin = $this->getAdmin();
$this->actingAs($admin); $this->actingAs($admin);
$page = Page::query()->first(); $page = $this->entities->page();
$this->activityService->add(ActivityType::PAGE_CREATE, $page); $this->activityService->add(ActivityType::PAGE_CREATE, $page);
$activity = Activity::query()->orderBy('id', 'desc')->first(); $activity = Activity::query()->orderBy('id', 'desc')->first();
@ -60,7 +60,7 @@ class AuditLogTest extends TestCase
public function test_shows_name_for_deleted_items() public function test_shows_name_for_deleted_items()
{ {
$this->actingAs($this->getAdmin()); $this->actingAs($this->getAdmin());
$page = Page::query()->first(); $page = $this->entities->page();
$pageName = $page->name; $pageName = $page->name;
$this->activityService->add(ActivityType::PAGE_CREATE, $page); $this->activityService->add(ActivityType::PAGE_CREATE, $page);
@ -76,7 +76,7 @@ class AuditLogTest extends TestCase
{ {
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$this->actingAs($viewer); $this->actingAs($viewer);
$page = Page::query()->first(); $page = $this->entities->page();
$this->activityService->add(ActivityType::PAGE_CREATE, $page); $this->activityService->add(ActivityType::PAGE_CREATE, $page);
$this->actingAs($this->getAdmin()); $this->actingAs($this->getAdmin());
@ -89,7 +89,7 @@ class AuditLogTest extends TestCase
public function test_filters_by_key() public function test_filters_by_key()
{ {
$this->actingAs($this->getAdmin()); $this->actingAs($this->getAdmin());
$page = Page::query()->first(); $page = $this->entities->page();
$this->activityService->add(ActivityType::PAGE_CREATE, $page); $this->activityService->add(ActivityType::PAGE_CREATE, $page);
$resp = $this->get('settings/audit'); $resp = $this->get('settings/audit');
@ -102,7 +102,7 @@ class AuditLogTest extends TestCase
public function test_date_filters() public function test_date_filters()
{ {
$this->actingAs($this->getAdmin()); $this->actingAs($this->getAdmin());
$page = Page::query()->first(); $page = $this->entities->page();
$this->activityService->add(ActivityType::PAGE_CREATE, $page); $this->activityService->add(ActivityType::PAGE_CREATE, $page);
$yesterday = (Carbon::now()->subDay()->format('Y-m-d')); $yesterday = (Carbon::now()->subDay()->format('Y-m-d'));
@ -126,11 +126,11 @@ class AuditLogTest extends TestCase
$admin = $this->getAdmin(); $admin = $this->getAdmin();
$editor = $this->getEditor(); $editor = $this->getEditor();
$this->actingAs($admin); $this->actingAs($admin);
$page = Page::query()->first(); $page = $this->entities->page();
$this->activityService->add(ActivityType::PAGE_CREATE, $page); $this->activityService->add(ActivityType::PAGE_CREATE, $page);
$this->actingAs($editor); $this->actingAs($editor);
$chapter = Chapter::query()->first(); $chapter = $this->entities->chapter();
$this->activityService->add(ActivityType::CHAPTER_UPDATE, $chapter); $this->activityService->add(ActivityType::CHAPTER_UPDATE, $chapter);
$resp = $this->actingAs($admin)->get('settings/audit?user=' . $admin->id); $resp = $this->actingAs($admin)->get('settings/audit?user=' . $admin->id);
@ -146,8 +146,7 @@ class AuditLogTest extends TestCase
{ {
config()->set('app.proxies', '*'); config()->set('app.proxies', '*');
$editor = $this->getEditor(); $editor = $this->getEditor();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$this->actingAs($editor)->put($page->getUrl(), [ $this->actingAs($editor)->put($page->getUrl(), [
'name' => 'Updated page', 'name' => 'Updated page',
@ -171,8 +170,7 @@ class AuditLogTest extends TestCase
{ {
config()->set('app.proxies', '*'); config()->set('app.proxies', '*');
$editor = $this->getEditor(); $editor = $this->getEditor();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$this->actingAs($editor)->put($page->getUrl(), [ $this->actingAs($editor)->put($page->getUrl(), [
'name' => 'Updated page', 'name' => 'Updated page',
@ -198,8 +196,7 @@ class AuditLogTest extends TestCase
config()->set('app.proxies', '*'); config()->set('app.proxies', '*');
config()->set('app.env', 'demo'); config()->set('app.env', 'demo');
$editor = $this->getEditor(); $editor = $this->getEditor();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$this->actingAs($editor)->put($page->getUrl(), [ $this->actingAs($editor)->put($page->getUrl(), [
'name' => 'Updated page', 'name' => 'Updated page',
@ -222,8 +219,7 @@ class AuditLogTest extends TestCase
config()->set('app.proxies', '*'); config()->set('app.proxies', '*');
config()->set('app.ip_address_precision', 2); config()->set('app.ip_address_precision', 2);
$editor = $this->getEditor(); $editor = $this->getEditor();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$this->actingAs($editor)->put($page->getUrl(), [ $this->actingAs($editor)->put($page->getUrl(), [
'name' => 'Updated page', 'name' => 'Updated page',

View File

@ -88,8 +88,7 @@ class WebhookCallTest extends TestCase
'*' => Http::response('', 200), '*' => Http::response('', 200),
]); ]);
$webhook = $this->newWebhook(['active' => true, 'endpoint' => 'https://wh.example.com'], ['all']); $webhook = $this->newWebhook(['active' => true, 'endpoint' => 'https://wh.example.com'], ['all']);
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$editor = $this->getEditor(); $editor = $this->getEditor();
$this->runEvent(ActivityType::PAGE_UPDATE, $page, $editor); $this->runEvent(ActivityType::PAGE_UPDATE, $page, $editor);

View File

@ -32,8 +32,7 @@ class WebhookFormatTesting extends TestCase
public function test_page_create_and_update_events_show_revision_info() public function test_page_create_and_update_events_show_revision_info()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']); $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
$data = $this->getWebhookData(ActivityType::PAGE_UPDATE, $page); $data = $this->getWebhookData(ActivityType::PAGE_UPDATE, $page);

View File

@ -17,7 +17,7 @@ class AttachmentsApiTest extends TestCase
public function test_index_endpoint_returns_expected_book() public function test_index_endpoint_returns_expected_book()
{ {
$this->actingAsApiEditor(); $this->actingAsApiEditor();
$page = Page::query()->first(); $page = $this->entities->page();
$attachment = $this->createAttachmentForPage($page, [ $attachment = $this->createAttachmentForPage($page, [
'name' => 'My test attachment', 'name' => 'My test attachment',
'external' => true, 'external' => true,
@ -37,8 +37,7 @@ class AttachmentsApiTest extends TestCase
public function test_attachments_listing_based_upon_page_visibility() public function test_attachments_listing_based_upon_page_visibility()
{ {
$this->actingAsApiEditor(); $this->actingAsApiEditor();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$attachment = $this->createAttachmentForPage($page, [ $attachment = $this->createAttachmentForPage($page, [
'name' => 'My test attachment', 'name' => 'My test attachment',
'external' => true, 'external' => true,
@ -66,8 +65,7 @@ class AttachmentsApiTest extends TestCase
public function test_create_endpoint_for_link_attachment() public function test_create_endpoint_for_link_attachment()
{ {
$this->actingAsApiAdmin(); $this->actingAsApiAdmin();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$details = [ $details = [
'name' => 'My attachment', 'name' => 'My attachment',
@ -85,8 +83,7 @@ class AttachmentsApiTest extends TestCase
public function test_create_endpoint_for_upload_attachment() public function test_create_endpoint_for_upload_attachment()
{ {
$this->actingAsApiAdmin(); $this->actingAsApiAdmin();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$file = $this->getTestFile('textfile.txt'); $file = $this->getTestFile('textfile.txt');
$details = [ $details = [
@ -106,8 +103,7 @@ class AttachmentsApiTest extends TestCase
public function test_upload_limit_restricts_attachment_uploads() public function test_upload_limit_restricts_attachment_uploads()
{ {
$this->actingAsApiAdmin(); $this->actingAsApiAdmin();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
config()->set('app.upload_limit', 1); config()->set('app.upload_limit', 1);
@ -130,8 +126,7 @@ class AttachmentsApiTest extends TestCase
public function test_name_needed_to_create() public function test_name_needed_to_create()
{ {
$this->actingAsApiAdmin(); $this->actingAsApiAdmin();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$details = [ $details = [
'uploaded_to' => $page->id, 'uploaded_to' => $page->id,
@ -146,8 +141,7 @@ class AttachmentsApiTest extends TestCase
public function test_link_or_file_needed_to_create() public function test_link_or_file_needed_to_create()
{ {
$this->actingAsApiAdmin(); $this->actingAsApiAdmin();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$details = [ $details = [
'name' => 'my attachment', 'name' => 'my attachment',
@ -165,8 +159,7 @@ class AttachmentsApiTest extends TestCase
public function test_message_shown_if_file_is_not_a_valid_file() public function test_message_shown_if_file_is_not_a_valid_file()
{ {
$this->actingAsApiAdmin(); $this->actingAsApiAdmin();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$details = [ $details = [
'name' => 'my attachment', 'name' => 'my attachment',
@ -182,8 +175,7 @@ class AttachmentsApiTest extends TestCase
public function test_read_endpoint_for_link_attachment() public function test_read_endpoint_for_link_attachment()
{ {
$this->actingAsApiAdmin(); $this->actingAsApiAdmin();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$attachment = $this->createAttachmentForPage($page, [ $attachment = $this->createAttachmentForPage($page, [
'name' => 'my attachment', 'name' => 'my attachment',
@ -216,8 +208,7 @@ class AttachmentsApiTest extends TestCase
public function test_read_endpoint_for_file_attachment() public function test_read_endpoint_for_file_attachment()
{ {
$this->actingAsApiAdmin(); $this->actingAsApiAdmin();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$file = $this->getTestFile('textfile.txt'); $file = $this->getTestFile('textfile.txt');
$details = [ $details = [
@ -259,8 +250,7 @@ class AttachmentsApiTest extends TestCase
$this->actingAsApiAdmin(); $this->actingAsApiAdmin();
$editor = $this->getEditor(); $editor = $this->getEditor();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$page->draft = true; $page->draft = true;
$page->owned_by = $editor->id; $page->owned_by = $editor->id;
$page->save(); $page->save();
@ -280,8 +270,7 @@ class AttachmentsApiTest extends TestCase
public function test_update_endpoint() public function test_update_endpoint()
{ {
$this->actingAsApiAdmin(); $this->actingAsApiAdmin();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$attachment = $this->createAttachmentForPage($page); $attachment = $this->createAttachmentForPage($page);
$details = [ $details = [
@ -298,8 +287,7 @@ class AttachmentsApiTest extends TestCase
public function test_update_link_attachment_to_file() public function test_update_link_attachment_to_file()
{ {
$this->actingAsApiAdmin(); $this->actingAsApiAdmin();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$attachment = $this->createAttachmentForPage($page); $attachment = $this->createAttachmentForPage($page);
$file = $this->getTestFile('textfile.txt'); $file = $this->getTestFile('textfile.txt');
@ -318,8 +306,7 @@ class AttachmentsApiTest extends TestCase
public function test_update_file_attachment_to_link() public function test_update_file_attachment_to_link()
{ {
$this->actingAsApiAdmin(); $this->actingAsApiAdmin();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$file = $this->getTestFile('textfile.txt'); $file = $this->getTestFile('textfile.txt');
$this->call('POST', $this->baseEndpoint, ['name' => 'My file attachment', 'uploaded_to' => $page->id], [], ['file' => $file]); $this->call('POST', $this->baseEndpoint, ['name' => 'My file attachment', 'uploaded_to' => $page->id], [], ['file' => $file]);
/** @var Attachment $attachment */ /** @var Attachment $attachment */
@ -346,8 +333,7 @@ class AttachmentsApiTest extends TestCase
public function test_delete_endpoint() public function test_delete_endpoint()
{ {
$this->actingAsApiAdmin(); $this->actingAsApiAdmin();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$attachment = $this->createAttachmentForPage($page); $attachment = $this->createAttachmentForPage($page);
$resp = $this->deleteJson("{$this->baseEndpoint}/{$attachment->id}"); $resp = $this->deleteJson("{$this->baseEndpoint}/{$attachment->id}");

View File

@ -34,7 +34,7 @@ class ChaptersApiTest extends TestCase
public function test_create_endpoint() public function test_create_endpoint()
{ {
$this->actingAsApiEditor(); $this->actingAsApiEditor();
$book = Book::query()->first(); $book = $this->entities->book();
$details = [ $details = [
'name' => 'My API chapter', 'name' => 'My API chapter',
'description' => 'A chapter created via the API', 'description' => 'A chapter created via the API',
@ -64,7 +64,7 @@ class ChaptersApiTest extends TestCase
public function test_chapter_name_needed_to_create() public function test_chapter_name_needed_to_create()
{ {
$this->actingAsApiEditor(); $this->actingAsApiEditor();
$book = Book::query()->first(); $book = $this->entities->book();
$details = [ $details = [
'book_id' => $book->id, 'book_id' => $book->id,
'description' => 'A chapter created via the API', 'description' => 'A chapter created via the API',

View File

@ -35,7 +35,7 @@ class PagesApiTest extends TestCase
public function test_create_endpoint() public function test_create_endpoint()
{ {
$this->actingAsApiEditor(); $this->actingAsApiEditor();
$book = Book::query()->first(); $book = $this->entities->book();
$details = [ $details = [
'name' => 'My API page', 'name' => 'My API page',
'book_id' => $book->id, 'book_id' => $book->id,
@ -67,7 +67,7 @@ class PagesApiTest extends TestCase
public function test_page_name_needed_to_create() public function test_page_name_needed_to_create()
{ {
$this->actingAsApiEditor(); $this->actingAsApiEditor();
$book = Book::query()->first(); $book = $this->entities->book();
$details = [ $details = [
'book_id' => $book->id, 'book_id' => $book->id,
'html' => '<p>A page created via the API</p>', 'html' => '<p>A page created via the API</p>',

View File

@ -50,8 +50,8 @@ class RecycleBinApiTest extends TestCase
{ {
$admin = $this->getAdmin(); $admin = $this->getAdmin();
$page = Page::query()->first(); $page = $this->entities->page();
$book = Book::query()->first(); $book = $this->entities->book();
$this->actingAs($admin)->delete($page->getUrl()); $this->actingAs($admin)->delete($page->getUrl());
$this->delete($book->getUrl()); $this->delete($book->getUrl());
@ -139,7 +139,7 @@ class RecycleBinApiTest extends TestCase
public function test_restore_endpoint() public function test_restore_endpoint()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$this->asAdmin()->delete($page->getUrl()); $this->asAdmin()->delete($page->getUrl());
$page->refresh(); $page->refresh();
@ -163,7 +163,7 @@ class RecycleBinApiTest extends TestCase
public function test_destroy_endpoint() public function test_destroy_endpoint()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$this->asAdmin()->delete($page->getUrl()); $this->asAdmin()->delete($page->getUrl());
$page->refresh(); $page->refresh();

View File

@ -38,8 +38,7 @@ class SearchApiTest extends TestCase
public function test_all_endpoint_returns_entity_url() public function test_all_endpoint_returns_entity_url()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$page->update(['name' => 'name with superuniquevalue within']); $page->update(['name' => 'name with superuniquevalue within']);
$page->indexForSearch(); $page->indexForSearch();
@ -52,8 +51,7 @@ class SearchApiTest extends TestCase
public function test_all_endpoint_returns_items_with_preview_html() public function test_all_endpoint_returns_items_with_preview_html()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$book->update(['name' => 'name with superuniquevalue within', 'description' => 'Description with superuniquevalue within']); $book->update(['name' => 'name with superuniquevalue within', 'description' => 'Description with superuniquevalue within']);
$book->indexForSearch(); $book->indexForSearch();

View File

@ -58,8 +58,7 @@ class AuthTest extends TestCase
public function test_login_redirects_to_initially_requested_url_correctly() public function test_login_redirects_to_initially_requested_url_correctly()
{ {
config()->set('app.url', 'http://localhost'); config()->set('app.url', 'http://localhost');
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$this->get($page->getUrl())->assertRedirect(url('/login')); $this->get($page->getUrl())->assertRedirect(url('/login'));
$this->login('admin@admin.com', 'password') $this->login('admin@admin.com', 'password')

View File

@ -14,8 +14,7 @@ class ClearActivityCommandTest extends TestCase
public function test_clear_activity_command() public function test_clear_activity_command()
{ {
$this->asEditor(); $this->asEditor();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
Activity::add(ActivityType::PAGE_UPDATE, $page); Activity::add(ActivityType::PAGE_UPDATE, $page);
$this->assertDatabaseHas('activities', [ $this->assertDatabaseHas('activities', [

View File

@ -36,7 +36,7 @@ class CopyShelfPermissionsCommandTest extends TestCase
public function test_copy_shelf_permissions_command_using_all() public function test_copy_shelf_permissions_command_using_all()
{ {
$shelf = Bookshelf::query()->first(); $shelf = $this->entities->shelf();
Bookshelf::query()->where('id', '!=', $shelf->id)->delete(); Bookshelf::query()->where('id', '!=', $shelf->id)->delete();
$child = $shelf->books()->first(); $child = $shelf->books()->first();
$editorRole = $this->getEditor()->roles()->first(); $editorRole = $this->getEditor()->roles()->first();

View File

@ -10,8 +10,7 @@ class RegenerateReferencesCommandTest extends TestCase
{ {
public function test_regenerate_references_command() public function test_regenerate_references_command()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$book = $page->book; $book = $page->book;
$page->html = '<a href="' . $book->getUrl() . '">Book Link</a>'; $page->html = '<a href="' . $book->getUrl() . '">Book Link</a>';

View File

@ -10,7 +10,7 @@ class UpdateUrlCommandTest extends TestCase
{ {
public function test_command_updates_page_content() public function test_command_updates_page_content()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$page->html = '<a href="https://example.com/donkeys"></a>'; $page->html = '<a href="https://example.com/donkeys"></a>';
$page->save(); $page->save();

View File

@ -62,7 +62,7 @@ class BookShelfTest extends TestCase
config()->set([ config()->set([
'setting-defaults.user.bookshelves_view_type' => 'list', 'setting-defaults.user.bookshelves_view_type' => 'list',
]); ]);
$shelf = Bookshelf::query()->first(); $shelf = $this->entities->shelf();
$book = $shelf->books()->first(); $book = $shelf->books()->first();
$resp = $this->asEditor()->get('/shelves'); $resp = $this->asEditor()->get('/shelves');
@ -160,7 +160,7 @@ class BookShelfTest extends TestCase
public function test_shelf_view_has_sort_control_that_defaults_to_default() public function test_shelf_view_has_sort_control_that_defaults_to_default()
{ {
$shelf = Bookshelf::query()->first(); $shelf = $this->entities->shelf();
$resp = $this->asAdmin()->get($shelf->getUrl()); $resp = $this->asAdmin()->get($shelf->getUrl());
$this->withHtml($resp)->assertElementExists('form[action$="change-sort/shelf_books"]'); $this->withHtml($resp)->assertElementExists('form[action$="change-sort/shelf_books"]');
$this->withHtml($resp)->assertElementContains('form[action$="change-sort/shelf_books"] [aria-haspopup="true"]', 'Default'); $this->withHtml($resp)->assertElementContains('form[action$="change-sort/shelf_books"] [aria-haspopup="true"]', 'Default');
@ -373,8 +373,7 @@ class BookShelfTest extends TestCase
public function test_cancel_on_child_book_creation_returns_to_original_shelf() public function test_cancel_on_child_book_creation_returns_to_original_shelf()
{ {
/** @var Bookshelf $shelf */ $shelf = $this->entities->shelf();
$shelf = Bookshelf::query()->first();
$resp = $this->asEditor()->get($shelf->getUrl('/create-book')); $resp = $this->asEditor()->get($shelf->getUrl('/create-book'));
$this->withHtml($resp)->assertElementContains('form a[href="' . $shelf->getUrl() . '"]', 'Cancel'); $this->withHtml($resp)->assertElementContains('form a[href="' . $shelf->getUrl() . '"]', 'Cancel');
} }

View File

@ -80,8 +80,7 @@ class BookTest extends TestCase
public function test_update() public function test_update()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
// Cheeky initial update to refresh slug // Cheeky initial update to refresh slug
$this->asEditor()->put($book->getUrl(), ['name' => $book->name . '5', 'description' => $book->description]); $this->asEditor()->put($book->getUrl(), ['name' => $book->name . '5', 'description' => $book->description]);
$book->refresh(); $book->refresh();
@ -104,8 +103,7 @@ class BookTest extends TestCase
public function test_update_sets_tags() public function test_update_sets_tags()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$this->assertEquals(0, $book->tags()->count()); $this->assertEquals(0, $book->tags()->count());
@ -167,15 +165,14 @@ class BookTest extends TestCase
public function test_cancel_on_edit_book_page_leads_back_to_book() public function test_cancel_on_edit_book_page_leads_back_to_book()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$resp = $this->asEditor()->get($book->getUrl('/edit')); $resp = $this->asEditor()->get($book->getUrl('/edit'));
$this->withHtml($resp)->assertElementContains('form a[href="' . $book->getUrl() . '"]', 'Cancel'); $this->withHtml($resp)->assertElementContains('form a[href="' . $book->getUrl() . '"]', 'Cancel');
} }
public function test_next_previous_navigation_controls_show_within_book_content() public function test_next_previous_navigation_controls_show_within_book_content()
{ {
$book = Book::query()->first(); $book = $this->entities->book();
$chapter = $book->chapters->first(); $chapter = $book->chapters->first();
$resp = $this->asEditor()->get($chapter->getUrl()); $resp = $this->asEditor()->get($chapter->getUrl());
@ -270,8 +267,7 @@ class BookTest extends TestCase
public function test_show_view_has_copy_button() public function test_show_view_has_copy_button()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$resp = $this->asEditor()->get($book->getUrl()); $resp = $this->asEditor()->get($book->getUrl());
$this->withHtml($resp)->assertElementContains("a[href=\"{$book->getUrl('/copy')}\"]", 'Copy'); $this->withHtml($resp)->assertElementContains("a[href=\"{$book->getUrl('/copy')}\"]", 'Copy');
@ -279,8 +275,7 @@ class BookTest extends TestCase
public function test_copy_view() public function test_copy_view()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$resp = $this->asEditor()->get($book->getUrl('/copy')); $resp = $this->asEditor()->get($book->getUrl('/copy'));
$resp->assertOk(); $resp->assertOk();
@ -338,8 +333,7 @@ class BookTest extends TestCase
public function test_copy_clones_cover_image_if_existing() public function test_copy_clones_cover_image_if_existing()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$bookRepo = $this->app->make(BookRepo::class); $bookRepo = $this->app->make(BookRepo::class);
$coverImageFile = $this->getTestImage('cover.png'); $coverImageFile = $this->getTestImage('cover.png');
$bookRepo->updateCoverImage($book, $coverImageFile); $bookRepo->updateCoverImage($book, $coverImageFile);
@ -357,8 +351,7 @@ class BookTest extends TestCase
/** @var Bookshelf $shelfA */ /** @var Bookshelf $shelfA */
/** @var Bookshelf $shelfB */ /** @var Bookshelf $shelfB */
[$shelfA, $shelfB] = Bookshelf::query()->take(2)->get(); [$shelfA, $shelfB] = Bookshelf::query()->take(2)->get();
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$shelfA->appendBook($book); $shelfA->appendBook($book);
$shelfB->appendBook($book); $shelfB->appendBook($book);

View File

@ -11,8 +11,7 @@ class ChapterTest extends TestCase
{ {
public function test_create() public function test_create()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$chapter = Chapter::factory()->make([ $chapter = Chapter::factory()->make([
'name' => 'My First Chapter', 'name' => 'My First Chapter',
@ -58,8 +57,7 @@ class ChapterTest extends TestCase
public function test_show_view_has_copy_button() public function test_show_view_has_copy_button()
{ {
/** @var Chapter $chapter */ $chapter = $this->entities->chapter();
$chapter = Chapter::query()->first();
$resp = $this->asEditor()->get($chapter->getUrl()); $resp = $this->asEditor()->get($chapter->getUrl());
$this->withHtml($resp)->assertElementContains("a[href$=\"{$chapter->getUrl('/copy')}\"]", 'Copy'); $this->withHtml($resp)->assertElementContains("a[href$=\"{$chapter->getUrl('/copy')}\"]", 'Copy');
@ -67,8 +65,7 @@ class ChapterTest extends TestCase
public function test_copy_view() public function test_copy_view()
{ {
/** @var Chapter $chapter */ $chapter = $this->entities->chapter();
$chapter = Chapter::query()->first();
$resp = $this->asEditor()->get($chapter->getUrl('/copy')); $resp = $this->asEditor()->get($chapter->getUrl('/copy'));
$resp->assertOk(); $resp->assertOk();
@ -149,8 +146,7 @@ class ChapterTest extends TestCase
public function test_sort_book_action_visible_if_permissions_allow() public function test_sort_book_action_visible_if_permissions_allow()
{ {
/** @var Chapter $chapter */ $chapter = $this->entities->chapter();
$chapter = Chapter::query()->first();
$resp = $this->actingAs($this->getViewer())->get($chapter->getUrl()); $resp = $this->actingAs($this->getViewer())->get($chapter->getUrl());
$this->withHtml($resp)->assertLinkNotExists($chapter->book->getUrl('sort')); $this->withHtml($resp)->assertLinkNotExists($chapter->book->getUrl('sort'));

View File

@ -14,8 +14,7 @@ class ConvertTest extends TestCase
{ {
public function test_chapter_edit_view_shows_convert_option() public function test_chapter_edit_view_shows_convert_option()
{ {
/** @var Chapter $chapter */ $chapter = $this->entities->chapter();
$chapter = Chapter::query()->first();
$resp = $this->asEditor()->get($chapter->getUrl('/edit')); $resp = $this->asEditor()->get($chapter->getUrl('/edit'));
$resp->assertSee('Convert to Book'); $resp->assertSee('Convert to Book');
@ -50,8 +49,7 @@ class ConvertTest extends TestCase
public function test_convert_chapter_to_book_requires_permissions() public function test_convert_chapter_to_book_requires_permissions()
{ {
/** @var Chapter $chapter */ $chapter = $this->entities->chapter();
$chapter = Chapter::query()->first();
$user = $this->getViewer(); $user = $this->getViewer();
$permissions = ['chapter-delete-all', 'book-create-all', 'chapter-update-all']; $permissions = ['chapter-delete-all', 'book-create-all', 'chapter-update-all'];
@ -71,7 +69,7 @@ class ConvertTest extends TestCase
public function test_book_edit_view_shows_convert_option() public function test_book_edit_view_shows_convert_option()
{ {
$book = Book::query()->first(); $book = $this->entities->book();
$resp = $this->asEditor()->get($book->getUrl('/edit')); $resp = $this->asEditor()->get($book->getUrl('/edit'));
$resp->assertSee('Convert to Shelf'); $resp->assertSee('Convert to Shelf');
@ -124,8 +122,7 @@ class ConvertTest extends TestCase
public function test_book_convert_to_shelf_requires_permissions() public function test_book_convert_to_shelf_requires_permissions()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$user = $this->getViewer(); $user = $this->getViewer();
$permissions = ['book-delete-all', 'bookshelf-create-all', 'book-update-all', 'book-create-all']; $permissions = ['book-delete-all', 'bookshelf-create-all', 'book-update-all', 'book-create-all'];

View File

@ -23,8 +23,7 @@ class EntitySearchTest extends TestCase
public function test_bookshelf_search() public function test_bookshelf_search()
{ {
/** @var Bookshelf $shelf */ $shelf = $this->entities->shelf();
$shelf = Bookshelf::query()->first();
$search = $this->asEditor()->get('/search?term=' . urlencode($shelf->name) . ' {type:bookshelf}'); $search = $this->asEditor()->get('/search?term=' . urlencode($shelf->name) . ' {type:bookshelf}');
$search->assertSee('Search Results'); $search->assertSee('Search Results');
@ -232,7 +231,7 @@ class EntitySearchTest extends TestCase
public function test_ajax_entity_search_reflects_items_without_permission() public function test_ajax_entity_search_reflects_items_without_permission()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$baseSelector = 'a[data-entity-type="page"][data-entity-id="' . $page->id . '"]'; $baseSelector = 'a[data-entity-type="page"][data-entity-id="' . $page->id . '"]';
$searchUrl = '/ajax/search/entities?permission=update&term=' . urlencode($page->name); $searchUrl = '/ajax/search/entities?permission=update&term=' . urlencode($page->name);
@ -318,7 +317,7 @@ class EntitySearchTest extends TestCase
public function test_search_works_on_updated_page_content() public function test_search_works_on_updated_page_content()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$this->asEditor(); $this->asEditor();
$update = $this->put($page->getUrl(), [ $update = $this->put($page->getUrl(), [

View File

@ -15,7 +15,7 @@ class ExportTest extends TestCase
{ {
public function test_page_text_export() public function test_page_text_export()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$this->asEditor(); $this->asEditor();
$resp = $this->get($page->getUrl('/export/plaintext')); $resp = $this->get($page->getUrl('/export/plaintext'));
@ -26,7 +26,7 @@ class ExportTest extends TestCase
public function test_page_pdf_export() public function test_page_pdf_export()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$this->asEditor(); $this->asEditor();
$resp = $this->get($page->getUrl('/export/pdf')); $resp = $this->get($page->getUrl('/export/pdf'));
@ -36,7 +36,7 @@ class ExportTest extends TestCase
public function test_page_html_export() public function test_page_html_export()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$this->asEditor(); $this->asEditor();
$resp = $this->get($page->getUrl('/export/html')); $resp = $this->get($page->getUrl('/export/html'));
@ -47,7 +47,7 @@ class ExportTest extends TestCase
public function test_book_text_export() public function test_book_text_export()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$book = $page->book; $book = $page->book;
$this->asEditor(); $this->asEditor();
@ -60,7 +60,7 @@ class ExportTest extends TestCase
public function test_book_pdf_export() public function test_book_pdf_export()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$book = $page->book; $book = $page->book;
$this->asEditor(); $this->asEditor();
@ -71,7 +71,7 @@ class ExportTest extends TestCase
public function test_book_html_export() public function test_book_html_export()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$book = $page->book; $book = $page->book;
$this->asEditor(); $this->asEditor();
@ -85,7 +85,7 @@ class ExportTest extends TestCase
public function test_book_html_export_shows_chapter_descriptions() public function test_book_html_export_shows_chapter_descriptions()
{ {
$chapterDesc = 'My custom test chapter description ' . Str::random(12); $chapterDesc = 'My custom test chapter description ' . Str::random(12);
$chapter = Chapter::query()->first(); $chapter = $this->entities->chapter();
$chapter->description = $chapterDesc; $chapter->description = $chapterDesc;
$chapter->save(); $chapter->save();
@ -98,7 +98,7 @@ class ExportTest extends TestCase
public function test_chapter_text_export() public function test_chapter_text_export()
{ {
$chapter = Chapter::query()->first(); $chapter = $this->entities->chapter();
$page = $chapter->pages[0]; $page = $chapter->pages[0];
$this->asEditor(); $this->asEditor();
@ -111,7 +111,7 @@ class ExportTest extends TestCase
public function test_chapter_pdf_export() public function test_chapter_pdf_export()
{ {
$chapter = Chapter::query()->first(); $chapter = $this->entities->chapter();
$this->asEditor(); $this->asEditor();
$resp = $this->get($chapter->getUrl('/export/pdf')); $resp = $this->get($chapter->getUrl('/export/pdf'));
@ -121,7 +121,7 @@ class ExportTest extends TestCase
public function test_chapter_html_export() public function test_chapter_html_export()
{ {
$chapter = Chapter::query()->first(); $chapter = $this->entities->chapter();
$page = $chapter->pages[0]; $page = $chapter->pages[0];
$this->asEditor(); $this->asEditor();
@ -134,7 +134,7 @@ class ExportTest extends TestCase
public function test_page_html_export_contains_custom_head_if_set() public function test_page_html_export_contains_custom_head_if_set()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$customHeadContent = '<style>p{color: red;}</style>'; $customHeadContent = '<style>p{color: red;}</style>';
$this->setSettings(['app-custom-head' => $customHeadContent]); $this->setSettings(['app-custom-head' => $customHeadContent]);
@ -145,7 +145,7 @@ class ExportTest extends TestCase
public function test_page_html_export_does_not_break_with_only_comments_in_custom_head() public function test_page_html_export_does_not_break_with_only_comments_in_custom_head()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$customHeadContent = '<!-- A comment -->'; $customHeadContent = '<!-- A comment -->';
$this->setSettings(['app-custom-head' => $customHeadContent]); $this->setSettings(['app-custom-head' => $customHeadContent]);
@ -157,7 +157,7 @@ class ExportTest extends TestCase
public function test_page_html_export_use_absolute_dates() public function test_page_html_export_use_absolute_dates()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$resp = $this->asEditor()->get($page->getUrl('/export/html')); $resp = $this->asEditor()->get($page->getUrl('/export/html'));
$resp->assertSee($page->created_at->formatLocalized('%e %B %Y %H:%M:%S')); $resp->assertSee($page->created_at->formatLocalized('%e %B %Y %H:%M:%S'));
@ -168,7 +168,7 @@ class ExportTest extends TestCase
public function test_page_export_does_not_include_user_or_revision_links() public function test_page_export_does_not_include_user_or_revision_links()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$resp = $this->asEditor()->get($page->getUrl('/export/html')); $resp = $this->asEditor()->get($page->getUrl('/export/html'));
$resp->assertDontSee($page->getUrl('/revisions')); $resp->assertDontSee($page->getUrl('/revisions'));
@ -178,7 +178,7 @@ class ExportTest extends TestCase
public function test_page_export_sets_right_data_type_for_svg_embeds() public function test_page_export_sets_right_data_type_for_svg_embeds()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
Storage::disk('local')->makeDirectory('uploads/images/gallery'); Storage::disk('local')->makeDirectory('uploads/images/gallery');
Storage::disk('local')->put('uploads/images/gallery/svg_test.svg', '<svg></svg>'); Storage::disk('local')->put('uploads/images/gallery/svg_test.svg', '<svg></svg>');
$page->html = '<img src="http://localhost/uploads/images/gallery/svg_test.svg">'; $page->html = '<img src="http://localhost/uploads/images/gallery/svg_test.svg">';
@ -194,7 +194,7 @@ class ExportTest extends TestCase
public function test_page_image_containment_works_on_multiple_images_within_a_single_line() public function test_page_image_containment_works_on_multiple_images_within_a_single_line()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
Storage::disk('local')->makeDirectory('uploads/images/gallery'); Storage::disk('local')->makeDirectory('uploads/images/gallery');
Storage::disk('local')->put('uploads/images/gallery/svg_test.svg', '<svg></svg>'); Storage::disk('local')->put('uploads/images/gallery/svg_test.svg', '<svg></svg>');
Storage::disk('local')->put('uploads/images/gallery/svg_test2.svg', '<svg></svg>'); Storage::disk('local')->put('uploads/images/gallery/svg_test2.svg', '<svg></svg>');
@ -210,7 +210,7 @@ class ExportTest extends TestCase
public function test_page_export_contained_html_image_fetches_only_run_when_url_points_to_image_upload_folder() public function test_page_export_contained_html_image_fetches_only_run_when_url_points_to_image_upload_folder()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$page->html = '<img src="http://localhost/uploads/images/gallery/svg_test.svg"/>' $page->html = '<img src="http://localhost/uploads/images/gallery/svg_test.svg"/>'
. '<img src="http://localhost/uploads/svg_test.svg"/>' . '<img src="http://localhost/uploads/svg_test.svg"/>'
. '<img src="/uploads/svg_test.svg"/>'; . '<img src="/uploads/svg_test.svg"/>';
@ -235,7 +235,7 @@ class ExportTest extends TestCase
$contents = file_get_contents(public_path('.htaccess')); $contents = file_get_contents(public_path('.htaccess'));
config()->set('filesystems.images', 'local'); config()->set('filesystems.images', 'local');
$page = Page::query()->first(); $page = $this->entities->page();
$page->html = '<img src="http://localhost/uploads/images/../../.htaccess"/>'; $page->html = '<img src="http://localhost/uploads/images/../../.htaccess"/>';
$page->save(); $page->save();
@ -249,7 +249,7 @@ class ExportTest extends TestCase
config()->set('filesystems.images', 'local_secure'); config()->set('filesystems.images', 'local_secure');
file_put_contents($testFilePath, 'I am a cat'); file_put_contents($testFilePath, 'I am a cat');
$page = Page::query()->first(); $page = $this->entities->page();
$page->html = '<img src="http://localhost/uploads/images/../../logs/test.txt"/>'; $page->html = '<img src="http://localhost/uploads/images/../../logs/test.txt"/>';
$page->save(); $page->save();
@ -276,7 +276,7 @@ class ExportTest extends TestCase
public function test_page_export_with_deleted_creator_and_updater() public function test_page_export_with_deleted_creator_and_updater()
{ {
$user = $this->getViewer(['name' => 'ExportWizardTheFifth']); $user = $this->getViewer(['name' => 'ExportWizardTheFifth']);
$page = Page::query()->first(); $page = $this->entities->page();
$page->created_by = $user->id; $page->created_by = $user->id;
$page->updated_by = $user->id; $page->updated_by = $user->id;
$page->save(); $page->save();
@ -329,7 +329,7 @@ class ExportTest extends TestCase
public function test_page_markdown_export() public function test_page_markdown_export()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$resp = $this->asEditor()->get($page->getUrl('/export/markdown')); $resp = $this->asEditor()->get($page->getUrl('/export/markdown'));
$resp->assertStatus(200); $resp->assertStatus(200);
@ -364,7 +364,7 @@ class ExportTest extends TestCase
public function test_chapter_markdown_export() public function test_chapter_markdown_export()
{ {
$chapter = Chapter::query()->first(); $chapter = $this->entities->chapter();
$page = $chapter->pages()->first(); $page = $chapter->pages()->first();
$resp = $this->asEditor()->get($chapter->getUrl('/export/markdown')); $resp = $this->asEditor()->get($chapter->getUrl('/export/markdown'));
@ -430,8 +430,7 @@ class ExportTest extends TestCase
public function test_wkhtmltopdf_only_used_when_allow_untrusted_is_true() public function test_wkhtmltopdf_only_used_when_allow_untrusted_is_true()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
config()->set('snappy.pdf.binary', '/abc123'); config()->set('snappy.pdf.binary', '/abc123');
config()->set('app.allow_untrusted_server_fetching', false); config()->set('app.allow_untrusted_server_fetching', false);
@ -460,7 +459,7 @@ class ExportTest extends TestCase
public function test_html_exports_contain_body_classes_for_export_identification() public function test_html_exports_contain_body_classes_for_export_identification()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$resp = $this->asEditor()->get($page->getUrl('/export/html')); $resp = $this->asEditor()->get($page->getUrl('/export/html'));
$this->withHtml($resp)->assertElementExists('body.export.export-format-html.export-engine-none'); $this->withHtml($resp)->assertElementExists('body.export.export-format-html.export-engine-none');

View File

@ -15,7 +15,7 @@ class PageContentTest extends TestCase
public function test_page_includes() public function test_page_includes()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$secondPage = Page::query()->where('id', '!=', $page->id)->first(); $secondPage = Page::query()->where('id', '!=', $page->id)->first();
$secondPage->html = "<p id='section1'>Hello, This is a test</p><p id='section2'>This is a second block of content</p>"; $secondPage->html = "<p id='section1'>Hello, This is a test</p><p id='section2'>This is a second block of content</p>";
@ -44,7 +44,7 @@ class PageContentTest extends TestCase
public function test_saving_page_with_includes() public function test_saving_page_with_includes()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$secondPage = Page::query()->where('id', '!=', $page->id)->first(); $secondPage = Page::query()->where('id', '!=', $page->id)->first();
$this->asEditor(); $this->asEditor();
@ -62,10 +62,8 @@ class PageContentTest extends TestCase
public function test_page_includes_do_not_break_tables() public function test_page_includes_do_not_break_tables()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first(); $secondPage = $this->entities->page();
/** @var Page $secondPage */
$secondPage = Page::query()->where('id', '!=', $page->id)->first();
$content = '<table id="table"><tbody><tr><td>test</td></tr></tbody></table>'; $content = '<table id="table"><tbody><tr><td>test</td></tr></tbody></table>';
$secondPage->html = $content; $secondPage->html = $content;
@ -80,10 +78,8 @@ class PageContentTest extends TestCase
public function test_page_includes_do_not_break_code() public function test_page_includes_do_not_break_code()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first(); $secondPage = $this->entities->page();
/** @var Page $secondPage */
$secondPage = Page::query()->where('id', '!=', $page->id)->first();
$content = '<pre id="bkmrk-code"><code>var cat = null;</code></pre>'; $content = '<pre id="bkmrk-code"><code>var cat = null;</code></pre>';
$secondPage->html = $content; $secondPage->html = $content;
@ -98,7 +94,7 @@ class PageContentTest extends TestCase
public function test_page_includes_rendered_on_book_export() public function test_page_includes_rendered_on_book_export()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$secondPage = Page::query() $secondPage = Page::query()
->where('book_id', '!=', $page->book_id) ->where('book_id', '!=', $page->book_id)
->first(); ->first();
@ -118,7 +114,7 @@ class PageContentTest extends TestCase
public function test_page_content_scripts_removed_by_default() public function test_page_content_scripts_removed_by_default()
{ {
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
$script = 'abc123<script>console.log("hello-test")</script>abc123'; $script = 'abc123<script>console.log("hello-test")</script>abc123';
$page->html = "escape {$script}"; $page->html = "escape {$script}";
$page->save(); $page->save();
@ -141,7 +137,7 @@ class PageContentTest extends TestCase
]; ];
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
foreach ($checks as $check) { foreach ($checks as $check) {
$page->html = $check; $page->html = $check;
@ -177,7 +173,7 @@ class PageContentTest extends TestCase
]; ];
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
foreach ($checks as $check) { foreach ($checks as $check) {
$page->html = $check; $page->html = $check;
@ -206,7 +202,7 @@ class PageContentTest extends TestCase
]; ];
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
foreach ($checks as $check) { foreach ($checks as $check) {
$page->html = $check; $page->html = $check;
@ -230,7 +226,7 @@ class PageContentTest extends TestCase
]; ];
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
foreach ($checks as $check) { foreach ($checks as $check) {
$page->html = $check; $page->html = $check;
@ -255,7 +251,7 @@ class PageContentTest extends TestCase
]; ];
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
foreach ($checks as $check) { foreach ($checks as $check) {
$page->html = $check; $page->html = $check;
@ -273,7 +269,7 @@ class PageContentTest extends TestCase
public function test_page_inline_on_attributes_removed_by_default() public function test_page_inline_on_attributes_removed_by_default()
{ {
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
$script = '<p onmouseenter="console.log(\'test\')">Hello</p>'; $script = '<p onmouseenter="console.log(\'test\')">Hello</p>';
$page->html = "escape {$script}"; $page->html = "escape {$script}";
$page->save(); $page->save();
@ -298,7 +294,7 @@ class PageContentTest extends TestCase
]; ];
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
foreach ($checks as $check) { foreach ($checks as $check) {
$page->html = $check; $page->html = $check;
@ -313,7 +309,7 @@ class PageContentTest extends TestCase
public function test_page_content_scripts_show_when_configured() public function test_page_content_scripts_show_when_configured()
{ {
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
config()->push('app.allow_content_scripts', 'true'); config()->push('app.allow_content_scripts', 'true');
$script = 'abc123<script>console.log("hello-test")</script>abc123'; $script = 'abc123<script>console.log("hello-test")</script>abc123';
@ -339,7 +335,7 @@ class PageContentTest extends TestCase
]; ];
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
foreach ($checks as $check) { foreach ($checks as $check) {
$page->html = $check; $page->html = $check;
@ -358,7 +354,7 @@ class PageContentTest extends TestCase
public function test_page_inline_on_attributes_show_if_configured() public function test_page_inline_on_attributes_show_if_configured()
{ {
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
config()->push('app.allow_content_scripts', 'true'); config()->push('app.allow_content_scripts', 'true');
$script = '<p onmouseenter="console.log(\'test\')">Hello</p>'; $script = '<p onmouseenter="console.log(\'test\')">Hello</p>';
@ -390,7 +386,7 @@ class PageContentTest extends TestCase
public function test_duplicate_ids_fixed_on_page_save() public function test_duplicate_ids_fixed_on_page_save()
{ {
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
$content = '<ul id="bkmrk-test"><li>test a</li><li><ul id="bkmrk-test"><li>test b</li></ul></li></ul>'; $content = '<ul id="bkmrk-test"><li>test a</li><li><ul id="bkmrk-test"><li>test b</li></ul></li></ul>';
$pageSave = $this->put($page->getUrl(), [ $pageSave = $this->put($page->getUrl(), [
@ -407,7 +403,7 @@ class PageContentTest extends TestCase
public function test_anchors_referencing_non_bkmrk_ids_rewritten_after_save() public function test_anchors_referencing_non_bkmrk_ids_rewritten_after_save()
{ {
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
$content = '<h1 id="non-standard-id">test</h1><p><a href="#non-standard-id">link</a></p>'; $content = '<h1 id="non-standard-id">test</h1><p><a href="#non-standard-id">link</a></p>';
$this->put($page->getUrl(), [ $this->put($page->getUrl(), [
@ -485,7 +481,7 @@ class PageContentTest extends TestCase
public function test_page_text_decodes_html_entities() public function test_page_text_decodes_html_entities()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$this->actingAs($this->getAdmin()) $this->actingAs($this->getAdmin())
->put($page->getUrl(''), [ ->put($page->getUrl(''), [
@ -500,7 +496,7 @@ class PageContentTest extends TestCase
public function test_page_markdown_table_rendering() public function test_page_markdown_table_rendering()
{ {
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
$content = '| Syntax | Description | $content = '| Syntax | Description |
| ----------- | ----------- | | ----------- | ----------- |
@ -521,7 +517,7 @@ class PageContentTest extends TestCase
public function test_page_markdown_task_list_rendering() public function test_page_markdown_task_list_rendering()
{ {
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
$content = '- [ ] Item a $content = '- [ ] Item a
- [x] Item b'; - [x] Item b';
@ -542,7 +538,7 @@ class PageContentTest extends TestCase
public function test_page_markdown_strikethrough_rendering() public function test_page_markdown_strikethrough_rendering()
{ {
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
$content = '~~some crossed out text~~'; $content = '~~some crossed out text~~';
$this->put($page->getUrl(), [ $this->put($page->getUrl(), [
@ -560,7 +556,7 @@ class PageContentTest extends TestCase
public function test_page_markdown_single_html_comment_saving() public function test_page_markdown_single_html_comment_saving()
{ {
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
$content = '<!-- Test Comment -->'; $content = '<!-- Test Comment -->';
$this->put($page->getUrl(), [ $this->put($page->getUrl(), [
@ -579,7 +575,7 @@ class PageContentTest extends TestCase
public function test_base64_images_get_extracted_from_page_content() public function test_base64_images_get_extracted_from_page_content()
{ {
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
$this->put($page->getUrl(), [ $this->put($page->getUrl(), [
'name' => $page->name, 'summary' => '', 'name' => $page->name, 'summary' => '',
@ -601,7 +597,7 @@ class PageContentTest extends TestCase
public function test_base64_images_get_extracted_when_containing_whitespace() public function test_base64_images_get_extracted_when_containing_whitespace()
{ {
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
$base64PngWithWhitespace = "iVBORw0KGg\noAAAANSUhE\tUgAAAAEAAAA BCA YAAAAfFcSJAAA\n\t ACklEQVR4nGMAAQAABQAB"; $base64PngWithWhitespace = "iVBORw0KGg\noAAAANSUhE\tUgAAAAEAAAA BCA YAAAAfFcSJAAA\n\t ACklEQVR4nGMAAQAABQAB";
$base64PngWithoutWhitespace = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQAB'; $base64PngWithoutWhitespace = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQAB';
@ -632,7 +628,7 @@ class PageContentTest extends TestCase
foreach ($extensions as $extension) { foreach ($extensions as $extension) {
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
$this->put($page->getUrl(), [ $this->put($page->getUrl(), [
'name' => $page->name, 'summary' => '', 'name' => $page->name, 'summary' => '',
@ -647,7 +643,7 @@ class PageContentTest extends TestCase
public function test_base64_images_get_extracted_from_markdown_page_content() public function test_base64_images_get_extracted_from_markdown_page_content()
{ {
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
$this->put($page->getUrl(), [ $this->put($page->getUrl(), [
'name' => $page->name, 'summary' => '', 'name' => $page->name, 'summary' => '',
@ -672,7 +668,7 @@ class PageContentTest extends TestCase
$pcreRecursionLimit = ini_get('pcre.recursion_limit'); $pcreRecursionLimit = ini_get('pcre.recursion_limit');
$this->asEditor(); $this->asEditor();
$page = Page::query()->first(); $page = $this->entities->page();
ini_set('pcre.backtrack_limit', '500'); ini_set('pcre.backtrack_limit', '500');
ini_set('pcre.recursion_limit', '500'); ini_set('pcre.recursion_limit', '500');
@ -701,7 +697,7 @@ class PageContentTest extends TestCase
public function test_base64_images_within_markdown_blanked_if_not_supported_extension_for_extract() public function test_base64_images_within_markdown_blanked_if_not_supported_extension_for_extract()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$this->asEditor()->put($page->getUrl(), [ $this->asEditor()->put($page->getUrl(), [
'name' => $page->name, 'summary' => '', 'name' => $page->name, 'summary' => '',
@ -713,7 +709,7 @@ class PageContentTest extends TestCase
public function test_nested_headers_gets_assigned_an_id() public function test_nested_headers_gets_assigned_an_id()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$content = '<table><tbody><tr><td><h5>Simple Test</h5></td></tr></tbody></table>'; $content = '<table><tbody><tr><td><h5>Simple Test</h5></td></tr></tbody></table>';
$this->asEditor()->put($page->getUrl(), [ $this->asEditor()->put($page->getUrl(), [
@ -729,8 +725,7 @@ class PageContentTest extends TestCase
public function test_non_breaking_spaces_are_preserved() public function test_non_breaking_spaces_are_preserved()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$content = '<p>&nbsp;</p>'; $content = '<p>&nbsp;</p>';
$this->asEditor()->put($page->getUrl(), [ $this->asEditor()->put($page->getUrl(), [

View File

@ -85,8 +85,7 @@ class PageDraftTest extends TestCase
{ {
$admin = $this->getAdmin(); $admin = $this->getAdmin();
$editor = $this->getEditor(); $editor = $this->getEditor();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$this->actingAs($editor)->put('/ajax/page/' . $page->id . '/save-draft', [ $this->actingAs($editor)->put('/ajax/page/' . $page->id . '/save-draft', [
'name' => $page->name, 'name' => $page->name,
@ -120,8 +119,7 @@ class PageDraftTest extends TestCase
{ {
$admin = $this->getAdmin(); $admin = $this->getAdmin();
$editor = $this->getEditor(); $editor = $this->getEditor();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$this->actingAs($admin)->put('/ajax/page/' . $page->id . '/save-draft', [ $this->actingAs($admin)->put('/ajax/page/' . $page->id . '/save-draft', [
'name' => $page->name, 'name' => $page->name,
@ -140,8 +138,7 @@ class PageDraftTest extends TestCase
public function test_draft_pages_show_on_homepage() public function test_draft_pages_show_on_homepage()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$resp = $this->asAdmin()->get('/'); $resp = $this->asAdmin()->get('/');
$this->withHtml($resp)->assertElementNotContains('#recent-drafts', 'New Page'); $this->withHtml($resp)->assertElementNotContains('#recent-drafts', 'New Page');
@ -152,8 +149,7 @@ class PageDraftTest extends TestCase
public function test_draft_pages_not_visible_by_others() public function test_draft_pages_not_visible_by_others()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$chapter = $book->chapters->first(); $chapter = $book->chapters->first();
$newUser = $this->getEditor(); $newUser = $this->getEditor();
@ -171,8 +167,7 @@ class PageDraftTest extends TestCase
public function test_page_html_in_ajax_fetch_response() public function test_page_html_in_ajax_fetch_response()
{ {
$this->asAdmin(); $this->asAdmin();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$this->getJson('/ajax/page/' . $page->id)->assertJson([ $this->getJson('/ajax/page/' . $page->id)->assertJson([
'html' => $page->html, 'html' => $page->html,
@ -181,8 +176,7 @@ class PageDraftTest extends TestCase
public function test_updating_page_draft_with_markdown_retains_markdown_content() public function test_updating_page_draft_with_markdown_retains_markdown_content()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$this->asEditor()->get($book->getUrl('/create-page')); $this->asEditor()->get($book->getUrl('/create-page'));
/** @var Page $draft */ /** @var Page $draft */
$draft = Page::query()->where('draft', '=', true)->where('book_id', '=', $book->id)->firstOrFail(); $draft = Page::query()->where('draft', '=', true)->where('book_id', '=', $book->id)->firstOrFail();
@ -207,8 +201,7 @@ class PageDraftTest extends TestCase
public function test_slug_generated_on_draft_publish_to_page_when_no_name_change() public function test_slug_generated_on_draft_publish_to_page_when_no_name_change()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$this->asEditor()->get($book->getUrl('/create-page')); $this->asEditor()->get($book->getUrl('/create-page'));
/** @var Page $draft */ /** @var Page $draft */
$draft = Page::query()->where('draft', '=', true)->where('book_id', '=', $book->id)->firstOrFail(); $draft = Page::query()->where('draft', '=', true)->where('book_id', '=', $book->id)->firstOrFail();

View File

@ -58,8 +58,7 @@ class PageEditorTest extends TestCase
public function test_empty_markdown_still_saves_without_error() public function test_empty_markdown_still_saves_without_error()
{ {
$this->setSettings(['app-editor' => 'markdown']); $this->setSettings(['app-editor' => 'markdown']);
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$this->asEditor()->get($book->getUrl('/create-page')); $this->asEditor()->get($book->getUrl('/create-page'));
$draft = Page::query()->where('book_id', '=', $book->id) $draft = Page::query()->where('book_id', '=', $book->id)
@ -108,8 +107,7 @@ class PageEditorTest extends TestCase
public function test_switching_from_html_to_clean_markdown_works() public function test_switching_from_html_to_clean_markdown_works()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$page->html = '<h2>A Header</h2><p>Some <strong>bold</strong> content.</p>'; $page->html = '<h2>A Header</h2><p>Some <strong>bold</strong> content.</p>';
$page->save(); $page->save();
@ -121,8 +119,7 @@ class PageEditorTest extends TestCase
public function test_switching_from_html_to_stable_markdown_works() public function test_switching_from_html_to_stable_markdown_works()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$page->html = '<h2>A Header</h2><p>Some <strong>bold</strong> content.</p>'; $page->html = '<h2>A Header</h2><p>Some <strong>bold</strong> content.</p>';
$page->save(); $page->save();
@ -134,8 +131,7 @@ class PageEditorTest extends TestCase
public function test_switching_from_markdown_to_wysiwyg_works() public function test_switching_from_markdown_to_wysiwyg_works()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$page->html = ''; $page->html = '';
$page->markdown = "## A Header\n\nSome content with **bold** text!"; $page->markdown = "## A Header\n\nSome content with **bold** text!";
$page->save(); $page->save();
@ -180,8 +176,7 @@ class PageEditorTest extends TestCase
public function test_page_editor_type_switch_does_not_work_without_change_editor_permissions() public function test_page_editor_type_switch_does_not_work_without_change_editor_permissions()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$page->html = '<h2>A Header</h2><p>Some <strong>bold</strong> content.</p>'; $page->html = '<h2>A Header</h2><p>Some <strong>bold</strong> content.</p>';
$page->save(); $page->save();
@ -193,8 +188,7 @@ class PageEditorTest extends TestCase
public function test_page_save_does_not_change_active_editor_without_change_editor_permissions() public function test_page_save_does_not_change_active_editor_without_change_editor_permissions()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$page->html = '<h2>A Header</h2><p>Some <strong>bold</strong> content.</p>'; $page->html = '<h2>A Header</h2><p>Some <strong>bold</strong> content.</p>';
$page->editor = 'wysiwyg'; $page->editor = 'wysiwyg';
$page->save(); $page->save();

View File

@ -10,8 +10,7 @@ class PageRevisionTest extends TestCase
{ {
public function test_revision_links_visible_to_viewer() public function test_revision_links_visible_to_viewer()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$html = $this->withHtml($this->asViewer()->get($page->getUrl())); $html = $this->withHtml($this->asViewer()->get($page->getUrl()));
$html->assertLinkExists($page->getUrl('/revisions')); $html->assertLinkExists($page->getUrl('/revisions'));
@ -143,8 +142,7 @@ class PageRevisionTest extends TestCase
public function test_revision_deletion() public function test_revision_deletion()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$this->createRevisions($page, 2); $this->createRevisions($page, 2);
$beforeRevisionCount = $page->revisions->count(); $beforeRevisionCount = $page->revisions->count();
@ -208,8 +206,7 @@ class PageRevisionTest extends TestCase
public function test_revision_restore_action_only_visible_with_permission() public function test_revision_restore_action_only_visible_with_permission()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$this->createRevisions($page, 2); $this->createRevisions($page, 2);
$viewer = $this->getViewer(); $viewer = $this->getViewer();
@ -227,8 +224,7 @@ class PageRevisionTest extends TestCase
public function test_revision_delete_action_only_visible_with_permission() public function test_revision_delete_action_only_visible_with_permission()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$this->createRevisions($page, 2); $this->createRevisions($page, 2);
$viewer = $this->getViewer(); $viewer = $this->getViewer();

View File

@ -12,8 +12,7 @@ class PageTest extends TestCase
{ {
public function test_create() public function test_create()
{ {
/** @var Chapter $chapter */ $chapter = $this->entities->chapter();
$chapter = Chapter::query()->first();
$page = Page::factory()->make([ $page = Page::factory()->make([
'name' => 'My First Page', 'name' => 'My First Page',
]); ]);
@ -39,7 +38,7 @@ class PageTest extends TestCase
public function test_page_view_when_creator_is_deleted_but_owner_exists() public function test_page_view_when_creator_is_deleted_but_owner_exists()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$user = $this->getViewer(); $user = $this->getViewer();
$owner = $this->getEditor(); $owner = $this->getEditor();
$page->created_by = $user->id; $page->created_by = $user->id;
@ -55,7 +54,7 @@ class PageTest extends TestCase
public function test_page_creation_with_markdown_content() public function test_page_creation_with_markdown_content()
{ {
$this->setSettings(['app-editor' => 'markdown']); $this->setSettings(['app-editor' => 'markdown']);
$book = Book::query()->first(); $book = $this->entities->book();
$this->asEditor()->get($book->getUrl('/create-page')); $this->asEditor()->get($book->getUrl('/create-page'));
$draft = Page::query()->where('book_id', '=', $book->id) $draft = Page::query()->where('book_id', '=', $book->id)
@ -83,7 +82,7 @@ class PageTest extends TestCase
public function test_page_delete() public function test_page_delete()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$this->assertNull($page->deleted_at); $this->assertNull($page->deleted_at);
$deleteViewReq = $this->asEditor()->get($page->getUrl('/delete')); $deleteViewReq = $this->asEditor()->get($page->getUrl('/delete'));
@ -103,8 +102,7 @@ class PageTest extends TestCase
public function test_page_full_delete_removes_all_revisions() public function test_page_full_delete_removes_all_revisions()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$page->revisions()->create([ $page->revisions()->create([
'html' => '<p>ducks</p>', 'html' => '<p>ducks</p>',
'name' => 'my page revision', 'name' => 'my page revision',
@ -221,8 +219,7 @@ class PageTest extends TestCase
public function test_old_page_slugs_redirect_to_new_pages() public function test_old_page_slugs_redirect_to_new_pages()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
// Need to save twice since revisions are not generated in seeder. // Need to save twice since revisions are not generated in seeder.
$this->asAdmin()->put($page->getUrl(), [ $this->asAdmin()->put($page->getUrl(), [
@ -244,8 +241,7 @@ class PageTest extends TestCase
public function test_page_within_chapter_deletion_returns_to_chapter() public function test_page_within_chapter_deletion_returns_to_chapter()
{ {
/** @var Chapter $chapter */ $chapter = $this->entities->chapter();
$chapter = Chapter::query()->first();
$page = $chapter->pages()->first(); $page = $chapter->pages()->first();
$this->asEditor()->delete($page->getUrl()) $this->asEditor()->delete($page->getUrl())
@ -264,8 +260,7 @@ class PageTest extends TestCase
public function test_recently_updated_pages_view_shows_updated_by_details() public function test_recently_updated_pages_view_shows_updated_by_details()
{ {
$user = $this->getEditor(); $user = $this->getEditor();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$this->actingAs($user)->put($page->getUrl(), [ $this->actingAs($user)->put($page->getUrl(), [
'name' => 'Updated title', 'name' => 'Updated title',

View File

@ -33,7 +33,7 @@ class SortTest extends TestCase
public function test_page_move_into_book() public function test_page_move_into_book()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$currentBook = $page->book; $currentBook = $page->book;
$newBook = Book::query()->where('id', '!=', $currentBook->id)->first(); $newBook = Book::query()->where('id', '!=', $currentBook->id)->first();
@ -55,7 +55,7 @@ class SortTest extends TestCase
public function test_page_move_into_chapter() public function test_page_move_into_chapter()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$currentBook = $page->book; $currentBook = $page->book;
$newBook = Book::query()->where('id', '!=', $currentBook->id)->first(); $newBook = Book::query()->where('id', '!=', $currentBook->id)->first();
$newChapter = $newBook->chapters()->first(); $newChapter = $newBook->chapters()->first();
@ -93,7 +93,7 @@ class SortTest extends TestCase
public function test_page_move_requires_create_permissions_on_parent() public function test_page_move_requires_create_permissions_on_parent()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$currentBook = $page->book; $currentBook = $page->book;
$newBook = Book::query()->where('id', '!=', $currentBook->id)->first(); $newBook = Book::query()->where('id', '!=', $currentBook->id)->first();
$editor = $this->getEditor(); $editor = $this->getEditor();
@ -118,7 +118,7 @@ class SortTest extends TestCase
public function test_page_move_requires_delete_permissions() public function test_page_move_requires_delete_permissions()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$currentBook = $page->book; $currentBook = $page->book;
$newBook = Book::query()->where('id', '!=', $currentBook->id)->first(); $newBook = Book::query()->where('id', '!=', $currentBook->id)->first();
$editor = $this->getEditor(); $editor = $this->getEditor();
@ -145,7 +145,7 @@ class SortTest extends TestCase
public function test_chapter_move() public function test_chapter_move()
{ {
$chapter = Chapter::query()->first(); $chapter = $this->entities->chapter();
$currentBook = $chapter->book; $currentBook = $chapter->book;
$pageToCheck = $chapter->pages->first(); $pageToCheck = $chapter->pages->first();
$newBook = Book::query()->where('id', '!=', $currentBook->id)->first(); $newBook = Book::query()->where('id', '!=', $currentBook->id)->first();
@ -173,7 +173,7 @@ class SortTest extends TestCase
public function test_chapter_move_requires_delete_permissions() public function test_chapter_move_requires_delete_permissions()
{ {
$chapter = Chapter::query()->first(); $chapter = $this->entities->chapter();
$currentBook = $chapter->book; $currentBook = $chapter->book;
$newBook = Book::query()->where('id', '!=', $currentBook->id)->first(); $newBook = Book::query()->where('id', '!=', $currentBook->id)->first();
$editor = $this->getEditor(); $editor = $this->getEditor();
@ -200,7 +200,7 @@ class SortTest extends TestCase
public function test_chapter_move_requires_create_permissions_in_new_book() public function test_chapter_move_requires_create_permissions_in_new_book()
{ {
$chapter = Chapter::query()->first(); $chapter = $this->entities->chapter();
$currentBook = $chapter->book; $currentBook = $chapter->book;
$newBook = Book::query()->where('id', '!=', $currentBook->id)->first(); $newBook = Book::query()->where('id', '!=', $currentBook->id)->first();
$editor = $this->getEditor(); $editor = $this->getEditor();

View File

@ -102,8 +102,7 @@ class TagTest extends TestCase
public function test_tags_index_shows_tag_name_as_expected_with_right_counts() public function test_tags_index_shows_tag_name_as_expected_with_right_counts()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$page->tags()->create(['name' => 'Category', 'value' => 'GreatTestContent']); $page->tags()->create(['name' => 'Category', 'value' => 'GreatTestContent']);
$page->tags()->create(['name' => 'Category', 'value' => 'OtherTestContent']); $page->tags()->create(['name' => 'Category', 'value' => 'OtherTestContent']);
@ -120,8 +119,7 @@ class TagTest extends TestCase
$html->assertElementContains('a[title="Assigned to Shelves"]', '0'); $html->assertElementContains('a[title="Assigned to Shelves"]', '0');
$html->assertElementContains('a[href$="/tags?name=Category"]', '2 unique values'); $html->assertElementContains('a[href$="/tags?name=Category"]', '2 unique values');
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$book->tags()->create(['name' => 'Category', 'value' => 'GreatTestContent']); $book->tags()->create(['name' => 'Category', 'value' => 'GreatTestContent']);
$resp = $this->asEditor()->get('/tags'); $resp = $this->asEditor()->get('/tags');
$this->withHtml($resp)->assertElementContains('a[title="Total tag usages"]', '3'); $this->withHtml($resp)->assertElementContains('a[title="Total tag usages"]', '3');
@ -131,8 +129,7 @@ class TagTest extends TestCase
public function test_tag_index_can_be_searched() public function test_tag_index_can_be_searched()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$page->tags()->create(['name' => 'Category', 'value' => 'GreatTestContent']); $page->tags()->create(['name' => 'Category', 'value' => 'GreatTestContent']);
$resp = $this->asEditor()->get('/tags?search=cat'); $resp = $this->asEditor()->get('/tags?search=cat');
@ -148,8 +145,7 @@ class TagTest extends TestCase
public function test_tag_index_search_will_show_mulitple_values_of_a_single_tag_name() public function test_tag_index_search_will_show_mulitple_values_of_a_single_tag_name()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$page->tags()->create(['name' => 'Animal', 'value' => 'Catfish']); $page->tags()->create(['name' => 'Animal', 'value' => 'Catfish']);
$page->tags()->create(['name' => 'Animal', 'value' => 'Catdog']); $page->tags()->create(['name' => 'Animal', 'value' => 'Catdog']);
@ -160,8 +156,7 @@ class TagTest extends TestCase
public function test_tag_index_can_be_scoped_to_specific_tag_name() public function test_tag_index_can_be_scoped_to_specific_tag_name()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$page->tags()->create(['name' => 'Category', 'value' => 'GreatTestContent']); $page->tags()->create(['name' => 'Category', 'value' => 'GreatTestContent']);
$page->tags()->create(['name' => 'Category', 'value' => 'OtherTestContent']); $page->tags()->create(['name' => 'Category', 'value' => 'OtherTestContent']);
$page->tags()->create(['name' => 'OtherTagName', 'value' => 'OtherValue']); $page->tags()->create(['name' => 'OtherTagName', 'value' => 'OtherValue']);
@ -178,8 +173,7 @@ class TagTest extends TestCase
public function test_tags_index_adheres_to_page_permissions() public function test_tags_index_adheres_to_page_permissions()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$page->tags()->create(['name' => 'SuperCategory', 'value' => 'GreatTestContent']); $page->tags()->create(['name' => 'SuperCategory', 'value' => 'GreatTestContent']);
$resp = $this->asEditor()->get('/tags'); $resp = $this->asEditor()->get('/tags');
@ -216,7 +210,7 @@ class TagTest extends TestCase
public function test_tag_classes_are_escaped() public function test_tag_classes_are_escaped()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$page->tags()->create(['name' => '<>']); $page->tags()->create(['name' => '<>']);
$resp = $this->asEditor()->get($page->getUrl()); $resp = $this->asEditor()->get($page->getUrl());
$resp->assertDontSee('tag-name-<>', false); $resp->assertDontSee('tag-name-<>', false);

View File

@ -27,7 +27,7 @@ class ErrorTest extends TestCase
{ {
$this->actingAs($this->getViewer()); $this->actingAs($this->getViewer());
$handler = $this->withTestLogger(); $handler = $this->withTestLogger();
$book = Book::query()->first(); $book = $this->entities->book();
// Ensure we're seeing errors // Ensure we're seeing errors
Log::error('cat'); Log::error('cat');

View File

@ -13,7 +13,7 @@ class FavouriteTest extends TestCase
{ {
public function test_page_add_favourite_flow() public function test_page_add_favourite_flow()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$editor = $this->getEditor(); $editor = $this->getEditor();
$resp = $this->actingAs($editor)->get($page->getUrl()); $resp = $this->actingAs($editor)->get($page->getUrl());
@ -36,7 +36,7 @@ class FavouriteTest extends TestCase
public function test_page_remove_favourite_flow() public function test_page_remove_favourite_flow()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$editor = $this->getEditor(); $editor = $this->getEditor();
Favourite::query()->forceCreate([ Favourite::query()->forceCreate([
'user_id' => $editor->id, 'user_id' => $editor->id,
@ -62,8 +62,7 @@ class FavouriteTest extends TestCase
public function test_favourite_flow_with_own_permissions() public function test_favourite_flow_with_own_permissions()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$user = User::factory()->create(); $user = User::factory()->create();
$book->owned_by = $user->id; $book->owned_by = $user->id;
$book->save(); $book->save();
@ -115,8 +114,7 @@ class FavouriteTest extends TestCase
$resp = $this->actingAs($editor)->get('/'); $resp = $this->actingAs($editor)->get('/');
$this->withHtml($resp)->assertElementNotExists('#top-favourites'); $this->withHtml($resp)->assertElementNotExists('#top-favourites');
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$page->favourites()->save((new Favourite())->forceFill(['user_id' => $editor->id])); $page->favourites()->save((new Favourite())->forceFill(['user_id' => $editor->id]));
$resp = $this->get('/'); $resp = $this->get('/');
@ -126,8 +124,7 @@ class FavouriteTest extends TestCase
public function test_favourites_list_page_shows_favourites_and_has_working_pagination() public function test_favourites_list_page_shows_favourites_and_has_working_pagination()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$editor = $this->getEditor(); $editor = $this->getEditor();
$resp = $this->actingAs($editor)->get('/favourites'); $resp = $this->actingAs($editor)->get('/favourites');

View File

@ -141,7 +141,7 @@ class EntityProvider
*/ */
public function newPage(array $input = ['name' => 'test page', 'html' => 'My new test page']): Page public function newPage(array $input = ['name' => 'test page', 'html' => 'My new test page']): Page
{ {
$book = Book::query()->first(); $book = $this->book();
$pageRepo = app(PageRepo::class); $pageRepo = app(PageRepo::class);
$draftPage = $pageRepo->getNewDraftPage($book); $draftPage = $pageRepo->getNewDraftPage($book);
$this->addToCache($draftPage); $this->addToCache($draftPage);

View File

@ -81,8 +81,7 @@ class HomepageTest extends TestCase
public function test_custom_homepage_cannot_be_deleted_from_parent_deletion() public function test_custom_homepage_cannot_be_deleted_from_parent_deletion()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$this->setSettings([ $this->setSettings([
'app-homepage' => $page->id, 'app-homepage' => $page->id,
'app-homepage-type' => 'page', 'app-homepage-type' => 'page',
@ -161,7 +160,7 @@ class HomepageTest extends TestCase
$this->setSettings(['app-homepage-type' => 'bookshelves']); $this->setSettings(['app-homepage-type' => 'bookshelves']);
$this->asEditor(); $this->asEditor();
$shelf = Bookshelf::query()->first(); $shelf = $this->entities->shelf();
$book = $shelf->books()->first(); $book = $shelf->books()->first();
// Ensure initially visible // Ensure initially visible

View File

@ -18,7 +18,7 @@ class OpenGraphTest extends TestCase
public function test_page_tags() public function test_page_tags()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$resp = $this->asEditor()->get($page->getUrl()); $resp = $this->asEditor()->get($page->getUrl());
$tags = $this->getOpenGraphTags($resp); $tags = $this->getOpenGraphTags($resp);
@ -29,7 +29,7 @@ class OpenGraphTest extends TestCase
public function test_chapter_tags() public function test_chapter_tags()
{ {
$chapter = Chapter::query()->first(); $chapter = $this->entities->chapter();
$resp = $this->asEditor()->get($chapter->getUrl()); $resp = $this->asEditor()->get($chapter->getUrl());
$tags = $this->getOpenGraphTags($resp); $tags = $this->getOpenGraphTags($resp);
@ -40,7 +40,7 @@ class OpenGraphTest extends TestCase
public function test_book_tags() public function test_book_tags()
{ {
$book = Book::query()->first(); $book = $this->entities->book();
$resp = $this->asEditor()->get($book->getUrl()); $resp = $this->asEditor()->get($book->getUrl());
$tags = $this->getOpenGraphTags($resp); $tags = $this->getOpenGraphTags($resp);
@ -60,7 +60,7 @@ class OpenGraphTest extends TestCase
public function test_shelf_tags() public function test_shelf_tags()
{ {
$shelf = Bookshelf::query()->first(); $shelf = $this->entities->shelf();
$resp = $this->asEditor()->get($shelf->getUrl()); $resp = $this->asEditor()->get($shelf->getUrl());
$tags = $this->getOpenGraphTags($resp); $tags = $this->getOpenGraphTags($resp);

View File

@ -13,7 +13,7 @@ class EntityOwnerChangeTest extends TestCase
{ {
public function test_changing_page_owner() public function test_changing_page_owner()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$user = User::query()->where('id', '!=', $page->owned_by)->first(); $user = User::query()->where('id', '!=', $page->owned_by)->first();
$this->asAdmin()->put($page->getUrl('permissions'), ['owned_by' => $user->id]); $this->asAdmin()->put($page->getUrl('permissions'), ['owned_by' => $user->id]);
@ -22,7 +22,7 @@ class EntityOwnerChangeTest extends TestCase
public function test_changing_chapter_owner() public function test_changing_chapter_owner()
{ {
$chapter = Chapter::query()->first(); $chapter = $this->entities->chapter();
$user = User::query()->where('id', '!=', $chapter->owned_by)->first(); $user = User::query()->where('id', '!=', $chapter->owned_by)->first();
$this->asAdmin()->put($chapter->getUrl('permissions'), ['owned_by' => $user->id]); $this->asAdmin()->put($chapter->getUrl('permissions'), ['owned_by' => $user->id]);
@ -31,7 +31,7 @@ class EntityOwnerChangeTest extends TestCase
public function test_changing_book_owner() public function test_changing_book_owner()
{ {
$book = Book::query()->first(); $book = $this->entities->book();
$user = User::query()->where('id', '!=', $book->owned_by)->first(); $user = User::query()->where('id', '!=', $book->owned_by)->first();
$this->asAdmin()->put($book->getUrl('permissions'), ['owned_by' => $user->id]); $this->asAdmin()->put($book->getUrl('permissions'), ['owned_by' => $user->id]);
@ -40,7 +40,7 @@ class EntityOwnerChangeTest extends TestCase
public function test_changing_shelf_owner() public function test_changing_shelf_owner()
{ {
$shelf = Bookshelf::query()->first(); $shelf = $this->entities->shelf();
$user = User::query()->where('id', '!=', $shelf->owned_by)->first(); $user = User::query()->where('id', '!=', $shelf->owned_by)->first();
$this->asAdmin()->put($shelf->getUrl('permissions'), ['owned_by' => $user->id]); $this->asAdmin()->put($shelf->getUrl('permissions'), ['owned_by' => $user->id]);

View File

@ -41,8 +41,7 @@ class EntityPermissionsTest extends TestCase
public function test_bookshelf_view_restriction() public function test_bookshelf_view_restriction()
{ {
/** @var Bookshelf $shelf */ $shelf = $this->entities->shelf();
$shelf = Bookshelf::query()->first();
$this->actingAs($this->user) $this->actingAs($this->user)
->get($shelf->getUrl()) ->get($shelf->getUrl())
@ -61,8 +60,7 @@ class EntityPermissionsTest extends TestCase
public function test_bookshelf_update_restriction() public function test_bookshelf_update_restriction()
{ {
/** @var Bookshelf $shelf */ $shelf = $this->entities->shelf();
$shelf = Bookshelf::query()->first();
$this->actingAs($this->user) $this->actingAs($this->user)
->get($shelf->getUrl('/edit')) ->get($shelf->getUrl('/edit'))
@ -82,8 +80,7 @@ class EntityPermissionsTest extends TestCase
public function test_bookshelf_delete_restriction() public function test_bookshelf_delete_restriction()
{ {
/** @var Bookshelf $shelf */ $shelf = $this->entities->shelf();
$shelf = Bookshelf::query()->first();
$this->actingAs($this->user) $this->actingAs($this->user)
->get($shelf->getUrl('/delete')) ->get($shelf->getUrl('/delete'))
@ -103,8 +100,7 @@ class EntityPermissionsTest extends TestCase
public function test_book_view_restriction() public function test_book_view_restriction()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$bookPage = $book->pages->first(); $bookPage = $book->pages->first();
$bookChapter = $book->chapters->first(); $bookChapter = $book->chapters->first();
@ -134,8 +130,7 @@ class EntityPermissionsTest extends TestCase
public function test_book_create_restriction() public function test_book_create_restriction()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$bookUrl = $book->getUrl(); $bookUrl = $book->getUrl();
$resp = $this->actingAs($this->viewer)->get($bookUrl); $resp = $this->actingAs($this->viewer)->get($bookUrl);
@ -181,8 +176,7 @@ class EntityPermissionsTest extends TestCase
public function test_book_update_restriction() public function test_book_update_restriction()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$bookPage = $book->pages->first(); $bookPage = $book->pages->first();
$bookChapter = $book->chapters->first(); $bookChapter = $book->chapters->first();
@ -209,8 +203,7 @@ class EntityPermissionsTest extends TestCase
public function test_book_delete_restriction() public function test_book_delete_restriction()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$bookPage = $book->pages->first(); $bookPage = $book->pages->first();
$bookChapter = $book->chapters->first(); $bookChapter = $book->chapters->first();
@ -236,8 +229,7 @@ class EntityPermissionsTest extends TestCase
public function test_chapter_view_restriction() public function test_chapter_view_restriction()
{ {
/** @var Chapter $chapter */ $chapter = $this->entities->chapter();
$chapter = Chapter::query()->first();
$chapterPage = $chapter->pages->first(); $chapterPage = $chapter->pages->first();
$chapterUrl = $chapter->getUrl(); $chapterUrl = $chapter->getUrl();
@ -256,8 +248,7 @@ class EntityPermissionsTest extends TestCase
public function test_chapter_create_restriction() public function test_chapter_create_restriction()
{ {
/** @var Chapter $chapter */ $chapter = $this->entities->chapter();
$chapter = Chapter::query()->first();
$chapterUrl = $chapter->getUrl(); $chapterUrl = $chapter->getUrl();
$resp = $this->actingAs($this->user)->get($chapterUrl); $resp = $this->actingAs($this->user)->get($chapterUrl);
@ -285,8 +276,7 @@ class EntityPermissionsTest extends TestCase
public function test_chapter_update_restriction() public function test_chapter_update_restriction()
{ {
/** @var Chapter $chapter */ $chapter = $this->entities->chapter();
$chapter = Chapter::query()->first();
$chapterPage = $chapter->pages->first(); $chapterPage = $chapter->pages->first();
$chapterUrl = $chapter->getUrl(); $chapterUrl = $chapter->getUrl();
@ -308,8 +298,7 @@ class EntityPermissionsTest extends TestCase
public function test_chapter_delete_restriction() public function test_chapter_delete_restriction()
{ {
/** @var Chapter $chapter */ $chapter = $this->entities->chapter();
$chapter = Chapter::query()->first();
$chapterPage = $chapter->pages->first(); $chapterPage = $chapter->pages->first();
$chapterUrl = $chapter->getUrl(); $chapterUrl = $chapter->getUrl();
@ -332,8 +321,7 @@ class EntityPermissionsTest extends TestCase
public function test_page_view_restriction() public function test_page_view_restriction()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$pageUrl = $page->getUrl(); $pageUrl = $page->getUrl();
$this->actingAs($this->user)->get($pageUrl)->assertOk(); $this->actingAs($this->user)->get($pageUrl)->assertOk();
@ -349,8 +337,7 @@ class EntityPermissionsTest extends TestCase
public function test_page_update_restriction() public function test_page_update_restriction()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$pageUrl = $page->getUrl(); $pageUrl = $page->getUrl();
$resp = $this->actingAs($this->user) $resp = $this->actingAs($this->user)
@ -371,8 +358,7 @@ class EntityPermissionsTest extends TestCase
public function test_page_delete_restriction() public function test_page_delete_restriction()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$pageUrl = $page->getUrl(); $pageUrl = $page->getUrl();
$this->actingAs($this->user) $this->actingAs($this->user)
@ -436,8 +422,7 @@ class EntityPermissionsTest extends TestCase
public function test_restricted_pages_not_visible_in_book_navigation_on_pages() public function test_restricted_pages_not_visible_in_book_navigation_on_pages()
{ {
/** @var Chapter $chapter */ $chapter = $this->entities->chapter();
$chapter = Chapter::query()->first();
$page = $chapter->pages->first(); $page = $chapter->pages->first();
$page2 = $chapter->pages[2]; $page2 = $chapter->pages[2];
@ -449,8 +434,7 @@ class EntityPermissionsTest extends TestCase
public function test_restricted_pages_not_visible_in_book_navigation_on_chapters() public function test_restricted_pages_not_visible_in_book_navigation_on_chapters()
{ {
/** @var Chapter $chapter */ $chapter = $this->entities->chapter();
$chapter = Chapter::query()->first();
$page = $chapter->pages->first(); $page = $chapter->pages->first();
$this->setRestrictionsForTestRoles($page, []); $this->setRestrictionsForTestRoles($page, []);
@ -461,8 +445,7 @@ class EntityPermissionsTest extends TestCase
public function test_restricted_pages_not_visible_on_chapter_pages() public function test_restricted_pages_not_visible_on_chapter_pages()
{ {
/** @var Chapter $chapter */ $chapter = $this->entities->chapter();
$chapter = Chapter::query()->first();
$page = $chapter->pages->first(); $page = $chapter->pages->first();
$this->setRestrictionsForTestRoles($page, []); $this->setRestrictionsForTestRoles($page, []);
@ -474,8 +457,7 @@ class EntityPermissionsTest extends TestCase
public function test_restricted_chapter_pages_not_visible_on_book_page() public function test_restricted_chapter_pages_not_visible_on_book_page()
{ {
/** @var Chapter $chapter */ $chapter = $this->entities->chapter();
$chapter = Chapter::query()->first();
$this->actingAs($this->user) $this->actingAs($this->user)
->get($chapter->book->getUrl()) ->get($chapter->book->getUrl())
->assertSee($chapter->pages->first()->name); ->assertSee($chapter->pages->first()->name);
@ -491,8 +473,7 @@ class EntityPermissionsTest extends TestCase
public function test_bookshelf_update_restriction_override() public function test_bookshelf_update_restriction_override()
{ {
/** @var Bookshelf $shelf */ $shelf = $this->entities->shelf();
$shelf = Bookshelf::query()->first();
$this->actingAs($this->viewer) $this->actingAs($this->viewer)
->get($shelf->getUrl('/edit')) ->get($shelf->getUrl('/edit'))
@ -510,8 +491,7 @@ class EntityPermissionsTest extends TestCase
public function test_bookshelf_delete_restriction_override() public function test_bookshelf_delete_restriction_override()
{ {
/** @var Bookshelf $shelf */ $shelf = $this->entities->shelf();
$shelf = Bookshelf::query()->first();
$this->actingAs($this->viewer) $this->actingAs($this->viewer)
->get($shelf->getUrl('/delete')) ->get($shelf->getUrl('/delete'))
@ -529,8 +509,7 @@ class EntityPermissionsTest extends TestCase
public function test_book_create_restriction_override() public function test_book_create_restriction_override()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$bookUrl = $book->getUrl(); $bookUrl = $book->getUrl();
$resp = $this->actingAs($this->viewer)->get($bookUrl); $resp = $this->actingAs($this->viewer)->get($bookUrl);
@ -571,8 +550,7 @@ class EntityPermissionsTest extends TestCase
public function test_book_update_restriction_override() public function test_book_update_restriction_override()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$bookPage = $book->pages->first(); $bookPage = $book->pages->first();
$bookChapter = $book->chapters->first(); $bookChapter = $book->chapters->first();
@ -598,8 +576,7 @@ class EntityPermissionsTest extends TestCase
public function test_book_delete_restriction_override() public function test_book_delete_restriction_override()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$bookPage = $book->pages->first(); $bookPage = $book->pages->first();
$bookChapter = $book->chapters->first(); $bookChapter = $book->chapters->first();
@ -626,8 +603,7 @@ class EntityPermissionsTest extends TestCase
public function test_page_visible_if_has_permissions_when_book_not_visible() public function test_page_visible_if_has_permissions_when_book_not_visible()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$bookChapter = $book->chapters->first(); $bookChapter = $book->chapters->first();
$bookPage = $bookChapter->pages->first(); $bookPage = $bookChapter->pages->first();
@ -667,8 +643,7 @@ class EntityPermissionsTest extends TestCase
public function test_can_create_page_if_chapter_has_permissions_when_book_not_visible() public function test_can_create_page_if_chapter_has_permissions_when_book_not_visible()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$this->setRestrictionsForTestRoles($book, []); $this->setRestrictionsForTestRoles($book, []);
$bookChapter = $book->chapters->first(); $bookChapter = $book->chapters->first();
$this->setRestrictionsForTestRoles($bookChapter, ['view']); $this->setRestrictionsForTestRoles($bookChapter, ['view']);

View File

@ -11,7 +11,7 @@ class ExportPermissionsTest extends TestCase
{ {
public function test_page_content_without_view_access_hidden_on_chapter_export() public function test_page_content_without_view_access_hidden_on_chapter_export()
{ {
$chapter = Chapter::query()->first(); $chapter = $this->entities->chapter();
$page = $chapter->pages()->firstOrFail(); $page = $chapter->pages()->firstOrFail();
$pageContent = Str::random(48); $pageContent = Str::random(48);
$page->html = '<p>' . $pageContent . '</p>'; $page->html = '<p>' . $pageContent . '</p>';
@ -39,7 +39,7 @@ class ExportPermissionsTest extends TestCase
public function test_page_content_without_view_access_hidden_on_book_export() public function test_page_content_without_view_access_hidden_on_book_export()
{ {
$book = Book::query()->first(); $book = $this->entities->book();
$page = $book->pages()->firstOrFail(); $page = $book->pages()->firstOrFail();
$pageContent = Str::random(48); $pageContent = Str::random(48);
$page->html = '<p>' . $pageContent . '</p>'; $page->html = '<p>' . $pageContent . '</p>';

View File

@ -520,8 +520,7 @@ class RolesTest extends TestCase
public function test_chapter_create_all_permissions() public function test_chapter_create_all_permissions()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$this->checkAccessPermission('chapter-create-all', [ $this->checkAccessPermission('chapter-create-all', [
$book->getUrl('/create-chapter'), $book->getUrl('/create-chapter'),
], [ ], [
@ -603,10 +602,8 @@ class RolesTest extends TestCase
public function test_page_create_own_permissions() public function test_page_create_own_permissions()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first(); $chapter = $this->entities->chapter();
/** @var Chapter $chapter */
$chapter = Chapter::query()->first();
$entities = $this->entities->createChainBelongingToUser($this->user); $entities = $this->entities->createChainBelongingToUser($this->user);
$ownBook = $entities['book']; $ownBook = $entities['book'];
@ -652,10 +649,8 @@ class RolesTest extends TestCase
public function test_page_create_all_permissions() public function test_page_create_all_permissions()
{ {
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first(); $chapter = $this->entities->chapter();
/** @var Chapter $chapter */
$chapter = Chapter::query()->first();
$createUrl = $book->getUrl('/create-page'); $createUrl = $book->getUrl('/create-page');
$createUrlChapter = $chapter->getUrl('/create-page'); $createUrlChapter = $chapter->getUrl('/create-page');
@ -806,8 +801,7 @@ class RolesTest extends TestCase
public function test_image_delete_own_permission() public function test_image_delete_own_permission()
{ {
$this->giveUserPermissions($this->user, ['image-update-all']); $this->giveUserPermissions($this->user, ['image-update-all']);
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$image = Image::factory()->create([ $image = Image::factory()->create([
'uploaded_to' => $page->id, 'uploaded_to' => $page->id,
'created_by' => $this->user->id, 'created_by' => $this->user->id,
@ -826,8 +820,7 @@ class RolesTest extends TestCase
{ {
$this->giveUserPermissions($this->user, ['image-update-all']); $this->giveUserPermissions($this->user, ['image-update-all']);
$admin = $this->getAdmin(); $admin = $this->getAdmin();
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$image = Image::factory()->create(['uploaded_to' => $page->id, 'created_by' => $admin->id, 'updated_by' => $admin->id]); $image = Image::factory()->create(['uploaded_to' => $page->id, 'created_by' => $admin->id, 'updated_by' => $admin->id]);
$this->actingAs($this->user)->json('delete', '/images/' . $image->id)->assertStatus(403); $this->actingAs($this->user)->json('delete', '/images/' . $image->id)->assertStatus(403);
@ -845,8 +838,7 @@ class RolesTest extends TestCase
public function test_role_permission_removal() public function test_role_permission_removal()
{ {
// To cover issue fixed in f99c8ff99aee9beb8c692f36d4b84dc6e651e50a. // To cover issue fixed in f99c8ff99aee9beb8c692f36d4b84dc6e651e50a.
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$viewerRole = Role::getRole('viewer'); $viewerRole = Role::getRole('viewer');
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$this->actingAs($viewer)->get($page->getUrl())->assertOk(); $this->actingAs($viewer)->get($page->getUrl())->assertOk();

View File

@ -17,11 +17,11 @@ class PublicActionTest extends TestCase
public function test_app_not_public() public function test_app_not_public()
{ {
$this->setSettings(['app-public' => 'false']); $this->setSettings(['app-public' => 'false']);
$book = Book::query()->first(); $book = $this->entities->book();
$this->get('/books')->assertRedirect('/login'); $this->get('/books')->assertRedirect('/login');
$this->get($book->getUrl())->assertRedirect('/login'); $this->get($book->getUrl())->assertRedirect('/login');
$page = Page::query()->first(); $page = $this->entities->page();
$this->get($page->getUrl())->assertRedirect('/login'); $this->get($page->getUrl())->assertRedirect('/login');
} }
@ -93,8 +93,7 @@ class PublicActionTest extends TestCase
$this->app->make(JointPermissionBuilder::class)->rebuildForRole($publicRole); $this->app->make(JointPermissionBuilder::class)->rebuildForRole($publicRole);
user()->clearPermissionCache(); user()->clearPermissionCache();
/** @var Chapter $chapter */ $chapter = $this->entities->chapter();
$chapter = Chapter::query()->first();
$resp = $this->get($chapter->getUrl()); $resp = $this->get($chapter->getUrl());
$resp->assertSee('New Page'); $resp->assertSee('New Page');
$this->withHtml($resp)->assertElementExists('a[href="' . $chapter->getUrl('/create-page') . '"]'); $this->withHtml($resp)->assertElementExists('a[href="' . $chapter->getUrl('/create-page') . '"]');
@ -118,7 +117,7 @@ class PublicActionTest extends TestCase
public function test_content_not_listed_on_404_for_public_users() public function test_content_not_listed_on_404_for_public_users()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$page->fill(['name' => 'my testing random unique page name'])->save(); $page->fill(['name' => 'my testing random unique page name'])->save();
$this->asAdmin()->get($page->getUrl()); // Fake visit to show on recents $this->asAdmin()->get($page->getUrl()); // Fake visit to show on recents
$resp = $this->get('/cats/dogs/hippos'); $resp = $this->get('/cats/dogs/hippos');
@ -162,8 +161,7 @@ class PublicActionTest extends TestCase
public function test_public_view_then_login_redirects_to_previous_content() public function test_public_view_then_login_redirects_to_previous_content()
{ {
$this->setSettings(['app-public' => 'true']); $this->setSettings(['app-public' => 'true']);
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$resp = $this->get($book->getUrl()); $resp = $this->get($book->getUrl());
$resp->assertSee($book->name); $resp->assertSee($book->name);
@ -175,8 +173,7 @@ class PublicActionTest extends TestCase
public function test_access_hidden_content_then_login_redirects_to_intended_content() public function test_access_hidden_content_then_login_redirects_to_intended_content()
{ {
$this->setSettings(['app-public' => 'true']); $this->setSettings(['app-public' => 'true']);
/** @var Book $book */ $book = $this->entities->book();
$book = Book::query()->first();
$this->entities->setPermissions($book); $this->entities->setPermissions($book);
$resp = $this->get($book->getUrl()); $resp = $this->get($book->getUrl());

View File

@ -40,7 +40,7 @@ class CrossLinkParserTest extends TestCase
public function test_similar_page_and_book_reference_links_dont_conflict() public function test_similar_page_and_book_reference_links_dont_conflict()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$book = $page->book; $book = $page->book;
$html = ' $html = '

View File

@ -97,7 +97,7 @@ class ReferencesTest extends TestCase
{ {
/** @var Page $page */ /** @var Page $page */
/** @var Page $pageB */ /** @var Page $pageB */
$page = Page::query()->first(); $page = $this->entities->page();
$pageB = Page::query()->where('id', '!=', $page->id)->first(); $pageB = Page::query()->where('id', '!=', $page->id)->first();
$this->createReference($pageB, $page); $this->createReference($pageB, $page);
@ -109,8 +109,7 @@ class ReferencesTest extends TestCase
public function test_reference_page_shows_empty_state_with_no_references() public function test_reference_page_shows_empty_state_with_no_references()
{ {
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$this->asEditor() $this->asEditor()
->get($page->getUrl('/references')) ->get($page->getUrl('/references'))
@ -124,7 +123,7 @@ class ReferencesTest extends TestCase
/** @var Book $book */ /** @var Book $book */
$pageA = Page::query()->first(); $pageA = Page::query()->first();
$pageB = Page::query()->where('id', '!=', $pageA->id)->first(); $pageB = Page::query()->where('id', '!=', $pageA->id)->first();
$book = Book::query()->first(); $book = $this->entities->book();
foreach ([$pageA, $pageB] as $page) { foreach ([$pageA, $pageB] as $page) {
$page->html = '<a href="' . $book->getUrl() . '">Link</a>'; $page->html = '<a href="' . $book->getUrl() . '">Link</a>';
@ -200,8 +199,8 @@ class ReferencesTest extends TestCase
{ {
/** @var Page $page */ /** @var Page $page */
/** @var Book $book */ /** @var Book $book */
$page = Page::query()->first(); $page = $this->entities->page();
$book = Book::query()->first(); $book = $this->entities->book();
$bookUrl = $book->getUrl(); $bookUrl = $book->getUrl();
$markdown = ' $markdown = '

View File

@ -16,7 +16,7 @@ class RecycleBinTest extends TestCase
{ {
public function test_recycle_bin_routes_permissions() public function test_recycle_bin_routes_permissions()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$editor = $this->getEditor(); $editor = $this->getEditor();
$this->actingAs($editor)->delete($page->getUrl()); $this->actingAs($editor)->delete($page->getUrl());
$deletion = Deletion::query()->firstOrFail(); $deletion = Deletion::query()->firstOrFail();
@ -57,7 +57,7 @@ class RecycleBinTest extends TestCase
public function test_recycle_bin_view() public function test_recycle_bin_view()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$book = Book::query()->whereHas('pages')->whereHas('chapters')->withCount(['pages', 'chapters'])->first(); $book = Book::query()->whereHas('pages')->whereHas('chapters')->withCount(['pages', 'chapters'])->first();
$editor = $this->getEditor(); $editor = $this->getEditor();
$this->actingAs($editor)->delete($page->getUrl()); $this->actingAs($editor)->delete($page->getUrl());
@ -74,7 +74,7 @@ class RecycleBinTest extends TestCase
public function test_recycle_bin_empty() public function test_recycle_bin_empty()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$book = Book::query()->where('id', '!=', $page->book_id)->whereHas('pages')->whereHas('chapters')->with(['pages', 'chapters'])->firstOrFail(); $book = Book::query()->where('id', '!=', $page->book_id)->whereHas('pages')->whereHas('chapters')->with(['pages', 'chapters'])->firstOrFail();
$editor = $this->getEditor(); $editor = $this->getEditor();
$this->actingAs($editor)->delete($page->getUrl()); $this->actingAs($editor)->delete($page->getUrl());

View File

@ -64,7 +64,7 @@ class ThemeTest extends TestCase
}; };
Theme::listen(ThemeEvents::COMMONMARK_ENVIRONMENT_CONFIGURE, $callback); Theme::listen(ThemeEvents::COMMONMARK_ENVIRONMENT_CONFIGURE, $callback);
$page = Page::query()->first(); $page = $this->entities->page();
$content = new PageContent($page); $content = new PageContent($page);
$content->setNewMarkdown('# test'); $content->setNewMarkdown('# test');
@ -199,7 +199,7 @@ class ThemeTest extends TestCase
public function test_event_activity_logged() public function test_event_activity_logged()
{ {
$book = Book::query()->first(); $book = $this->entities->book();
$args = []; $args = [];
$callback = function (...$eventArgs) use (&$args) { $callback = function (...$eventArgs) use (&$args) {
$args = $eventArgs; $args = $eventArgs;
@ -218,7 +218,7 @@ class ThemeTest extends TestCase
{ {
/** @var Page $page */ /** @var Page $page */
/** @var Page $otherPage */ /** @var Page $otherPage */
$page = Page::query()->first(); $page = $this->entities->page();
$otherPage = Page::query()->where('id', '!=', $page->id)->first(); $otherPage = Page::query()->where('id', '!=', $page->id)->first();
$otherPage->html = '<p id="bkmrk-cool">This is a really cool section</p>'; $otherPage->html = '<p id="bkmrk-cool">This is a really cool section</p>';
$page->html = "<p>{{@{$otherPage->id}#bkmrk-cool}}</p>"; $page->html = "<p>{{@{$otherPage->id}#bkmrk-cool}}</p>";
@ -324,8 +324,7 @@ class ThemeTest extends TestCase
{ {
$bodyStartStr = 'garry-fought-against-the-panther'; $bodyStartStr = 'garry-fought-against-the-panther';
$bodyEndStr = 'garry-lost-his-fight-with-grace'; $bodyEndStr = 'garry-lost-his-fight-with-grace';
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$this->usingThemeFolder(function (string $folder) use ($bodyStartStr, $bodyEndStr, $page) { $this->usingThemeFolder(function (string $folder) use ($bodyStartStr, $bodyEndStr, $page) {
$viewDir = theme_path('layouts/parts'); $viewDir = theme_path('layouts/parts');

View File

@ -73,7 +73,7 @@ class AttachmentTest extends TestCase
public function test_file_upload() public function test_file_upload()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$this->asAdmin(); $this->asAdmin();
$admin = $this->getAdmin(); $admin = $this->getAdmin();
$fileName = 'upload_test_file.txt'; $fileName = 'upload_test_file.txt';
@ -101,7 +101,7 @@ class AttachmentTest extends TestCase
public function test_file_upload_does_not_use_filename() public function test_file_upload_does_not_use_filename()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$fileName = 'upload_test_file.txt'; $fileName = 'upload_test_file.txt';
$upload = $this->asAdmin()->uploadFile($fileName, $page->id); $upload = $this->asAdmin()->uploadFile($fileName, $page->id);
@ -115,7 +115,7 @@ class AttachmentTest extends TestCase
public function test_file_display_and_access() public function test_file_display_and_access()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$this->asAdmin(); $this->asAdmin();
$fileName = 'upload_test_file.txt'; $fileName = 'upload_test_file.txt';
@ -136,7 +136,7 @@ class AttachmentTest extends TestCase
public function test_attaching_link_to_page() public function test_attaching_link_to_page()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$admin = $this->getAdmin(); $admin = $this->getAdmin();
$this->asAdmin(); $this->asAdmin();
@ -173,7 +173,7 @@ class AttachmentTest extends TestCase
public function test_attachment_updating() public function test_attachment_updating()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$this->asAdmin(); $this->asAdmin();
$attachment = $this->createAttachment($page); $attachment = $this->createAttachment($page);
@ -197,7 +197,7 @@ class AttachmentTest extends TestCase
public function test_file_deletion() public function test_file_deletion()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$this->asAdmin(); $this->asAdmin();
$fileName = 'deletion_test.txt'; $fileName = 'deletion_test.txt';
$this->uploadFile($fileName, $page->id); $this->uploadFile($fileName, $page->id);
@ -219,7 +219,7 @@ class AttachmentTest extends TestCase
public function test_attachment_deletion_on_page_deletion() public function test_attachment_deletion_on_page_deletion()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$this->asAdmin(); $this->asAdmin();
$fileName = 'deletion_test.txt'; $fileName = 'deletion_test.txt';
$this->uploadFile($fileName, $page->id); $this->uploadFile($fileName, $page->id);
@ -247,7 +247,7 @@ class AttachmentTest extends TestCase
{ {
$admin = $this->getAdmin(); $admin = $this->getAdmin();
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$page = Page::query()->first(); /** @var Page $page */ $page = $this->entities->page(); /** @var Page $page */
$this->actingAs($admin); $this->actingAs($admin);
$fileName = 'permission_test.txt'; $fileName = 'permission_test.txt';
$this->uploadFile($fileName, $page->id); $this->uploadFile($fileName, $page->id);
@ -269,7 +269,7 @@ class AttachmentTest extends TestCase
public function test_data_and_js_links_cannot_be_attached_to_a_page() public function test_data_and_js_links_cannot_be_attached_to_a_page()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$this->asAdmin(); $this->asAdmin();
$badLinks = [ $badLinks = [
@ -310,7 +310,7 @@ class AttachmentTest extends TestCase
public function test_file_access_with_open_query_param_provides_inline_response_with_correct_content_type() public function test_file_access_with_open_query_param_provides_inline_response_with_correct_content_type()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$this->asAdmin(); $this->asAdmin();
$fileName = 'upload_test_file.txt'; $fileName = 'upload_test_file.txt';
@ -329,7 +329,7 @@ class AttachmentTest extends TestCase
public function test_html_file_access_with_open_forces_plain_content_type() public function test_html_file_access_with_open_forces_plain_content_type()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$this->asAdmin(); $this->asAdmin();
$attachment = $this->createUploadAttachment($page, 'test_file.html', '<html></html><p>testing</p>', 'text/html'); $attachment = $this->createUploadAttachment($page, 'test_file.html', '<html></html><p>testing</p>', 'text/html');
@ -346,7 +346,7 @@ class AttachmentTest extends TestCase
{ {
config()->set('filesystems.attachments', 'local_secure_restricted'); config()->set('filesystems.attachments', 'local_secure_restricted');
$page = Page::query()->first(); $page = $this->entities->page();
$fileName = 'upload_test_file.txt'; $fileName = 'upload_test_file.txt';
$upload = $this->asAdmin()->uploadFile($fileName, $page->id); $upload = $this->asAdmin()->uploadFile($fileName, $page->id);

View File

@ -15,7 +15,7 @@ class ImageTest extends TestCase
public function test_image_upload() public function test_image_upload()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$admin = $this->getAdmin(); $admin = $this->getAdmin();
$this->actingAs($admin); $this->actingAs($admin);
@ -39,7 +39,7 @@ class ImageTest extends TestCase
public function test_image_display_thumbnail_generation_does_not_increase_image_size() public function test_image_display_thumbnail_generation_does_not_increase_image_size()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$admin = $this->getAdmin(); $admin = $this->getAdmin();
$this->actingAs($admin); $this->actingAs($admin);
@ -63,7 +63,7 @@ class ImageTest extends TestCase
public function test_image_display_thumbnail_generation_for_apng_images_uses_original_file() public function test_image_display_thumbnail_generation_for_apng_images_uses_original_file()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$admin = $this->getAdmin(); $admin = $this->getAdmin();
$this->actingAs($admin); $this->actingAs($admin);
@ -125,7 +125,7 @@ class ImageTest extends TestCase
public function test_image_usage() public function test_image_usage()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$editor = $this->getEditor(); $editor = $this->getEditor();
$this->actingAs($editor); $this->actingAs($editor);
@ -145,7 +145,7 @@ class ImageTest extends TestCase
public function test_php_files_cannot_be_uploaded() public function test_php_files_cannot_be_uploaded()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$admin = $this->getAdmin(); $admin = $this->getAdmin();
$this->actingAs($admin); $this->actingAs($admin);
@ -167,7 +167,7 @@ class ImageTest extends TestCase
public function test_php_like_files_cannot_be_uploaded() public function test_php_like_files_cannot_be_uploaded()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$admin = $this->getAdmin(); $admin = $this->getAdmin();
$this->actingAs($admin); $this->actingAs($admin);
@ -184,7 +184,7 @@ class ImageTest extends TestCase
public function test_files_with_double_extensions_will_get_sanitized() public function test_files_with_double_extensions_will_get_sanitized()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$admin = $this->getAdmin(); $admin = $this->getAdmin();
$this->actingAs($admin); $this->actingAs($admin);
@ -219,7 +219,7 @@ class ImageTest extends TestCase
]; ];
foreach ($badNames as $name) { foreach ($badNames as $name) {
$galleryFile = $this->getTestImage($name); $galleryFile = $this->getTestImage($name);
$page = Page::query()->first(); $page = $this->entities->page();
$badPath = $this->getTestImagePath('gallery', $name); $badPath = $this->getTestImagePath('gallery', $name);
$this->deleteImage($badPath); $this->deleteImage($badPath);
@ -244,7 +244,7 @@ class ImageTest extends TestCase
config()->set('filesystems.images', 'local_secure'); config()->set('filesystems.images', 'local_secure');
$this->asEditor(); $this->asEditor();
$galleryFile = $this->getTestImage('my-secure-test-upload.png'); $galleryFile = $this->getTestImage('my-secure-test-upload.png');
$page = Page::query()->first(); $page = $this->entities->page();
$expectedPath = storage_path('uploads/images/gallery/' . date('Y-m') . '/my-secure-test-upload.png'); $expectedPath = storage_path('uploads/images/gallery/' . date('Y-m') . '/my-secure-test-upload.png');
$upload = $this->call('POST', '/images/gallery', ['uploaded_to' => $page->id], [], ['file' => $galleryFile], []); $upload = $this->call('POST', '/images/gallery', ['uploaded_to' => $page->id], [], ['file' => $galleryFile], []);
@ -292,7 +292,7 @@ class ImageTest extends TestCase
config()->set('filesystems.images', 'local_secure'); config()->set('filesystems.images', 'local_secure');
$this->asEditor(); $this->asEditor();
$galleryFile = $this->getTestImage('my-secure-test-upload.png'); $galleryFile = $this->getTestImage('my-secure-test-upload.png');
$page = Page::query()->first(); $page = $this->entities->page();
$expectedPath = storage_path('uploads/images/gallery/' . date('Y-m') . '/my-secure-test-upload.png'); $expectedPath = storage_path('uploads/images/gallery/' . date('Y-m') . '/my-secure-test-upload.png');
$upload = $this->call('POST', '/images/gallery', ['uploaded_to' => $page->id], [], ['file' => $galleryFile], []); $upload = $this->call('POST', '/images/gallery', ['uploaded_to' => $page->id], [], ['file' => $galleryFile], []);
@ -332,8 +332,7 @@ class ImageTest extends TestCase
config()->set('filesystems.images', 'local_secure_restricted'); config()->set('filesystems.images', 'local_secure_restricted');
$this->asEditor(); $this->asEditor();
$galleryFile = $this->getTestImage('my-secure-restricted-test-upload.png'); $galleryFile = $this->getTestImage('my-secure-restricted-test-upload.png');
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$upload = $this->call('POST', '/images/gallery', ['uploaded_to' => $page->id], [], ['file' => $galleryFile], []); $upload = $this->call('POST', '/images/gallery', ['uploaded_to' => $page->id], [], ['file' => $galleryFile], []);
$upload->assertStatus(200); $upload->assertStatus(200);
@ -357,8 +356,7 @@ class ImageTest extends TestCase
config()->set('filesystems.images', 'local_secure_restricted'); config()->set('filesystems.images', 'local_secure_restricted');
$this->asEditor(); $this->asEditor();
$galleryFile = $this->getTestImage('my-secure-restricted-thumb-test-test.png'); $galleryFile = $this->getTestImage('my-secure-restricted-thumb-test-test.png');
/** @var Page $page */ $page = $this->entities->page();
$page = Page::query()->first();
$upload = $this->call('POST', '/images/gallery', ['uploaded_to' => $page->id], [], ['file' => $galleryFile], []); $upload = $this->call('POST', '/images/gallery', ['uploaded_to' => $page->id], [], ['file' => $galleryFile], []);
$upload->assertStatus(200); $upload->assertStatus(200);
@ -412,7 +410,7 @@ class ImageTest extends TestCase
public function test_image_delete() public function test_image_delete()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$this->asAdmin(); $this->asAdmin();
$imageName = 'first-image.png'; $imageName = 'first-image.png';
$relPath = $this->getTestImagePath('gallery', $imageName); $relPath = $this->getTestImagePath('gallery', $imageName);
@ -434,7 +432,7 @@ class ImageTest extends TestCase
public function test_image_delete_does_not_delete_similar_images() public function test_image_delete_does_not_delete_similar_images()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$this->asAdmin(); $this->asAdmin();
$imageName = 'first-image.png'; $imageName = 'first-image.png';
@ -459,7 +457,7 @@ class ImageTest extends TestCase
public function test_image_manager_delete_button_only_shows_with_permission() public function test_image_manager_delete_button_only_shows_with_permission()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$this->asAdmin(); $this->asAdmin();
$imageName = 'first-image.png'; $imageName = 'first-image.png';
$relPath = $this->getTestImagePath('gallery', $imageName); $relPath = $this->getTestImagePath('gallery', $imageName);
@ -539,7 +537,7 @@ class ImageTest extends TestCase
public function test_deleted_unused_images() public function test_deleted_unused_images()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$admin = $this->getAdmin(); $admin = $this->getAdmin();
$this->actingAs($admin); $this->actingAs($admin);

View File

@ -91,7 +91,7 @@ trait UsesImages
protected function uploadGalleryImage(Page $page = null, ?string $testDataFileName = null) protected function uploadGalleryImage(Page $page = null, ?string $testDataFileName = null)
{ {
if ($page === null) { if ($page === null) {
$page = Page::query()->first(); $page = $this->entities->page();
} }
$imageName = $testDataFileName ?? 'first-image.png'; $imageName = $testDataFileName ?? 'first-image.png';

View File

@ -150,7 +150,7 @@ class UserManagementTest extends TestCase
public function test_delete_with_new_owner_id_changes_ownership() public function test_delete_with_new_owner_id_changes_ownership()
{ {
$page = Page::query()->first(); $page = $this->entities->page();
$owner = $page->ownedBy; $owner = $page->ownedBy;
$newOwner = User::query()->where('id', '!=', $owner->id)->first(); $newOwner = User::query()->where('id', '!=', $owner->id)->first();

View File

@ -132,8 +132,7 @@ class UserPreferencesTest extends TestCase
public function test_shelf_view_type_change() public function test_shelf_view_type_change()
{ {
$editor = $this->getEditor(); $editor = $this->getEditor();
/** @var Bookshelf $shelf */ $shelf = $this->entities->shelf();
$shelf = Bookshelf::query()->first();
setting()->putUser($editor, 'bookshelf_view_type', 'list'); setting()->putUser($editor, 'bookshelf_view_type', 'list');
$resp = $this->actingAs($editor)->get($shelf->getUrl())->assertSee('Grid View'); $resp = $this->actingAs($editor)->get($shelf->getUrl())->assertSee('Grid View');
@ -155,7 +154,7 @@ class UserPreferencesTest extends TestCase
public function test_update_code_language_favourite() public function test_update_code_language_favourite()
{ {
$editor = $this->getEditor(); $editor = $this->getEditor();
$page = Page::query()->first(); $page = $this->entities->page();
$this->actingAs($editor); $this->actingAs($editor);
$this->patch('/settings/users/update-code-language-favourite', ['language' => 'php', 'active' => true]); $this->patch('/settings/users/update-code-language-favourite', ['language' => 'php', 'active' => true]);