X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/0288320700668bae9d87bcc7c3e7d66aaa05f6aa..a2440e20bc017a7f3754308ecd5229903ab714f7:/tests/Entity/BookTest.php diff --git a/tests/Entity/BookTest.php b/tests/Entity/BookTest.php index 7f102a17e..6b3c6aa38 100644 --- a/tests/Entity/BookTest.php +++ b/tests/Entity/BookTest.php @@ -50,6 +50,33 @@ class BookTest extends TestCase $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() { /** @var Book $book */ @@ -74,6 +101,36 @@ class BookTest extends TestCase $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() { $book = Book::query()->whereHas('pages')->whereHas('chapters')->first(); @@ -290,6 +347,7 @@ class BookTest extends TestCase /** @var Book $copy */ $copy = Book::query()->where('name', '=', 'My copy book')->first(); + $this->assertNotNull($copy->cover); $this->assertNotEquals($book->cover->id, $copy->cover->id); }