1 <?php namespace Tests\Entity;
3 use BookStack\Entities\Models\Book;
6 class BookTest extends TestCase
8 public function test_book_delete()
10 $book = Book::query()->whereHas('pages')->whereHas('chapters')->first();
11 $this->assertNull($book->deleted_at);
12 $pageCount = $book->pages()->count();
13 $chapterCount = $book->chapters()->count();
15 $deleteViewReq = $this->asEditor()->get($book->getUrl('/delete'));
16 $deleteViewReq->assertSeeText('Are you sure you want to delete this book?');
18 $deleteReq = $this->delete($book->getUrl());
19 $deleteReq->assertRedirect(url('/books'));
20 $this->assertActivityExists('book_delete', $book);
23 $this->assertNotNull($book->deleted_at);
25 $this->assertTrue($book->pages()->count() === 0);
26 $this->assertTrue($book->chapters()->count() === 0);
27 $this->assertTrue($book->pages()->withTrashed()->count() === $pageCount);
28 $this->assertTrue($book->chapters()->withTrashed()->count() === $chapterCount);
29 $this->assertTrue($book->deletions()->count() === 1);
31 $redirectReq = $this->get($deleteReq->baseResponse->headers->get('location'));
32 $redirectReq->assertNotificationContains('Book Successfully Deleted');
35 public function test_next_previous_navigation_controls_show_within_book_content()
37 $book = Book::query()->first();
38 $chapter = $book->chapters->first();
40 $resp = $this->asEditor()->get($chapter->getUrl());
41 $resp->assertElementContains('#sibling-navigation', 'Next');
42 $resp->assertElementContains('#sibling-navigation', substr($chapter->pages[0]->name, 0, 20));
44 $resp = $this->get($chapter->pages[0]->getUrl());
45 $resp->assertElementContains('#sibling-navigation', substr($chapter->pages[1]->name, 0, 20));
46 $resp->assertElementContains('#sibling-navigation', 'Previous');
47 $resp->assertElementContains('#sibling-navigation', substr($chapter->name, 0, 20));