Added test for markdown page revision restore
Also added md change detection in revision saving.
This commit is contained in:
parent
61a911dd39
commit
37de4e2e0a
|
@ -177,17 +177,13 @@ class PageRepo
|
||||||
// Hold the old details to compare later
|
// Hold the old details to compare later
|
||||||
$oldHtml = $page->html;
|
$oldHtml = $page->html;
|
||||||
$oldName = $page->name;
|
$oldName = $page->name;
|
||||||
|
$oldMarkdown = $page->markdown;
|
||||||
|
|
||||||
$this->updateTemplateStatusAndContentFromInput($page, $input);
|
$this->updateTemplateStatusAndContentFromInput($page, $input);
|
||||||
$this->baseRepo->update($page, $input);
|
$this->baseRepo->update($page, $input);
|
||||||
|
|
||||||
// Update with new details
|
// Update with new details
|
||||||
$page->revision_count++;
|
$page->revision_count++;
|
||||||
|
|
||||||
if (setting('app-editor') !== 'markdown') {
|
|
||||||
$page->markdown = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$page->save();
|
$page->save();
|
||||||
|
|
||||||
// Remove all update drafts for this user & page.
|
// Remove all update drafts for this user & page.
|
||||||
|
@ -195,7 +191,10 @@ class PageRepo
|
||||||
|
|
||||||
// Save a revision after updating
|
// Save a revision after updating
|
||||||
$summary = $input['summary'] ?? null;
|
$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);
|
$this->savePageRevision($page, $summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,36 @@ class PageRevisionTest extends TestCase
|
||||||
$pageView->assertSee('def456');
|
$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()
|
public function test_page_revision_restore_sets_new_revision_with_summary()
|
||||||
{
|
{
|
||||||
$this->asEditor();
|
$this->asEditor();
|
||||||
|
|
Loading…
Reference in New Issue