mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-30 12:43:43 +08:00
f139cded78
* Temporarily moved back config path * Apply Laravel coding style * Shift exception handler * Shift HTTP kernel and middleware * Shift service providers * Convert options array to fluent methods * Shift to class based routes * Shift console routes * Ignore temporary framework files * Shift to class based factories * Namespace seeders * Shift PSR-4 autoloading * Shift config files * Default config files * Shift Laravel dependencies * Shift return type of base TestCase methods * Shift cleanup * Applied stylci style changes * Reverted config files location * Applied manual changes to Laravel 8 shift Co-authored-by: Shift <shift@laravelshift.com>
58 lines
2.1 KiB
PHP
58 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Entity;
|
|
|
|
use BookStack\Entities\Models\Book;
|
|
use BookStack\Entities\Models\Chapter;
|
|
use Tests\TestCase;
|
|
|
|
class ChapterTest extends TestCase
|
|
{
|
|
public function test_create()
|
|
{
|
|
/** @var Book $book */
|
|
$book = Book::query()->first();
|
|
|
|
$chapter = Chapter::factory()->make([
|
|
'name' => 'My First Chapter',
|
|
]);
|
|
|
|
$resp = $this->asEditor()->get($book->getUrl());
|
|
$resp->assertElementContains('a[href="' . $book->getUrl('/create-chapter') . '"]', 'New Chapter');
|
|
|
|
$resp = $this->get($book->getUrl('/create-chapter'));
|
|
$resp->assertElementContains('form[action="' . $book->getUrl('/create-chapter') . '"][method="POST"]', 'Save Chapter');
|
|
|
|
$resp = $this->post($book->getUrl('/create-chapter'), $chapter->only('name', 'description'));
|
|
$resp->assertRedirect($book->getUrl('/chapter/my-first-chapter'));
|
|
|
|
$resp = $this->get($book->getUrl('/chapter/my-first-chapter'));
|
|
$resp->assertSee($chapter->name);
|
|
$resp->assertSee($chapter->description);
|
|
}
|
|
|
|
public function test_delete()
|
|
{
|
|
$chapter = Chapter::query()->whereHas('pages')->first();
|
|
$this->assertNull($chapter->deleted_at);
|
|
$pageCount = $chapter->pages()->count();
|
|
|
|
$deleteViewReq = $this->asEditor()->get($chapter->getUrl('/delete'));
|
|
$deleteViewReq->assertSeeText('Are you sure you want to delete this chapter?');
|
|
|
|
$deleteReq = $this->delete($chapter->getUrl());
|
|
$deleteReq->assertRedirect($chapter->getParent()->getUrl());
|
|
$this->assertActivityExists('chapter_delete', $chapter);
|
|
|
|
$chapter->refresh();
|
|
$this->assertNotNull($chapter->deleted_at);
|
|
|
|
$this->assertTrue($chapter->pages()->count() === 0);
|
|
$this->assertTrue($chapter->pages()->withTrashed()->count() === $pageCount);
|
|
$this->assertTrue($chapter->deletions()->count() === 1);
|
|
|
|
$redirectReq = $this->get($deleteReq->baseResponse->headers->get('location'));
|
|
$redirectReq->assertNotificationContains('Chapter Successfully Deleted');
|
|
}
|
|
}
|