3 namespace Tests\Entity;
5 use BookStack\Entities\Models\Book;
8 class BookTest extends TestCase
10 public function test_book_delete()
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();
17 $deleteViewReq = $this->asEditor()->get($book->getUrl('/delete'));
18 $deleteViewReq->assertSeeText('Are you sure you want to delete this book?');
20 $deleteReq = $this->delete($book->getUrl());
21 $deleteReq->assertRedirect(url('/books'));
22 $this->assertActivityExists('book_delete', $book);
25 $this->assertNotNull($book->deleted_at);
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);
33 $redirectReq = $this->get($deleteReq->baseResponse->headers->get('location'));
34 $redirectReq->assertNotificationContains('Book Successfully Deleted');
37 public function test_next_previous_navigation_controls_show_within_book_content()
39 $book = Book::query()->first();
40 $chapter = $book->chapters->first();
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));
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));