X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/f84bf8e883e8e5bd9a24b908e2f90a2742d36d19..refs/pull/2700/head:/tests/Entity/PageRevisionTest.php diff --git a/tests/Entity/PageRevisionTest.php b/tests/Entity/PageRevisionTest.php index f8baccc54..62fbfbf31 100644 --- a/tests/Entity/PageRevisionTest.php +++ b/tests/Entity/PageRevisionTest.php @@ -1,6 +1,6 @@ assertSee('new content'); } + public function test_page_revision_preview_shows_content_of_revision() + { + $this->asEditor(); + + $pageRepo = app(PageRepo::class); + $page = Page::first(); + $pageRepo->update($page, ['name' => 'updated page', 'html' => '
new revision content
', 'summary' => 'page revision testing']); + $pageRevision = $page->revisions->last(); + $pageRepo->update($page, ['name' => 'updated page', 'html' => 'Updated content
', 'summary' => 'page revision testing 2']); + + $revisionView = $this->get($page->getUrl() . '/revisions/' . $pageRevision->id); + $revisionView->assertStatus(200); + $revisionView->assertSee('new revision content'); + } + public function test_page_revision_restore_updates_content() { $this->asEditor(); @@ -51,6 +66,58 @@ class PageRevisionTest extends TestCase $pageView->assertSee('def456'); } + public function test_page_revision_restore_with_markdown_retains_markdown_content() + { + $this->asEditor(); + + $pageRepo = app(PageRepo::class); + $page = Page::first(); + $pageRepo->update($page, ['name' => 'updated page abc123', 'markdown' => '## New Content def456', 'summary' => 'initial page revision testing']); + $pageRepo->update($page, ['name' => 'updated page again', 'markdown' => '## New Content Updated', 'summary' => 'page revision testing']); + $page = Page::find($page->id); + + $pageView = $this->get($page->getUrl()); + $pageView->assertDontSee('abc123'); + $pageView->assertDontSee('def456'); + + $revToRestore = $page->revisions()->where('name', 'like', '%abc123')->first(); + $restoreReq = $this->put($page->getUrl() . '/revisions/' . $revToRestore->id . '/restore'); + $page = Page::find($page->id); + + $restoreReq->assertStatus(302); + $restoreReq->assertRedirect($page->getUrl()); + + $pageView = $this->get($page->getUrl()); + $this->assertDatabaseHas('pages', [ + 'id' => $page->id, + 'markdown' => '## New Content def456', + ]); + $pageView->assertSee('abc123'); + $pageView->assertSee('def456'); + } + + public function test_page_revision_restore_sets_new_revision_with_summary() + { + $this->asEditor(); + + $pageRepo = app(PageRepo::class); + $page = Page::first(); + $pageRepo->update($page, ['name' => 'updated page abc123', 'html' => 'new contente def456
', 'summary' => 'My first update']); + $pageRepo->update($page, ['name' => 'updated page again', 'html' => 'new content
', 'summary' => '']); + $page->refresh(); + + $revToRestore = $page->revisions()->where('name', 'like', '%abc123')->first(); + $this->put($page->getUrl() . '/revisions/' . $revToRestore->id . '/restore'); + $page->refresh(); + + $this->assertDatabaseHas('page_revisions', [ + 'page_id' => $page->id, + 'text' => 'new contente def456', + 'type' => 'version', + 'summary' => "Restored from #{$revToRestore->id}; My first update", + ]); + } + public function test_page_revision_count_increments_on_update() { $page = Page::first();