From 3502abdd49c1ca09e3529c7410ed626913682a8d Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sat, 23 May 2020 12:28:14 +0100 Subject: [PATCH] Fixed revision issues caused by page fillable changes --- app/Entities/Repos/PageRepo.php | 2 +- app/Http/Controllers/PageRevisionController.php | 7 +++++++ tests/Entity/PageRevisionTest.php | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/Entities/Repos/PageRepo.php b/app/Entities/Repos/PageRepo.php index fc585b4df..e5f13463c 100644 --- a/app/Entities/Repos/PageRepo.php +++ b/app/Entities/Repos/PageRepo.php @@ -278,7 +278,7 @@ class PageRepo $revision = $page->revisions()->where('id', '=', $revisionId)->first(); $page->fill($revision->toArray()); $content = new PageContent($page); - $content->setNewHTML($page->html); + $content->setNewHTML($revision->html); $page->updated_by = user()->id; $page->refreshSlug(); $page->save(); diff --git a/app/Http/Controllers/PageRevisionController.php b/app/Http/Controllers/PageRevisionController.php index 3c65b50ac..797f5db8f 100644 --- a/app/Http/Controllers/PageRevisionController.php +++ b/app/Http/Controllers/PageRevisionController.php @@ -1,5 +1,6 @@ fill($revision->toArray()); + // TODO - Refactor PageContent so we don't need to juggle this + $page->html = $revision->html; + $page->html = (new PageContent($page))->render(); $this->setPageTitle(trans('entities.pages_revision_named', ['pageName' => $page->getShortName()])); return view('pages.revision', [ @@ -73,6 +77,9 @@ class PageRevisionController extends Controller $diff = (new Htmldiff)->diff($prevContent, $revision->html); $page->fill($revision->toArray()); + // TODO - Refactor PageContent so we don't need to juggle this + $page->html = $revision->html; + $page->html = (new PageContent($page))->render(); $this->setPageTitle(trans('entities.pages_revision_named', ['pageName'=>$page->getShortName()])); return view('pages.revision', [ diff --git a/tests/Entity/PageRevisionTest.php b/tests/Entity/PageRevisionTest.php index f8baccc54..1e9dbd626 100644 --- a/tests/Entity/PageRevisionTest.php +++ b/tests/Entity/PageRevisionTest.php @@ -24,6 +24,21 @@ class PageRevisionTest extends TestCase $revisionView->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();