Fixed issue where markdown drafts showed as HTML

Markdown content was not being stored, only the sent
HTML representation, causing the draft to show as HTML upon next edit.
Added test to cover.

Fixes #3054
This commit is contained in:
Dan Brown 2021-11-14 12:17:22 +00:00
parent 89f7f8e259
commit 8e71cd9bac
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
2 changed files with 27 additions and 3 deletions

View File

@ -252,9 +252,7 @@ class PageRepo
{
// If the page itself is a draft simply update that
if ($page->draft) {
if (isset($input['html'])) {
(new PageContent($page))->setNewHTML($input['html']);
}
$this->updateTemplateStatusAndContentFromInput($page, $input);
$page->fill($input);
$page->save();

View File

@ -178,4 +178,30 @@ class PageDraftTest extends TestCase
'html' => $page->html,
]);
}
public function test_updating_page_draft_with_markdown_retains_markdown_content()
{
/** @var Book $book */
$book = Book::query()->first();
$this->asEditor()->get($book->getUrl('/create-page'));
/** @var Page $draft */
$draft = Page::query()->where('draft', '=', true)->where('book_id', '=', $book->id)->firstOrFail();
$resp = $this->put('/ajax/page/' . $draft->id . '/save-draft', [
'name' => 'My updated draft',
'markdown' => "# My markdown page\n\n[A link](https://example.com)",
'html' => '<p>checking markdown takes priority over this</p>'
]);
$resp->assertOk();
$this->assertDatabaseHas('pages', [
'id' => $draft->id,
'draft' => true,
'name' => 'My updated draft',
'markdown' => "# My markdown page\n\n[A link](https://example.com)",
]);
$draft->refresh();
$this->assertStringContainsString('href="https://example.com"', $draft->html);
}
}