]> BookStack Code Mirror - bookstack/blob - tests/Entity/BookTest.php
Adding Croatian translation files
[bookstack] / tests / Entity / BookTest.php
1 <?php namespace Tests\Entity;
2
3 use BookStack\Entities\Models\Book;
4 use Tests\TestCase;
5
6 class BookTest extends TestCase
7 {
8     public function test_book_delete()
9     {
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();
14
15         $deleteViewReq = $this->asEditor()->get($book->getUrl('/delete'));
16         $deleteViewReq->assertSeeText('Are you sure you want to delete this book?');
17
18         $deleteReq = $this->delete($book->getUrl());
19         $deleteReq->assertRedirect(url('/books'));
20         $this->assertActivityExists('book_delete', $book);
21
22         $book->refresh();
23         $this->assertNotNull($book->deleted_at);
24
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);
30
31         $redirectReq = $this->get($deleteReq->baseResponse->headers->get('location'));
32         $redirectReq->assertNotificationContains('Book Successfully Deleted');
33     }
34
35     public function test_next_previous_navigation_controls_show_within_book_content()
36     {
37         $book = Book::query()->first();
38         $chapter = $book->chapters->first();
39
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));
43
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));
48     }
49 }