From ea3c3cde5aa7e25dd68821fe4b1b8247b2ab714a Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sat, 15 Feb 2020 18:34:02 +0000 Subject: [PATCH] Added test to ensure shelf cover image gets set on create Related to #1897 --- tests/Entity/BookShelfTest.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/Entity/BookShelfTest.php b/tests/Entity/BookShelfTest.php index 5c7673847..b44761203 100644 --- a/tests/Entity/BookShelfTest.php +++ b/tests/Entity/BookShelfTest.php @@ -1,14 +1,17 @@ getViewer(); @@ -83,6 +86,26 @@ class BookShelfTest extends TestCase $this->assertDatabaseHas('bookshelves_books', ['bookshelf_id' => $shelf->id, 'book_id' => $booksToInclude[1]->id]); } + public function test_shelves_create_sets_cover_image() + { + $shelfInfo = [ + 'name' => 'My test book' . Str::random(4), + 'description' => 'Test book description ' . Str::random(10) + ]; + + $imageFile = $this->getTestImage('shelf-test.png'); + $resp = $this->asEditor()->call('POST', '/shelves', $shelfInfo, [], ['image' => $imageFile]); + $resp->assertRedirect(); + + $lastImage = Image::query()->orderByDesc('id')->firstOrFail(); + $shelf = Bookshelf::query()->where('name', '=', $shelfInfo['name'])->first(); + $this->assertDatabaseHas('bookshelves', [ + 'id' => $shelf, + 'image_id' => $lastImage->id, + ]); + $this->assertEquals($lastImage->id, $shelf->cover->id); + } + public function test_shelf_view() { $shelf = Bookshelf::first();