mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-04-25 21:54:05 +08:00
parent
36f0a68f1b
commit
3ed1ffdbeb
@ -88,10 +88,11 @@ class BookController extends Controller
|
|||||||
public function store(Request $request, string $shelfSlug = null)
|
public function store(Request $request, string $shelfSlug = null)
|
||||||
{
|
{
|
||||||
$this->checkPermission('book-create-all');
|
$this->checkPermission('book-create-all');
|
||||||
$this->validate($request, [
|
$validated = $this->validate($request, [
|
||||||
'name' => ['required', 'string', 'max:255'],
|
'name' => ['required', 'string', 'max:255'],
|
||||||
'description' => ['string', 'max:1000'],
|
'description' => ['string', 'max:1000'],
|
||||||
'image' => array_merge(['nullable'], $this->getImageValidationRules()),
|
'image' => array_merge(['nullable'], $this->getImageValidationRules()),
|
||||||
|
'tags' => ['array'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$bookshelf = null;
|
$bookshelf = null;
|
||||||
@ -100,7 +101,7 @@ class BookController extends Controller
|
|||||||
$this->checkOwnablePermission('bookshelf-update', $bookshelf);
|
$this->checkOwnablePermission('bookshelf-update', $bookshelf);
|
||||||
}
|
}
|
||||||
|
|
||||||
$book = $this->bookRepo->create($request->all());
|
$book = $this->bookRepo->create($validated);
|
||||||
|
|
||||||
if ($bookshelf) {
|
if ($bookshelf) {
|
||||||
$bookshelf->appendBook($book);
|
$bookshelf->appendBook($book);
|
||||||
@ -163,6 +164,7 @@ class BookController extends Controller
|
|||||||
'name' => ['required', 'string', 'max:255'],
|
'name' => ['required', 'string', 'max:255'],
|
||||||
'description' => ['string', 'max:1000'],
|
'description' => ['string', 'max:1000'],
|
||||||
'image' => array_merge(['nullable'], $this->getImageValidationRules()),
|
'image' => array_merge(['nullable'], $this->getImageValidationRules()),
|
||||||
|
'tags' => ['array'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($request->has('image_reset')) {
|
if ($request->has('image_reset')) {
|
||||||
|
@ -50,6 +50,33 @@ class BookTest extends TestCase
|
|||||||
$this->assertEquals('my-first-book', $books[1]->slug);
|
$this->assertEquals('my-first-book', $books[1]->slug);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_create_sets_tags()
|
||||||
|
{
|
||||||
|
// Cheeky initial update to refresh slug
|
||||||
|
$this->asEditor()->post('books', [
|
||||||
|
'name' => 'My book with tags',
|
||||||
|
'description' => 'A book with tags',
|
||||||
|
'tags' => [
|
||||||
|
[
|
||||||
|
'name' => 'Category',
|
||||||
|
'value' => 'Donkey Content',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Level',
|
||||||
|
'value' => '5',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
/** @var Book $book */
|
||||||
|
$book = Book::query()->where('name', '=', 'My book with tags')->firstOrFail();
|
||||||
|
$tags = $book->tags()->get();
|
||||||
|
|
||||||
|
$this->assertEquals(2, $tags->count());
|
||||||
|
$this->assertEquals('Donkey Content', $tags[0]->value);
|
||||||
|
$this->assertEquals('Level', $tags[1]->name);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_update()
|
public function test_update()
|
||||||
{
|
{
|
||||||
/** @var Book $book */
|
/** @var Book $book */
|
||||||
@ -74,6 +101,36 @@ class BookTest extends TestCase
|
|||||||
$resp->assertSee($newDesc);
|
$resp->assertSee($newDesc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_update_sets_tags()
|
||||||
|
{
|
||||||
|
/** @var Book $book */
|
||||||
|
$book = Book::query()->first();
|
||||||
|
|
||||||
|
$this->assertEquals(0, $book->tags()->count());
|
||||||
|
|
||||||
|
// Cheeky initial update to refresh slug
|
||||||
|
$this->asEditor()->put($book->getUrl(), [
|
||||||
|
'name' => $book->name,
|
||||||
|
'tags' => [
|
||||||
|
[
|
||||||
|
'name' => 'Category',
|
||||||
|
'value' => 'Dolphin Content',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'Level',
|
||||||
|
'value' => '5',
|
||||||
|
]
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$book->refresh();
|
||||||
|
$tags = $book->tags()->get();
|
||||||
|
|
||||||
|
$this->assertEquals(2, $tags->count());
|
||||||
|
$this->assertEquals('Dolphin Content', $tags[0]->value);
|
||||||
|
$this->assertEquals('Level', $tags[1]->name);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_delete()
|
public function test_delete()
|
||||||
{
|
{
|
||||||
$book = Book::query()->whereHas('pages')->whereHas('chapters')->first();
|
$book = Book::query()->whereHas('pages')->whereHas('chapters')->first();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user