Books: On delete, redirect to shelf if in context

For #6029
Added tests to cover
This commit is contained in:
Dan Brown
2026-02-20 11:23:26 +00:00
parent 5e12b678c7
commit 8e99fc6783
3 changed files with 27 additions and 0 deletions
@@ -224,9 +224,14 @@ class BookController extends Controller
{
$book = $this->queries->findVisibleBySlugOrFail($bookSlug);
$this->checkOwnablePermission(Permission::BookDelete, $book);
$contextShelf = $this->shelfContext->getContextualShelfForBook($book);
$this->bookRepo->destroy($book);
if ($contextShelf) {
return redirect($contextShelf->getUrl());
}
return redirect('/books');
}
+14
View File
@@ -154,6 +154,20 @@ class BookTest extends TestCase
$this->assertNotificationContains($redirectReq, 'Book Successfully Deleted');
}
public function test_delete_with_shelf_context_returns_to_shelf_view_after_delete()
{
$shelf = $this->entities->shelfHasBooks();
/** @var Book $book */
$book = $shelf->books()->first();
$this->asEditor()->get($shelf->getUrl());
$this->get($book->getUrl());
$this->get($book->getUrl('/delete'));
$resp = $this->delete($book->getUrl());
$resp->assertRedirect($shelf->getUrl());
}
public function test_cancel_on_create_page_leads_back_to_books_listing()
{
$resp = $this->asEditor()->get('/create-book');
+8
View File
@@ -110,6 +110,14 @@ class EntityProvider
return $shelf;
}
/**
* Get a shelf that has books assigned.
*/
public function shelfHasBooks(): Bookshelf
{
return $this->shelf(fn(Builder $query) => $query->whereHas('books'));
}
/**
* Get all entity types from the system.
* @return array{page: Page, chapter: Chapter, book: Book, bookshelf: Bookshelf}