]> BookStack Code Mirror - bookstack/blob - tests/Entity/SortTest.php
Merge pull request #3 from BookStackApp/master
[bookstack] / tests / Entity / SortTest.php
1 <?php
2
3 class SortTest extends TestCase
4 {
5     protected $book;
6
7     public function setUp()
8     {
9         parent::setUp();
10         $this->book = \BookStack\Book::first();
11     }
12
13     public function test_drafts_do_not_show_up()
14     {
15         $this->asAdmin();
16         $entityRepo = app('\BookStack\Repos\EntityRepo');
17         $draft = $entityRepo->getDraftPage($this->book);
18
19         $this->visit($this->book->getUrl())
20             ->see($draft->name)
21             ->visit($this->book->getUrl() . '/sort')
22             ->dontSee($draft->name);
23     }
24
25     public function test_page_move()
26     {
27         $page = \BookStack\Page::first();
28         $currentBook = $page->book;
29         $newBook = \BookStack\Book::where('id', '!=', $currentBook->id)->first();
30         $this->asAdmin()->visit($page->getUrl() . '/move')
31             ->see('Move Page')
32             ->type('book:' . $newBook->id, 'entity_selection')->press('Move Page');
33
34         $page = \BookStack\Page::find($page->id);
35         $this->seePageIs($page->getUrl());
36         $this->assertTrue($page->book->id == $newBook->id, 'Page book is now the new book');
37
38         $this->visit($newBook->getUrl())
39             ->seeInNthElement('.activity-list-item', 0, 'moved page')
40             ->seeInNthElement('.activity-list-item', 0, $page->name);
41     }
42
43     public function test_chapter_move()
44     {
45         $chapter = \BookStack\Chapter::first();
46         $currentBook = $chapter->book;
47         $pageToCheck = $chapter->pages->first();
48         $newBook = \BookStack\Book::where('id', '!=', $currentBook->id)->first();
49
50         $this->asAdmin()->visit($chapter->getUrl() . '/move')
51             ->see('Move Chapter')
52             ->type('book:' . $newBook->id, 'entity_selection')->press('Move Chapter');
53
54         $chapter = \BookStack\Chapter::find($chapter->id);
55         $this->seePageIs($chapter->getUrl());
56         $this->assertTrue($chapter->book->id === $newBook->id, 'Chapter Book is now the new book');
57
58         $this->visit($newBook->getUrl())
59             ->seeInNthElement('.activity-list-item', 0, 'moved chapter')
60             ->seeInNthElement('.activity-list-item', 0, $chapter->name);
61
62         $pageToCheck = \BookStack\Page::find($pageToCheck->id);
63         $this->assertTrue($pageToCheck->book_id === $newBook->id, 'Chapter child page\'s book id has changed to the new book');
64         $this->visit($pageToCheck->getUrl())
65             ->see($newBook->name);
66     }
67
68 }