]> BookStack Code Mirror - bookstack/blob - tests/Entity/ChapterTest.php
Merge branch 'v21.05.x'
[bookstack] / tests / Entity / ChapterTest.php
1 <?php
2
3 namespace Tests\Entity;
4
5 use BookStack\Entities\Models\Chapter;
6 use Tests\TestCase;
7
8 class ChapterTest extends TestCase
9 {
10     public function test_chapter_delete()
11     {
12         $chapter = Chapter::query()->whereHas('pages')->first();
13         $this->assertNull($chapter->deleted_at);
14         $pageCount = $chapter->pages()->count();
15
16         $deleteViewReq = $this->asEditor()->get($chapter->getUrl('/delete'));
17         $deleteViewReq->assertSeeText('Are you sure you want to delete this chapter?');
18
19         $deleteReq = $this->delete($chapter->getUrl());
20         $deleteReq->assertRedirect($chapter->getParent()->getUrl());
21         $this->assertActivityExists('chapter_delete', $chapter);
22
23         $chapter->refresh();
24         $this->assertNotNull($chapter->deleted_at);
25
26         $this->assertTrue($chapter->pages()->count() === 0);
27         $this->assertTrue($chapter->pages()->withTrashed()->count() === $pageCount);
28         $this->assertTrue($chapter->deletions()->count() === 1);
29
30         $redirectReq = $this->get($deleteReq->baseResponse->headers->get('location'));
31         $redirectReq->assertNotificationContains('Chapter Successfully Deleted');
32     }
33 }