From 20729a618f7d8b5c792220deab58336cc8141ce6 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Mon, 4 Jan 2021 17:52:08 +0000 Subject: [PATCH] Fixed markdown content not stored on first page save HTML content was still saved. This changes makes the back-end check for md content instead of html to ensure that gets stored in cases where both are sent to the system. Closes #2446 --- app/Entities/Repos/PageRepo.php | 6 +++--- tests/Entity/PageTest.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/app/Entities/Repos/PageRepo.php b/app/Entities/Repos/PageRepo.php index 721485b11..9ca254f1e 100644 --- a/app/Entities/Repos/PageRepo.php +++ b/app/Entities/Repos/PageRepo.php @@ -210,10 +210,10 @@ class PageRepo } $pageContent = new PageContent($page); - if (isset($input['html'])) { - $pageContent->setNewHTML($input['html']); - } else { + if (isset($input['markdown'])) { $pageContent->setNewMarkdown($input['markdown']); + } else { + $pageContent->setNewHTML($input['html']); } } diff --git a/tests/Entity/PageTest.php b/tests/Entity/PageTest.php index 887dfe8af..a49c8af20 100644 --- a/tests/Entity/PageTest.php +++ b/tests/Entity/PageTest.php @@ -1,10 +1,40 @@ setSettings(['app-editor' => 'markdown']); + $book = Book::query()->first(); + + $this->asEditor()->get($book->getUrl('/create-page')); + $draft = Page::query()->where('book_id', '=', $book->id) + ->where('draft', '=', true)->first(); + + $details = [ + 'markdown' => '# a title', + 'html' => '

a title

', + 'name' => 'my page', + ]; + $resp = $this->post($book->getUrl("/draft/{$draft->id}"), $details); + $resp->assertRedirect(); + + $this->assertDatabaseHas('pages', [ + 'markdown' => $details['markdown'], + 'name' => $details['name'], + 'id' => $draft->id, + 'draft' => false + ]); + + $draft->refresh(); + $resp = $this->get($draft->getUrl("/edit")); + $resp->assertSee("# a title"); + } + public function test_page_delete() { $page = Page::query()->first();