X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/b56f7355aa3a44c8529073fc2a3e760d0404f2ad..refs/pull/5312/head:/tests/Entity/PageDraftTest.php diff --git a/tests/Entity/PageDraftTest.php b/tests/Entity/PageDraftTest.php index acf6b01e8..e99ba9b81 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); } @@ -47,7 +39,7 @@ class PageDraftTest extends TestCase $this->withHtml($resp)->assertElementNotContains('[name="html"]', $addedContent); $newContent = $this->page->html . $addedContent; - $newUser = $this->getEditor(); + $newUser = $this->users->editor(); $this->pageRepo->updatePageDraft($this->page, ['html' => $newContent]); $resp = $this->actingAs($newUser)->get($this->page->getUrl('/edit')); @@ -70,7 +62,7 @@ class PageDraftTest extends TestCase $this->withHtml($resp)->assertElementNotContains('[name="html"]', $addedContent); $newContent = $this->page->html . $addedContent; - $newUser = $this->getEditor(); + $newUser = $this->users->editor(); $this->pageRepo->updatePageDraft($this->page, ['html' => $newContent]); $this->actingAs($newUser) @@ -83,8 +75,8 @@ class PageDraftTest extends TestCase public function test_draft_save_shows_alert_if_draft_older_than_last_page_update() { - $admin = $this->getAdmin(); - $editor = $this->getEditor(); + $admin = $this->users->admin(); + $editor = $this->users->editor(); $page = $this->entities->page(); $this->actingAs($editor)->put('/ajax/page/' . $page->id . '/save-draft', [ @@ -117,8 +109,8 @@ class PageDraftTest extends TestCase public function test_draft_save_shows_alert_if_draft_edit_started_by_someone_else() { - $admin = $this->getAdmin(); - $editor = $this->getEditor(); + $admin = $this->users->admin(); + $editor = $this->users->editor(); $page = $this->entities->page(); $this->actingAs($admin)->put('/ajax/page/' . $page->id . '/save-draft', [ @@ -151,7 +143,7 @@ class PageDraftTest extends TestCase { $book = $this->entities->book(); $chapter = $book->chapters->first(); - $newUser = $this->getEditor(); + $newUser = $this->users->editor(); $this->actingAs($newUser)->get($book->getUrl('/create-page')); $this->get($chapter->getUrl('/create-page')); @@ -174,6 +166,30 @@ class PageDraftTest extends TestCase ]); } + public function test_user_draft_removed_on_user_drafts_delete_call() + { + $editor = $this->users->editor(); + $page = $this->entities->page(); + + $this->actingAs($editor)->put('/ajax/page/' . $page->id . '/save-draft', [ + 'name' => $page->name, + 'html' => '
updated draft again
', + ]); + + $revisionData = [ + 'type' => 'update_draft', + 'created_by' => $editor->id, + 'page_id' => $page->id, + ]; + + $this->assertDatabaseHas('page_revisions', $revisionData); + + $resp = $this->delete("/page-revisions/user-drafts/{$page->id}"); + + $resp->assertOk(); + $this->assertDatabaseMissing('page_revisions', $revisionData); + } + public function test_updating_page_draft_with_markdown_retains_markdown_content() { $book = $this->entities->book();