2021-06-26 11:23:15 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Entity;
|
2020-11-06 07:54:39 -05:00
|
|
|
|
2020-11-21 19:17:45 -05:00
|
|
|
use BookStack\Entities\Models\Book;
|
2020-11-06 07:54:39 -05:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class BookTest extends TestCase
|
|
|
|
{
|
|
|
|
public function test_book_delete()
|
|
|
|
{
|
|
|
|
$book = Book::query()->whereHas('pages')->whereHas('chapters')->first();
|
|
|
|
$this->assertNull($book->deleted_at);
|
|
|
|
$pageCount = $book->pages()->count();
|
|
|
|
$chapterCount = $book->chapters()->count();
|
|
|
|
|
|
|
|
$deleteViewReq = $this->asEditor()->get($book->getUrl('/delete'));
|
|
|
|
$deleteViewReq->assertSeeText('Are you sure you want to delete this book?');
|
|
|
|
|
|
|
|
$deleteReq = $this->delete($book->getUrl());
|
|
|
|
$deleteReq->assertRedirect(url('/books'));
|
|
|
|
$this->assertActivityExists('book_delete', $book);
|
|
|
|
|
|
|
|
$book->refresh();
|
|
|
|
$this->assertNotNull($book->deleted_at);
|
|
|
|
|
|
|
|
$this->assertTrue($book->pages()->count() === 0);
|
|
|
|
$this->assertTrue($book->chapters()->count() === 0);
|
|
|
|
$this->assertTrue($book->pages()->withTrashed()->count() === $pageCount);
|
|
|
|
$this->assertTrue($book->chapters()->withTrashed()->count() === $chapterCount);
|
|
|
|
$this->assertTrue($book->deletions()->count() === 1);
|
|
|
|
|
|
|
|
$redirectReq = $this->get($deleteReq->baseResponse->headers->get('location'));
|
|
|
|
$redirectReq->assertNotificationContains('Book Successfully Deleted');
|
|
|
|
}
|
2021-05-29 07:49:10 -04:00
|
|
|
|
|
|
|
public function test_next_previous_navigation_controls_show_within_book_content()
|
|
|
|
{
|
|
|
|
$book = Book::query()->first();
|
|
|
|
$chapter = $book->chapters->first();
|
|
|
|
|
|
|
|
$resp = $this->asEditor()->get($chapter->getUrl());
|
|
|
|
$resp->assertElementContains('#sibling-navigation', 'Next');
|
2021-05-29 18:46:33 -04:00
|
|
|
$resp->assertElementContains('#sibling-navigation', substr($chapter->pages[0]->name, 0, 20));
|
2021-05-29 07:49:10 -04:00
|
|
|
|
|
|
|
$resp = $this->get($chapter->pages[0]->getUrl());
|
2021-05-29 18:46:33 -04:00
|
|
|
$resp->assertElementContains('#sibling-navigation', substr($chapter->pages[1]->name, 0, 20));
|
2021-05-29 07:49:10 -04:00
|
|
|
$resp->assertElementContains('#sibling-navigation', 'Previous');
|
2021-05-29 18:46:33 -04:00
|
|
|
$resp->assertElementContains('#sibling-navigation', substr($chapter->name, 0, 20));
|
2021-05-29 07:49:10 -04:00
|
|
|
}
|
2021-06-26 11:23:15 -04:00
|
|
|
}
|