3 namespace Tests\Entity;
5 use BookStack\Entities\Models\Chapter;
8 class ChapterTest extends TestCase
10 public function test_chapter_delete()
12 $chapter = Chapter::query()->whereHas('pages')->first();
13 $this->assertNull($chapter->deleted_at);
14 $pageCount = $chapter->pages()->count();
16 $deleteViewReq = $this->asEditor()->get($chapter->getUrl('/delete'));
17 $deleteViewReq->assertSeeText('Are you sure you want to delete this chapter?');
19 $deleteReq = $this->delete($chapter->getUrl());
20 $deleteReq->assertRedirect($chapter->getParent()->getUrl());
21 $this->assertActivityExists('chapter_delete', $chapter);
24 $this->assertNotNull($chapter->deleted_at);
26 $this->assertTrue($chapter->pages()->count() === 0);
27 $this->assertTrue($chapter->pages()->withTrashed()->count() === $pageCount);
28 $this->assertTrue($chapter->deletions()->count() === 1);
30 $redirectReq = $this->get($deleteReq->baseResponse->headers->get('location'));
31 $redirectReq->assertNotificationContains('Chapter Successfully Deleted');