]> BookStack Code Mirror - bookstack/blob - tests/Entity/BookTest.php
Apply fixes from StyleCI
[bookstack] / tests / Entity / BookTest.php
1 <?php
2
3 namespace Tests\Entity;
4
5 use BookStack\Entities\Models\Book;
6 use Tests\TestCase;
7
8 class BookTest extends TestCase
9 {
10     public function test_book_delete()
11     {
12         $book = Book::query()->whereHas('pages')->whereHas('chapters')->first();
13         $this->assertNull($book->deleted_at);
14         $pageCount = $book->pages()->count();
15         $chapterCount = $book->chapters()->count();
16
17         $deleteViewReq = $this->asEditor()->get($book->getUrl('/delete'));
18         $deleteViewReq->assertSeeText('Are you sure you want to delete this book?');
19
20         $deleteReq = $this->delete($book->getUrl());
21         $deleteReq->assertRedirect(url('/books'));
22         $this->assertActivityExists('book_delete', $book);
23
24         $book->refresh();
25         $this->assertNotNull($book->deleted_at);
26
27         $this->assertTrue($book->pages()->count() === 0);
28         $this->assertTrue($book->chapters()->count() === 0);
29         $this->assertTrue($book->pages()->withTrashed()->count() === $pageCount);
30         $this->assertTrue($book->chapters()->withTrashed()->count() === $chapterCount);
31         $this->assertTrue($book->deletions()->count() === 1);
32
33         $redirectReq = $this->get($deleteReq->baseResponse->headers->get('location'));
34         $redirectReq->assertNotificationContains('Book Successfully Deleted');
35     }
36
37     public function test_next_previous_navigation_controls_show_within_book_content()
38     {
39         $book = Book::query()->first();
40         $chapter = $book->chapters->first();
41
42         $resp = $this->asEditor()->get($chapter->getUrl());
43         $resp->assertElementContains('#sibling-navigation', 'Next');
44         $resp->assertElementContains('#sibling-navigation', substr($chapter->pages[0]->name, 0, 20));
45
46         $resp = $this->get($chapter->pages[0]->getUrl());
47         $resp->assertElementContains('#sibling-navigation', substr($chapter->pages[1]->name, 0, 20));
48         $resp->assertElementContains('#sibling-navigation', 'Previous');
49         $resp->assertElementContains('#sibling-navigation', substr($chapter->name, 0, 20));
50     }
51 }