// Hold the old details to compare later
$oldHtml = $page->html;
$oldName = $page->name;
+ $oldMarkdown = $page->markdown;
$this->updateTemplateStatusAndContentFromInput($page, $input);
$this->baseRepo->update($page, $input);
// Update with new details
$page->revision_count++;
-
- if (setting('app-editor') !== 'markdown') {
- $page->markdown = '';
- }
-
$page->save();
// Remove all update drafts for this user & page.
// Save a revision after updating
$summary = $input['summary'] ?? null;
- if ($oldHtml !== $input['html'] || $oldName !== $input['name'] || $summary !== null) {
+ $htmlChanged = isset($input['html']) && $input['html'] !== $oldHtml;
+ $nameChanged = isset($input['name']) && $input['name'] !== $oldName;
+ $markdownChanged = isset($input['markdown']) && $input['markdown'] !== $oldMarkdown;
+ if ($htmlChanged || $nameChanged || $markdownChanged || $summary !== null) {
$this->savePageRevision($page, $summary);
}
$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 Updated',
+ ]);
+ $pageView->assertSee('abc123');
+ $pageView->assertSee('def456');
+ }
+
public function test_page_revision_restore_sets_new_revision_with_summary()
{
$this->asEditor();