mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-06-06 02:24:33 +08:00
Added test to ensure shelf cover image gets set on create
Related to #1897
This commit is contained in:
@ -1,14 +1,17 @@
|
|||||||
<?php namespace Tests;
|
<?php namespace Tests;
|
||||||
|
|
||||||
use BookStack\Auth\Role;
|
|
||||||
use BookStack\Auth\User;
|
use BookStack\Auth\User;
|
||||||
use BookStack\Entities\Book;
|
use BookStack\Entities\Book;
|
||||||
use BookStack\Entities\Bookshelf;
|
use BookStack\Entities\Bookshelf;
|
||||||
|
use BookStack\Uploads\Image;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Tests\Uploads\UsesImages;
|
||||||
|
|
||||||
class BookShelfTest extends TestCase
|
class BookShelfTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
use UsesImages;
|
||||||
|
|
||||||
public function test_shelves_shows_in_header_if_have_view_permissions()
|
public function test_shelves_shows_in_header_if_have_view_permissions()
|
||||||
{
|
{
|
||||||
$viewer = $this->getViewer();
|
$viewer = $this->getViewer();
|
||||||
@ -83,6 +86,26 @@ class BookShelfTest extends TestCase
|
|||||||
$this->assertDatabaseHas('bookshelves_books', ['bookshelf_id' => $shelf->id, 'book_id' => $booksToInclude[1]->id]);
|
$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()
|
public function test_shelf_view()
|
||||||
{
|
{
|
||||||
$shelf = Bookshelf::first();
|
$shelf = Bookshelf::first();
|
||||||
|
Reference in New Issue
Block a user