mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-03-22 04:37:33 +08:00
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
|
||||
$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.
|
||||
@ -195,7 +191,10 @@ class PageRepo
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,36 @@ 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 Updated',
|
||||
]);
|
||||
$pageView->assertSee('abc123');
|
||||
$pageView->assertSee('def456');
|
||||
}
|
||||
|
||||
public function test_page_revision_restore_sets_new_revision_with_summary()
|
||||
{
|
||||
$this->asEditor();
|
||||
|
Loading…
x
Reference in New Issue
Block a user