]> BookStack Code Mirror - bookstack/blobdiff - tests/Entity/BookShelfTest.php
Merge branch 'feature/#1598' of git://github.com/cw1998/BookStack into cw1998-feature...
[bookstack] / tests / Entity / BookShelfTest.php
index 88358405f729acbd45d7a1a38100513c59f38c45..8f41e83ab05b5c34fc05822bc7b87eb0ede37e5e 100644 (file)
@@ -1,14 +1,18 @@
-<?php namespace Tests;
+<?php namespace Tests\Entity;
 
-use BookStack\Auth\Role;
 use BookStack\Auth\User;
 use BookStack\Entities\Book;
 use BookStack\Entities\Bookshelf;
+use BookStack\Uploads\Image;
 use Illuminate\Support\Str;
+use Tests\TestCase;
+use Tests\Uploads\UsesImages;
 
 class BookShelfTest extends TestCase
 {
 
+    use UsesImages;
+
     public function test_shelves_shows_in_header_if_have_view_permissions()
     {
         $viewer = $this->getViewer();
@@ -83,6 +87,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->id,
+            'image_id' => $lastImage->id,
+        ]);
+        $this->assertEquals($lastImage->id, $shelf->cover->id);
+    }
+
     public function test_shelf_view()
     {
         $shelf = Bookshelf::first();