diff --git a/app/Api/ListingResponseBuilder.php b/app/Api/ListingResponseBuilder.php index 7de5ddf07..39752e6d4 100644 --- a/app/Api/ListingResponseBuilder.php +++ b/app/Api/ListingResponseBuilder.php @@ -2,7 +2,6 @@ namespace BookStack\Api; -use BookStack\Model; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; use Illuminate\Http\JsonResponse; diff --git a/tests/Actions/AuditLogTest.php b/tests/Actions/AuditLogTest.php index f4eebb364..987e23a45 100644 --- a/tests/Actions/AuditLogTest.php +++ b/tests/Actions/AuditLogTest.php @@ -6,8 +6,6 @@ use BookStack\Actions\Activity; use BookStack\Actions\ActivityLogger; use BookStack\Actions\ActivityType; use BookStack\Auth\UserRepo; -use BookStack\Entities\Models\Chapter; -use BookStack\Entities\Models\Page; use BookStack\Entities\Repos\PageRepo; use BookStack\Entities\Tools\TrashCan; use Carbon\Carbon; @@ -15,8 +13,7 @@ use Tests\TestCase; class AuditLogTest extends TestCase { - /** @var ActivityLogger */ - protected $activityService; + protected ActivityLogger $activityService; protected function setUp(): void { diff --git a/tests/Actions/WebhookCallTest.php b/tests/Actions/WebhookCallTest.php index 7964fd8af..7ca190200 100644 --- a/tests/Actions/WebhookCallTest.php +++ b/tests/Actions/WebhookCallTest.php @@ -7,7 +7,6 @@ use BookStack\Actions\ActivityType; use BookStack\Actions\DispatchWebhookJob; use BookStack\Actions\Webhook; use BookStack\Auth\User; -use BookStack\Entities\Models\Page; use Illuminate\Http\Client\Request; use Illuminate\Support\Facades\Bus; use Illuminate\Support\Facades\Http; diff --git a/tests/Actions/WebhookFormatTesting.php b/tests/Actions/WebhookFormatTesting.php index 35467a76a..07341c75b 100644 --- a/tests/Actions/WebhookFormatTesting.php +++ b/tests/Actions/WebhookFormatTesting.php @@ -5,9 +5,6 @@ namespace Tests\Actions; use BookStack\Actions\ActivityType; use BookStack\Actions\Webhook; use BookStack\Actions\WebhookFormatter; -use BookStack\Entities\Models\Book; -use BookStack\Entities\Models\Chapter; -use BookStack\Entities\Models\Page; use Illuminate\Support\Arr; use Tests\TestCase; @@ -16,9 +13,9 @@ class WebhookFormatTesting extends TestCase public function test_entity_events_show_related_user_info() { $events = [ - ActivityType::BOOK_UPDATE => Book::query()->first(), - ActivityType::CHAPTER_CREATE => Chapter::query()->first(), - ActivityType::PAGE_MOVE => Page::query()->first(), + ActivityType::BOOK_UPDATE => $this->entities->book(), + ActivityType::CHAPTER_CREATE => $this->entities->chapter(), + ActivityType::PAGE_MOVE => $this->entities->page(), ]; foreach ($events as $event => $entity) { diff --git a/tests/Api/BooksApiTest.php b/tests/Api/BooksApiTest.php index 017322193..614185c93 100644 --- a/tests/Api/BooksApiTest.php +++ b/tests/Api/BooksApiTest.php @@ -68,7 +68,7 @@ class BooksApiTest extends TestCase public function test_read_endpoint() { $this->actingAsApiEditor(); - $book = Book::visible()->first(); + $book = $this->entities->book(); $resp = $this->getJson($this->baseEndpoint . "/{$book->id}"); @@ -91,8 +91,7 @@ class BooksApiTest extends TestCase public function test_read_endpoint_includes_chapter_and_page_contents() { $this->actingAsApiEditor(); - /** @var Book $book */ - $book = Book::visible()->has('chapters')->has('pages')->first(); + $book = $this->entities->bookHasChaptersAndPages(); $chapter = $book->chapters()->first(); $chapterPage = $chapter->pages()->first(); @@ -123,7 +122,7 @@ class BooksApiTest extends TestCase public function test_update_endpoint() { $this->actingAsApiEditor(); - $book = Book::visible()->first(); + $book = $this->entities->book(); $details = [ 'name' => 'My updated API book', 'description' => 'A book created via the API', @@ -140,7 +139,7 @@ class BooksApiTest extends TestCase public function test_update_increments_updated_date_if_only_tags_are_sent() { $this->actingAsApiEditor(); - $book = Book::visible()->first(); + $book = $this->entities->book(); DB::table('books')->where('id', '=', $book->id)->update(['updated_at' => Carbon::now()->subWeek()]); $details = [ @@ -156,7 +155,7 @@ class BooksApiTest extends TestCase { $this->actingAsApiEditor(); /** @var Book $book */ - $book = Book::visible()->first(); + $book = $this->entities->book(); $this->assertNull($book->cover); $file = $this->getTestImage('image.png'); @@ -191,7 +190,7 @@ class BooksApiTest extends TestCase public function test_delete_endpoint() { $this->actingAsApiEditor(); - $book = Book::visible()->first(); + $book = $this->entities->book(); $resp = $this->deleteJson($this->baseEndpoint . "/{$book->id}"); $resp->assertStatus(204); @@ -201,7 +200,7 @@ class BooksApiTest extends TestCase public function test_export_html_endpoint() { $this->actingAsApiEditor(); - $book = Book::visible()->first(); + $book = $this->entities->book(); $resp = $this->get($this->baseEndpoint . "/{$book->id}/export/html"); $resp->assertStatus(200); @@ -212,7 +211,7 @@ class BooksApiTest extends TestCase public function test_export_plain_text_endpoint() { $this->actingAsApiEditor(); - $book = Book::visible()->first(); + $book = $this->entities->book(); $resp = $this->get($this->baseEndpoint . "/{$book->id}/export/plaintext"); $resp->assertStatus(200); @@ -223,7 +222,7 @@ class BooksApiTest extends TestCase public function test_export_pdf_endpoint() { $this->actingAsApiEditor(); - $book = Book::visible()->first(); + $book = $this->entities->book(); $resp = $this->get($this->baseEndpoint . "/{$book->id}/export/pdf"); $resp->assertStatus(200); @@ -249,7 +248,7 @@ class BooksApiTest extends TestCase $this->actingAsApiEditor(); $this->removePermissionFromUser($this->getEditor(), 'content-export'); - $book = Book::visible()->first(); + $book = $this->entities->book(); foreach ($types as $type) { $resp = $this->get($this->baseEndpoint . "/{$book->id}/export/{$type}"); $this->assertPermissionError($resp); diff --git a/tests/Api/ChaptersApiTest.php b/tests/Api/ChaptersApiTest.php index 22be2482c..d2db0313f 100644 --- a/tests/Api/ChaptersApiTest.php +++ b/tests/Api/ChaptersApiTest.php @@ -2,7 +2,6 @@ namespace Tests\Api; -use BookStack\Entities\Models\Book; use BookStack\Entities\Models\Chapter; use Carbon\Carbon; use Illuminate\Support\Facades\DB; @@ -95,7 +94,7 @@ class ChaptersApiTest extends TestCase public function test_read_endpoint() { $this->actingAsApiEditor(); - $chapter = Chapter::visible()->first(); + $chapter = $this->entities->chapter(); $page = $chapter->pages()->first(); $resp = $this->getJson($this->baseEndpoint . "/{$chapter->id}"); @@ -127,7 +126,7 @@ class ChaptersApiTest extends TestCase public function test_update_endpoint() { $this->actingAsApiEditor(); - $chapter = Chapter::visible()->first(); + $chapter = $this->entities->chapter(); $details = [ 'name' => 'My updated API chapter', 'description' => 'A chapter created via the API', @@ -152,7 +151,7 @@ class ChaptersApiTest extends TestCase public function test_update_increments_updated_date_if_only_tags_are_sent() { $this->actingAsApiEditor(); - $chapter = Chapter::visible()->first(); + $chapter = $this->entities->chapter(); DB::table('chapters')->where('id', '=', $chapter->id)->update(['updated_at' => Carbon::now()->subWeek()]); $details = [ @@ -167,7 +166,7 @@ class ChaptersApiTest extends TestCase public function test_delete_endpoint() { $this->actingAsApiEditor(); - $chapter = Chapter::visible()->first(); + $chapter = $this->entities->chapter(); $resp = $this->deleteJson($this->baseEndpoint . "/{$chapter->id}"); $resp->assertStatus(204); @@ -177,7 +176,7 @@ class ChaptersApiTest extends TestCase public function test_export_html_endpoint() { $this->actingAsApiEditor(); - $chapter = Chapter::visible()->first(); + $chapter = $this->entities->chapter(); $resp = $this->get($this->baseEndpoint . "/{$chapter->id}/export/html"); $resp->assertStatus(200); @@ -188,7 +187,7 @@ class ChaptersApiTest extends TestCase public function test_export_plain_text_endpoint() { $this->actingAsApiEditor(); - $chapter = Chapter::visible()->first(); + $chapter = $this->entities->chapter(); $resp = $this->get($this->baseEndpoint . "/{$chapter->id}/export/plaintext"); $resp->assertStatus(200); @@ -199,7 +198,7 @@ class ChaptersApiTest extends TestCase public function test_export_pdf_endpoint() { $this->actingAsApiEditor(); - $chapter = Chapter::visible()->first(); + $chapter = $this->entities->chapter(); $resp = $this->get($this->baseEndpoint . "/{$chapter->id}/export/pdf"); $resp->assertStatus(200); diff --git a/tests/Api/PagesApiTest.php b/tests/Api/PagesApiTest.php index fe1fc8d36..8c533680f 100644 --- a/tests/Api/PagesApiTest.php +++ b/tests/Api/PagesApiTest.php @@ -2,7 +2,6 @@ namespace Tests\Api; -use BookStack\Entities\Models\Book; use BookStack\Entities\Models\Chapter; use BookStack\Entities\Models\Page; use Carbon\Carbon; @@ -95,11 +94,11 @@ class PagesApiTest extends TestCase 'chapter_id' => ['The chapter id field is required when book id is not present.'], ])); - $chapter = Chapter::visible()->first(); + $chapter = $this->entities->chapter(); $resp = $this->postJson($this->baseEndpoint, array_merge($details, ['chapter_id' => $chapter->id])); $resp->assertStatus(200); - $book = Book::visible()->first(); + $book = $this->entities->book(); $resp = $this->postJson($this->baseEndpoint, array_merge($details, ['book_id' => $book->id])); $resp->assertStatus(200); } @@ -107,7 +106,7 @@ class PagesApiTest extends TestCase public function test_markdown_can_be_provided_for_create() { $this->actingAsApiEditor(); - $book = Book::visible()->first(); + $book = $this->entities->book(); $details = [ 'book_id' => $book->id, 'name' => 'My api page', @@ -126,7 +125,7 @@ class PagesApiTest extends TestCase public function test_read_endpoint() { $this->actingAsApiEditor(); - $page = Page::visible()->first(); + $page = $this->entities->page(); $resp = $this->getJson($this->baseEndpoint . "/{$page->id}"); $resp->assertStatus(200); @@ -149,7 +148,7 @@ class PagesApiTest extends TestCase public function test_read_endpoint_provides_rendered_html() { $this->actingAsApiEditor(); - $page = Page::visible()->first(); + $page = $this->entities->page(); $page->html = "
testing
A page created via the API
', @@ -189,7 +188,7 @@ class PagesApiTest extends TestCase public function test_providing_new_chapter_id_on_update_will_move_page() { $this->actingAsApiEditor(); - $page = Page::visible()->first(); + $page = $this->entities->page(); $chapter = Chapter::visible()->where('book_id', '!=', $page->book_id)->first(); $details = [ 'name' => 'My updated API page', @@ -208,7 +207,7 @@ class PagesApiTest extends TestCase public function test_providing_move_via_update_requires_page_create_permission_on_new_parent() { $this->actingAsApiEditor(); - $page = Page::visible()->first(); + $page = $this->entities->page(); $chapter = Chapter::visible()->where('book_id', '!=', $page->book_id)->first(); $this->entities->setPermissions($chapter, ['view'], [$this->getEditor()->roles()->first()]); $details = [ @@ -224,7 +223,7 @@ class PagesApiTest extends TestCase public function test_update_endpoint_does_not_wipe_content_if_no_html_or_md_provided() { $this->actingAsApiEditor(); - $page = Page::visible()->first(); + $page = $this->entities->page(); $originalContent = $page->html; $details = [ 'name' => 'My updated API page', @@ -245,7 +244,7 @@ class PagesApiTest extends TestCase public function test_update_increments_updated_date_if_only_tags_are_sent() { $this->actingAsApiEditor(); - $page = Page::visible()->first(); + $page = $this->entities->page(); DB::table('pages')->where('id', '=', $page->id)->update(['updated_at' => Carbon::now()->subWeek()]); $details = [ @@ -262,7 +261,7 @@ class PagesApiTest extends TestCase public function test_delete_endpoint() { $this->actingAsApiEditor(); - $page = Page::visible()->first(); + $page = $this->entities->page(); $resp = $this->deleteJson($this->baseEndpoint . "/{$page->id}"); $resp->assertStatus(204); @@ -272,7 +271,7 @@ class PagesApiTest extends TestCase public function test_export_html_endpoint() { $this->actingAsApiEditor(); - $page = Page::visible()->first(); + $page = $this->entities->page(); $resp = $this->get($this->baseEndpoint . "/{$page->id}/export/html"); $resp->assertStatus(200); @@ -283,7 +282,7 @@ class PagesApiTest extends TestCase public function test_export_plain_text_endpoint() { $this->actingAsApiEditor(); - $page = Page::visible()->first(); + $page = $this->entities->page(); $resp = $this->get($this->baseEndpoint . "/{$page->id}/export/plaintext"); $resp->assertStatus(200); @@ -294,7 +293,7 @@ class PagesApiTest extends TestCase public function test_export_pdf_endpoint() { $this->actingAsApiEditor(); - $page = Page::visible()->first(); + $page = $this->entities->page(); $resp = $this->get($this->baseEndpoint . "/{$page->id}/export/pdf"); $resp->assertStatus(200); @@ -304,7 +303,7 @@ class PagesApiTest extends TestCase public function test_export_markdown_endpoint() { $this->actingAsApiEditor(); - $page = Page::visible()->first(); + $page = $this->entities->page(); $resp = $this->get($this->baseEndpoint . "/{$page->id}/export/markdown"); $resp->assertStatus(200); @@ -318,7 +317,7 @@ class PagesApiTest extends TestCase $this->actingAsApiEditor(); $this->removePermissionFromUser($this->getEditor(), 'content-export'); - $page = Page::visible()->first(); + $page = $this->entities->page(); foreach ($types as $type) { $resp = $this->get($this->baseEndpoint . "/{$page->id}/export/{$type}"); $this->assertPermissionError($resp); diff --git a/tests/Api/RecycleBinApiTest.php b/tests/Api/RecycleBinApiTest.php index cdb51f85a..bc7249987 100644 --- a/tests/Api/RecycleBinApiTest.php +++ b/tests/Api/RecycleBinApiTest.php @@ -4,7 +4,6 @@ namespace Tests\Api; use BookStack\Entities\Models\Book; use BookStack\Entities\Models\Deletion; -use BookStack\Entities\Models\Page; use Illuminate\Support\Collection; use Tests\TestCase; @@ -111,7 +110,7 @@ class RecycleBinApiTest extends TestCase public function test_index_endpoint_returns_parent() { $admin = $this->getAdmin(); - $page = Page::query()->whereHas('chapter')->with('chapter')->first(); + $page = $this->entities->pageWithinChapter(); $this->actingAs($admin)->delete($page->getUrl()); $deletion = Deletion::query()->orderBy('id')->first(); diff --git a/tests/Auth/AuthTest.php b/tests/Auth/AuthTest.php index 4456ed459..3220b2aac 100644 --- a/tests/Auth/AuthTest.php +++ b/tests/Auth/AuthTest.php @@ -3,7 +3,6 @@ namespace Tests\Auth; use BookStack\Auth\Access\Mfa\MfaSession; -use BookStack\Entities\Models\Page; use Illuminate\Testing\TestResponse; use Tests\TestCase; diff --git a/tests/Commands/ClearActivityCommandTest.php b/tests/Commands/ClearActivityCommandTest.php index abc8bc7f4..cf2fba0d6 100644 --- a/tests/Commands/ClearActivityCommandTest.php +++ b/tests/Commands/ClearActivityCommandTest.php @@ -3,7 +3,6 @@ namespace Tests\Commands; use BookStack\Actions\ActivityType; -use BookStack\Entities\Models\Page; use BookStack\Facades\Activity; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\DB; diff --git a/tests/Commands/CopyShelfPermissionsCommandTest.php b/tests/Commands/CopyShelfPermissionsCommandTest.php index bd96f2cc5..55b710ba9 100644 --- a/tests/Commands/CopyShelfPermissionsCommandTest.php +++ b/tests/Commands/CopyShelfPermissionsCommandTest.php @@ -16,7 +16,7 @@ class CopyShelfPermissionsCommandTest extends TestCase public function test_copy_shelf_permissions_command_using_slug() { - $shelf = Bookshelf::first(); + $shelf = $this->entities->shelf(); $child = $shelf->books()->first(); $editorRole = $this->getEditor()->roles()->first(); $this->assertFalse(boolval($child->restricted), 'Child book should not be restricted by default'); diff --git a/tests/Commands/RegenerateReferencesCommandTest.php b/tests/Commands/RegenerateReferencesCommandTest.php index 2c737712a..36af0d7cc 100644 --- a/tests/Commands/RegenerateReferencesCommandTest.php +++ b/tests/Commands/RegenerateReferencesCommandTest.php @@ -2,7 +2,6 @@ namespace Tests\Commands; -use BookStack\Entities\Models\Page; use Illuminate\Support\Facades\DB; use Tests\TestCase; diff --git a/tests/Commands/UpdateUrlCommandTest.php b/tests/Commands/UpdateUrlCommandTest.php index c4b09162e..c07a80312 100644 --- a/tests/Commands/UpdateUrlCommandTest.php +++ b/tests/Commands/UpdateUrlCommandTest.php @@ -2,7 +2,6 @@ namespace Tests\Commands; -use BookStack\Entities\Models\Page; use Symfony\Component\Console\Exception\RuntimeException; use Tests\TestCase; diff --git a/tests/Entity/BookShelfTest.php b/tests/Entity/BookShelfTest.php index 798edeadf..1e740b94e 100644 --- a/tests/Entity/BookShelfTest.php +++ b/tests/Entity/BookShelfTest.php @@ -39,7 +39,7 @@ class BookShelfTest extends TestCase { $user = User::factory()->create(); $this->giveUserPermissions($user, ['image-create-all']); - $shelf = Bookshelf::first(); + $shelf = $this->entities->shelf(); $userRole = $user->roles()->first(); $resp = $this->actingAs($user)->get('/'); @@ -130,7 +130,7 @@ class BookShelfTest extends TestCase public function test_shelf_view() { - $shelf = Bookshelf::first(); + $shelf = $this->entities->shelf(); $resp = $this->asEditor()->get($shelf->getUrl()); $resp->assertStatus(200); $resp->assertSeeText($shelf->name); @@ -143,7 +143,7 @@ class BookShelfTest extends TestCase public function test_shelf_view_shows_action_buttons() { - $shelf = Bookshelf::first(); + $shelf = $this->entities->shelf(); $resp = $this->asAdmin()->get($shelf->getUrl()); $resp->assertSee($shelf->getUrl('/create-book')); $resp->assertSee($shelf->getUrl('/edit')); @@ -201,7 +201,7 @@ class BookShelfTest extends TestCase public function test_shelf_edit() { - $shelf = Bookshelf::first(); + $shelf = $this->entities->shelf(); $resp = $this->asEditor()->get($shelf->getUrl('/edit')); $resp->assertSeeText('Edit Shelf'); @@ -239,7 +239,7 @@ class BookShelfTest extends TestCase public function test_shelf_create_new_book() { - $shelf = Bookshelf::first(); + $shelf = $this->entities->shelf(); $resp = $this->asEditor()->get($shelf->getUrl('/create-book')); $resp->assertSee('Create New Book'); @@ -288,7 +288,7 @@ class BookShelfTest extends TestCase public function test_shelf_copy_permissions() { - $shelf = Bookshelf::first(); + $shelf = $this->entities->shelf(); $resp = $this->asAdmin()->get($shelf->getUrl('/permissions')); $resp->assertSeeText('Copy Permissions'); $resp->assertSee("action=\"{$shelf->getUrl('/copy-permissions')}\"", false); @@ -311,14 +311,14 @@ class BookShelfTest extends TestCase public function test_permission_page_has_a_warning_about_no_cascading() { - $shelf = Bookshelf::first(); + $shelf = $this->entities->shelf(); $resp = $this->asAdmin()->get($shelf->getUrl('/permissions')); $resp->assertSeeText('Permissions on shelves do not automatically cascade to contained books.'); } public function test_bookshelves_show_in_breadcrumbs_if_in_context() { - $shelf = Bookshelf::first(); + $shelf = $this->entities->shelf(); $shelfBook = $shelf->books()->first(); $shelfPage = $shelfBook->pages()->first(); $this->asAdmin(); diff --git a/tests/Entity/ChapterTest.php b/tests/Entity/ChapterTest.php index fc8adb01d..afc60c20e 100644 --- a/tests/Entity/ChapterTest.php +++ b/tests/Entity/ChapterTest.php @@ -96,8 +96,7 @@ class ChapterTest extends TestCase public function test_copy_does_not_copy_non_visible_pages() { - /** @var Chapter $chapter */ - $chapter = Chapter::query()->whereHas('pages')->first(); + $chapter = $this->entities->chapterHasPages(); // Hide pages to all non-admin roles /** @var Page $page */ @@ -118,8 +117,7 @@ class ChapterTest extends TestCase public function test_copy_does_not_copy_pages_if_user_cant_page_create() { - /** @var Chapter $chapter */ - $chapter = Chapter::query()->whereHas('pages')->first(); + $chapter = $this->entities->chapterHasPages(); $viewer = $this->getViewer(); $this->giveUserPermissions($viewer, ['chapter-create-all']); diff --git a/tests/Entity/CommentSettingTest.php b/tests/Entity/CommentSettingTest.php index 0e3199979..7de457441 100644 --- a/tests/Entity/CommentSettingTest.php +++ b/tests/Entity/CommentSettingTest.php @@ -2,34 +2,27 @@ namespace Tests\Entity; -use BookStack\Entities\Models\Page; use Tests\TestCase; class CommentSettingTest extends TestCase { - protected $page; - - protected function setUp(): void - { - parent::setUp(); - $this->page = Page::query()->first(); - } - public function test_comment_disable() { + $page = $this->entities->page(); $this->setSettings(['app-disable-comments' => 'true']); $this->asAdmin(); - $resp = $this->asAdmin()->get($this->page->getUrl()); + $resp = $this->asAdmin()->get($page->getUrl()); $this->withHtml($resp)->assertElementNotExists('.comments-list'); } public function test_comment_enable() { + $page = $this->entities->page(); $this->setSettings(['app-disable-comments' => 'false']); $this->asAdmin(); - $resp = $this->asAdmin()->get($this->page->getUrl()); + $resp = $this->asAdmin()->get($page->getUrl()); $this->withHtml($resp)->assertElementExists('.comments-list'); } } diff --git a/tests/Entity/CommentTest.php b/tests/Entity/CommentTest.php index 1e8ecbcac..99e3525a0 100644 --- a/tests/Entity/CommentTest.php +++ b/tests/Entity/CommentTest.php @@ -11,7 +11,7 @@ class CommentTest extends TestCase public function test_add_comment() { $this->asAdmin(); - $page = Page::first(); + $page = $this->entities->page(); $comment = Comment::factory()->make(['parent_id' => 2]); $resp = $this->postJson("/comment/$page->id", $comment->getAttributes()); @@ -34,7 +34,7 @@ class CommentTest extends TestCase public function test_comment_edit() { $this->asAdmin(); - $page = Page::first(); + $page = $this->entities->page(); $comment = Comment::factory()->make(); $this->postJson("/comment/$page->id", $comment->getAttributes()); @@ -58,7 +58,7 @@ class CommentTest extends TestCase public function test_comment_delete() { $this->asAdmin(); - $page = Page::first(); + $page = $this->entities->page(); $comment = Comment::factory()->make(); $this->postJson("/comment/$page->id", $comment->getAttributes()); @@ -75,7 +75,7 @@ class CommentTest extends TestCase public function test_comments_converts_markdown_input_to_html() { - $page = Page::first(); + $page = $this->entities->page(); $this->asAdmin()->postJson("/comment/$page->id", [ 'text' => '# My Title', ]); @@ -94,7 +94,7 @@ class CommentTest extends TestCase public function test_html_cannot_be_injected_via_comment_content() { $this->asAdmin(); - $page = Page::first(); + $page = $this->entities->page(); $script = '\n\n# sometextinthecomment'; $this->postJson("/comment/$page->id", [ diff --git a/tests/Entity/ConvertTest.php b/tests/Entity/ConvertTest.php index 15205c9ad..16dd89068 100644 --- a/tests/Entity/ConvertTest.php +++ b/tests/Entity/ConvertTest.php @@ -24,8 +24,7 @@ class ConvertTest extends TestCase public function test_convert_chapter_to_book() { - /** @var Chapter $chapter */ - $chapter = Chapter::query()->whereHas('pages')->first(); + $chapter = $this->entities->chapterHasPages(); $chapter->tags()->save(new Tag(['name' => 'Category', 'value' => 'Penguins'])); /** @var Page $childPage */ $childPage = $chapter->pages()->first(); diff --git a/tests/Entity/EntityAccessTest.php b/tests/Entity/EntityAccessTest.php index e3d129d5e..2bb32fde8 100644 --- a/tests/Entity/EntityAccessTest.php +++ b/tests/Entity/EntityAccessTest.php @@ -4,7 +4,6 @@ namespace Tests\Entity; use BookStack\Auth\UserRepo; use BookStack\Entities\Models\Entity; -use BookStack\Entities\Repos\PageRepo; use Tests\TestCase; class EntityAccessTest extends TestCase @@ -16,7 +15,7 @@ class EntityAccessTest extends TestCase $updater = $this->getViewer(); $entities = $this->entities->createChainBelongingToUser($creator, $updater); app()->make(UserRepo::class)->destroy($creator); - app()->make(PageRepo::class)->update($entities['page'], ['html' => 'hello!
>']); + $this->entities->updatePage($entities['page'], ['html' => 'hello!
>']); $this->checkEntitiesViewable($entities); } @@ -28,7 +27,7 @@ class EntityAccessTest extends TestCase $updater = $this->getEditor(); $entities = $this->entities->createChainBelongingToUser($creator, $updater); app()->make(UserRepo::class)->destroy($updater); - app()->make(PageRepo::class)->update($entities['page'], ['html' => 'Hello there!
']); + $this->entities->updatePage($entities['page'], ['html' => 'Hello there!
']); $this->checkEntitiesViewable($entities); } diff --git a/tests/Entity/EntitySearchTest.php b/tests/Entity/EntitySearchTest.php index 82b97e6f3..cdb500a45 100644 --- a/tests/Entity/EntitySearchTest.php +++ b/tests/Entity/EntitySearchTest.php @@ -5,15 +5,13 @@ namespace Tests\Entity; use BookStack\Actions\Tag; use BookStack\Entities\Models\Book; use BookStack\Entities\Models\Bookshelf; -use BookStack\Entities\Models\Chapter; -use BookStack\Entities\Models\Page; use Tests\TestCase; class EntitySearchTest extends TestCase { public function test_page_search() { - $book = Book::all()->first(); + $book = $this->entities->book(); $page = $book->pages->first(); $search = $this->asEditor()->get('/search?term=' . urlencode($page->name)); @@ -71,7 +69,7 @@ class EntitySearchTest extends TestCase public function test_chapter_search() { - $chapter = Chapter::has('pages')->first(); + $chapter = $this->entities->chapterHasPages(); $page = $chapter->pages[0]; $pageTestResp = $this->asEditor()->get('/search/chapter/' . $chapter->id . '?term=' . urlencode($page->name)); @@ -91,10 +89,10 @@ class EntitySearchTest extends TestCase ]), ]; - $pageA = Page::first(); + $pageA = $this->entities->page(); $pageA->tags()->saveMany($newTags); - $pageB = Page::all()->last(); + $pageB = $this->entities->page(); $pageB->tags()->create(['name' => 'animal', 'value' => 'dog']); $this->asEditor(); @@ -197,7 +195,7 @@ class EntitySearchTest extends TestCase public function test_ajax_entity_search() { $page = $this->entities->newPage(['name' => 'my ajax search test', 'html' => 'ajax test']); - $notVisitedPage = Page::first(); + $notVisitedPage = $this->entities->page(); // Visit the page to make popular $this->asEditor()->get($page->getUrl()); @@ -215,7 +213,7 @@ class EntitySearchTest extends TestCase public function test_ajax_entity_search_shows_breadcrumbs() { - $chapter = Chapter::first(); + $chapter = $this->entities->chapter(); $page = $chapter->pages->first(); $this->asEditor(); @@ -246,7 +244,7 @@ class EntitySearchTest extends TestCase public function test_sibling_search_for_pages() { - $chapter = Chapter::query()->with('pages')->first(); + $chapter = $this->entities->chapterHasPages(); $this->assertGreaterThan(2, count($chapter->pages), 'Ensure we\'re testing with at least 1 sibling'); $page = $chapter->pages->first(); @@ -261,7 +259,7 @@ class EntitySearchTest extends TestCase public function test_sibling_search_for_pages_without_chapter() { - $page = Page::query()->where('chapter_id', '=', 0)->firstOrFail(); + $page = $this->entities->pageNotWithinChapter(); $bookChildren = $page->book->getDirectChildren(); $this->assertGreaterThan(2, count($bookChildren), 'Ensure we\'re testing with at least 1 sibling'); @@ -276,7 +274,7 @@ class EntitySearchTest extends TestCase public function test_sibling_search_for_chapters() { - $chapter = Chapter::query()->firstOrFail(); + $chapter = $this->entities->chapter(); $bookChildren = $chapter->book->getDirectChildren(); $this->assertGreaterThan(2, count($bookChildren), 'Ensure we\'re testing with at least 1 sibling'); diff --git a/tests/Entity/ExportTest.php b/tests/Entity/ExportTest.php index 1d4a23560..0f80bdd49 100644 --- a/tests/Entity/ExportTest.php +++ b/tests/Entity/ExportTest.php @@ -311,7 +311,7 @@ class ExportTest extends TestCase public function test_page_pdf_export_opens_details_blocks() { - $page = Page::query()->first()->forceFill([ + $page = $this->entities->page()->forceFill([ 'html' => 'Content!
Some bold text
', ]); @@ -446,9 +446,9 @@ class ExportTest extends TestCase public function test_html_exports_contain_csp_meta_tag() { $entities = [ - Page::query()->first(), - Book::query()->first(), - Chapter::query()->first(), + $this->entities->page(), + $this->entities->book(), + $this->entities->chapter(), ]; foreach ($entities as $entity) { diff --git a/tests/Entity/PageContentTest.php b/tests/Entity/PageContentTest.php index c6de4dc51..0c9854206 100644 --- a/tests/Entity/PageContentTest.php +++ b/tests/Entity/PageContentTest.php @@ -16,7 +16,7 @@ class PageContentTest extends TestCase public function test_page_includes() { $page = $this->entities->page(); - $secondPage = Page::query()->where('id', '!=', $page->id)->first(); + $secondPage = $this->entities->page(); $secondPage->html = "Hello, This is a test
This is a second block of content
"; $secondPage->save(); @@ -45,7 +45,7 @@ class PageContentTest extends TestCase public function test_saving_page_with_includes() { $page = $this->entities->page(); - $secondPage = Page::query()->where('id', '!=', $page->id)->first(); + $secondPage = $this->entities->page(); $this->asEditor(); $includeTag = '{{@' . $secondPage->id . '}}'; diff --git a/tests/Entity/PageDraftTest.php b/tests/Entity/PageDraftTest.php index acf6b01e8..010173852 100644 --- a/tests/Entity/PageDraftTest.php +++ b/tests/Entity/PageDraftTest.php @@ -2,7 +2,6 @@ namespace Tests\Entity; -use BookStack\Entities\Models\Book; use BookStack\Entities\Models\Page; use BookStack\Entities\Models\PageRevision; use BookStack\Entities\Repos\PageRepo; @@ -10,20 +9,13 @@ use Tests\TestCase; class PageDraftTest extends TestCase { - /** - * @var Page - */ - protected $page; - - /** - * @var PageRepo - */ - protected $pageRepo; + protected Page $page; + protected PageRepo $pageRepo; protected function setUp(): void { parent::setUp(); - $this->page = Page::query()->first(); + $this->page = $this->entities->page(); $this->pageRepo = app()->make(PageRepo::class); } diff --git a/tests/Entity/PageEditorTest.php b/tests/Entity/PageEditorTest.php index 6ce649a54..b2fb85955 100644 --- a/tests/Entity/PageEditorTest.php +++ b/tests/Entity/PageEditorTest.php @@ -2,20 +2,18 @@ namespace Tests\Entity; -use BookStack\Entities\Models\Book; use BookStack\Entities\Models\Chapter; use BookStack\Entities\Models\Page; use Tests\TestCase; class PageEditorTest extends TestCase { - /** @var Page */ - protected $page; + protected Page $page; protected function setUp(): void { parent::setUp(); - $this->page = Page::query()->first(); + $this->page = $this->entities->page(); } public function test_default_editor_is_wysiwyg_for_new_pages() @@ -80,8 +78,7 @@ class PageEditorTest extends TestCase public function test_back_link_in_editor_has_correct_url() { - /** @var Book $book */ - $book = Book::query()->whereHas('pages')->whereHas('chapters')->firstOrFail(); + $book = $this->entities->bookHasChaptersAndPages(); $this->asEditor()->get($book->getUrl('/create-page')); /** @var Chapter $chapter */ $chapter = $book->chapters()->firstOrFail(); diff --git a/tests/Entity/PageRevisionTest.php b/tests/Entity/PageRevisionTest.php index eabece4c6..d00ec5ce5 100644 --- a/tests/Entity/PageRevisionTest.php +++ b/tests/Entity/PageRevisionTest.php @@ -21,7 +21,7 @@ class PageRevisionTest extends TestCase public function test_page_revision_views_viewable() { $this->asEditor(); - $page = Page::first(); + $page = $this->entities->page(); $this->createRevisions($page, 1, ['name' => 'updated page', 'html' => 'new content
']); $pageRevision = $page->revisions->last(); @@ -37,7 +37,7 @@ class PageRevisionTest extends TestCase public function test_page_revision_preview_shows_content_of_revision() { $this->asEditor(); - $page = Page::first(); + $page = $this->entities->page(); $this->createRevisions($page, 1, ['name' => 'updated page', 'html' => 'new revision content
']); $pageRevision = $page->revisions->last(); $this->createRevisions($page, 1, ['name' => 'updated page', 'html' => 'Updated content
']); @@ -50,7 +50,7 @@ class PageRevisionTest extends TestCase public function test_page_revision_restore_updates_content() { $this->asEditor(); - $page = Page::first(); + $page = $this->entities->page(); $this->createRevisions($page, 1, ['name' => 'updated page abc123', 'html' => 'new contente def456
']); $this->createRevisions($page, 1, ['name' => 'updated page again', 'html' => 'new content
']); $page = Page::find($page->id); @@ -74,7 +74,7 @@ class PageRevisionTest extends TestCase public function test_page_revision_restore_with_markdown_retains_markdown_content() { $this->asEditor(); - $page = Page::first(); + $page = $this->entities->page(); $this->createRevisions($page, 1, ['name' => 'updated page abc123', 'markdown' => '## New Content def456']); $this->createRevisions($page, 1, ['name' => 'updated page again', 'markdown' => '## New Content Updated']); $page = Page::find($page->id); @@ -102,7 +102,7 @@ class PageRevisionTest extends TestCase public function test_page_revision_restore_sets_new_revision_with_summary() { $this->asEditor(); - $page = Page::first(); + $page = $this->entities->page(); $this->createRevisions($page, 1, ['name' => 'updated page abc123', 'html' => 'new contente def456
', 'summary' => 'My first update']); $this->createRevisions($page, 1, ['html' => 'new content
']); $page->refresh(); @@ -124,7 +124,7 @@ class PageRevisionTest extends TestCase public function test_page_revision_count_increments_on_update() { - $page = Page::first(); + $page = $this->entities->page(); $startCount = $page->revision_count; $this->createRevisions($page, 1); @@ -133,7 +133,7 @@ class PageRevisionTest extends TestCase public function test_revision_count_shown_in_page_meta() { - $page = Page::first(); + $page = $this->entities->page(); $this->createRevisions($page, 2); $pageView = $this->get($page->getUrl()); @@ -172,7 +172,7 @@ class PageRevisionTest extends TestCase public function test_revision_limit_enforced() { config()->set('app.revision_limit', 2); - $page = Page::first(); + $page = $this->entities->page(); $this->createRevisions($page, 12); $revisionCount = $page->revisions()->count(); @@ -182,7 +182,7 @@ class PageRevisionTest extends TestCase public function test_false_revision_limit_allows_many_revisions() { config()->set('app.revision_limit', false); - $page = Page::first(); + $page = $this->entities->page(); $this->createRevisions($page, 12); $revisionCount = $page->revisions()->count(); @@ -191,8 +191,7 @@ class PageRevisionTest extends TestCase public function test_revision_list_shows_editor_type() { - /** @var Page $page */ - $page = Page::first(); + $page = $this->entities->page(); $this->createRevisions($page, 1, ['html' => 'new page html']); $resp = $this->asAdmin()->get($page->refresh()->getUrl('/revisions')); diff --git a/tests/Entity/PageTemplateTest.php b/tests/Entity/PageTemplateTest.php index 3d1689510..dc45fcfb8 100644 --- a/tests/Entity/PageTemplateTest.php +++ b/tests/Entity/PageTemplateTest.php @@ -9,7 +9,7 @@ class PageTemplateTest extends TestCase { public function test_active_templates_visible_on_page_view() { - $page = Page::first(); + $page = $this->entities->page(); $this->asEditor(); $templateView = $this->get($page->getUrl()); @@ -24,7 +24,7 @@ class PageTemplateTest extends TestCase public function test_manage_templates_permission_required_to_change_page_template_status() { - $page = Page::first(); + $page = $this->entities->page(); $editor = $this->getEditor(); $this->actingAs($editor); @@ -52,7 +52,7 @@ class PageTemplateTest extends TestCase public function test_templates_content_should_be_fetchable_only_if_page_marked_as_template() { $content = 'This is some test content
'; $page->save(); @@ -151,7 +150,7 @@ class PageTest extends TestCase public function test_page_copy_with_markdown_has_both_html_and_markdown() { - $page = Page::first(); + $page = $this->entities->page(); $page->html = '