]> BookStack Code Mirror - bookstack/commitdiff
Merge branch 'master' of github.com:BookStackApp/BookStack
authorDan Brown <redacted>
Tue, 29 Oct 2019 22:34:12 +0000 (22:34 +0000)
committerDan Brown <redacted>
Tue, 29 Oct 2019 22:34:12 +0000 (22:34 +0000)
app/Entities/Repos/PageRepo.php
tests/Entity/SortTest.php

index 0fc68f95345189d6767087f04db9ec5ace2bb673..e49eeb1ef5518eb8aa124d11e981236f11ebbe04 100644 (file)
@@ -306,9 +306,11 @@ class PageRepo
             throw new PermissionsException('User does not have permission to create a page within the new parent');
         }
 
+        $page->chapter_id = ($parent instanceof Chapter) ? $parent->id : null;
         $page->changeBook($parent instanceof Book ? $parent->id : $parent->book->id);
         $page->rebuildPermissions();
-        return $parent;
+
+        return ($parent instanceof Book ? $parent : $parent->book);
     }
 
     /**
index 3c83d626aea73632dc93a5d08274a1a4d6e420da..7d67f05c6d6b0b77be7dde916d3c497c512d0482 100644 (file)
@@ -28,7 +28,7 @@ class SortTest extends TestCase
         $resp->assertDontSee($draft->name);
     }
 
-    public function test_page_move()
+    public function test_page_move_into_book()
     {
         $page = Page::first();
         $currentBook = $page->book;
@@ -50,6 +50,44 @@ class SortTest extends TestCase
         $newBookResp->assertSee($page->name);
     }
 
+    public function test_page_move_into_chapter()
+    {
+        $page = Page::first();
+        $currentBook = $page->book;
+        $newBook = Book::where('id', '!=', $currentBook->id)->first();
+        $newChapter = $newBook->chapters()->first();
+
+        $movePageResp = $this->actingAs($this->getEditor())->put($page->getUrl('/move'), [
+            'entity_selection' => 'chapter:' . $newChapter->id
+        ]);
+        $page = Page::find($page->id);
+
+        $movePageResp->assertRedirect($page->getUrl());
+        $this->assertTrue($page->book->id == $newBook->id, 'Page parent is now the new chapter');
+
+        $newChapterResp = $this->get($newChapter->getUrl());
+        $newChapterResp->assertSee($page->name);
+    }
+
+    public function test_page_move_from_chapter_to_book()
+    {
+        $oldChapter = Chapter::first();
+        $page = $oldChapter->pages()->first();
+        $newBook = Book::where('id', '!=', $oldChapter->book_id)->first();
+
+        $movePageResp = $this->actingAs($this->getEditor())->put($page->getUrl('/move'), [
+            'entity_selection' => 'book:' . $newBook->id
+        ]);
+        $page = Page::find($page->id);
+
+        $movePageResp->assertRedirect($page->getUrl());
+        $this->assertTrue($page->book->id == $newBook->id, 'Page parent is now the new book');
+        $this->assertTrue($page->chapter === null, 'Page has no parent chapter');
+
+        $newBookResp = $this->get($newBook->getUrl());
+        $newBookResp->assertSee($page->name);
+    }
+
     public function test_page_move_requires_create_permissions_on_parent()
     {
         $page = Page::first();