]> BookStack Code Mirror - bookstack/commitdiff
Fixed markdown content not stored on first page save
authorDan Brown <redacted>
Mon, 4 Jan 2021 17:52:08 +0000 (17:52 +0000)
committerDan Brown <redacted>
Mon, 4 Jan 2021 17:52:08 +0000 (17:52 +0000)
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
tests/Entity/PageTest.php

index 721485b11f0d7faa16e81c574e92cf7a666266e7..9ca254f1ebc9250b3d29d66bbace7e4065b8e3e3 100644 (file)
@@ -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']);
         }
     }
 
index 887dfe8af4db8c0eb526cd446a4ab8afbdd06fd2..a49c8af20fad60594af93ff232e6919cad0fc4fe 100644 (file)
@@ -1,10 +1,40 @@
 <?php namespace Tests\Entity;
 
+use BookStack\Entities\Models\Book;
 use BookStack\Entities\Models\Page;
 use Tests\TestCase;
 
 class PageTest extends TestCase
 {
+    public function test_page_creation_with_markdown_content()
+    {
+        $this->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' => '<h1>a title</h1>',
+            '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();
Morty Proxy This is a proxified and sanitized view of the page, visit original site.