]> BookStack Code Mirror - bookstack/blobdiff - tests/Entity/SortTest.php
Merge pull request #3 from BookStackApp/master
[bookstack] / tests / Entity / SortTest.php
index 8792a0a067c44b96f2db86f184e55c987c5f763e..4784297a2e804d7f0e2f74c91ddf60314670d4ae 100644 (file)
@@ -13,8 +13,8 @@ class SortTest extends TestCase
     public function test_drafts_do_not_show_up()
     {
         $this->asAdmin();
-        $pageRepo = app('\BookStack\Repos\PageRepo');
-        $draft = $pageRepo->getDraftPage($this->book);
+        $entityRepo = app('\BookStack\Repos\EntityRepo');
+        $draft = $entityRepo->getDraftPage($this->book);
 
         $this->visit($this->book->getUrl())
             ->see($draft->name)
@@ -22,4 +22,47 @@ class SortTest extends TestCase
             ->dontSee($draft->name);
     }
 
+    public function test_page_move()
+    {
+        $page = \BookStack\Page::first();
+        $currentBook = $page->book;
+        $newBook = \BookStack\Book::where('id', '!=', $currentBook->id)->first();
+        $this->asAdmin()->visit($page->getUrl() . '/move')
+            ->see('Move Page')
+            ->type('book:' . $newBook->id, 'entity_selection')->press('Move Page');
+
+        $page = \BookStack\Page::find($page->id);
+        $this->seePageIs($page->getUrl());
+        $this->assertTrue($page->book->id == $newBook->id, 'Page book is now the new book');
+
+        $this->visit($newBook->getUrl())
+            ->seeInNthElement('.activity-list-item', 0, 'moved page')
+            ->seeInNthElement('.activity-list-item', 0, $page->name);
+    }
+
+    public function test_chapter_move()
+    {
+        $chapter = \BookStack\Chapter::first();
+        $currentBook = $chapter->book;
+        $pageToCheck = $chapter->pages->first();
+        $newBook = \BookStack\Book::where('id', '!=', $currentBook->id)->first();
+
+        $this->asAdmin()->visit($chapter->getUrl() . '/move')
+            ->see('Move Chapter')
+            ->type('book:' . $newBook->id, 'entity_selection')->press('Move Chapter');
+
+        $chapter = \BookStack\Chapter::find($chapter->id);
+        $this->seePageIs($chapter->getUrl());
+        $this->assertTrue($chapter->book->id === $newBook->id, 'Chapter Book is now the new book');
+
+        $this->visit($newBook->getUrl())
+            ->seeInNthElement('.activity-list-item', 0, 'moved chapter')
+            ->seeInNthElement('.activity-list-item', 0, $chapter->name);
+
+        $pageToCheck = \BookStack\Page::find($pageToCheck->id);
+        $this->assertTrue($pageToCheck->book_id === $newBook->id, 'Chapter child page\'s book id has changed to the new book');
+        $this->visit($pageToCheck->getUrl())
+            ->see($newBook->name);
+    }
+
 }
\ No newline at end of file