Skip to content

Commit b7d4bd5

Browse files
committed
Breadcrumbs: Set book/shelf lists to use name ordering
Previously in database order (id) which is not predictable nor parsable for users. For #4876
1 parent 5a5f0b8 commit b7d4bd5

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

app/Entities/Tools/SiblingFetcher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ public function fetch(string $entityType, int $entityId): Collection
4343
if ($contextShelf) {
4444
$entities = $contextShelf->visibleBooks()->get();
4545
} else {
46-
$entities = $this->queries->books->visibleForList()->get();
46+
$entities = $this->queries->books->visibleForList()->orderBy('name', 'asc')->get();
4747
}
4848
}
4949

5050
// Shelf
5151
if ($entity instanceof Bookshelf) {
52-
$entities = $this->queries->shelves->visibleForList()->get();
52+
$entities = $this->queries->shelves->visibleForList()->orderBy('name', 'asc')->get();
5353
}
5454

5555
return $entities;

tests/Entity/EntitySearchTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,42 @@ public function test_sibling_search_for_shelves()
356356
}
357357
}
358358

359+
public function test_sibling_search_for_books_provides_results_in_alphabetical_order()
360+
{
361+
$contextBook = $this->entities->book();
362+
$searchBook = $this->entities->book();
363+
364+
$searchBook->name = 'Zebras';
365+
$searchBook->save();
366+
367+
$search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextBook->id}&entity_type=book");
368+
$this->withHtml($search)->assertElementNotContains('a:first-child', 'Zebras');
369+
370+
$searchBook->name = 'AAAAAAArdvarks';
371+
$searchBook->save();
372+
373+
$search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextBook->id}&entity_type=book");
374+
$this->withHtml($search)->assertElementContains('a:first-child', 'AAAAAAArdvarks');
375+
}
376+
377+
public function test_sibling_search_for_shelves_provides_results_in_alphabetical_order()
378+
{
379+
$contextShelf = $this->entities->shelf();
380+
$searchShelf = $this->entities->shelf();
381+
382+
$searchShelf->name = 'Zebras';
383+
$searchShelf->save();
384+
385+
$search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextShelf->id}&entity_type=bookshelf");
386+
$this->withHtml($search)->assertElementNotContains('a:first-child', 'Zebras');
387+
388+
$searchShelf->name = 'AAAAAAArdvarks';
389+
$searchShelf->save();
390+
391+
$search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextShelf->id}&entity_type=bookshelf");
392+
$this->withHtml($search)->assertElementContains('a:first-child', 'AAAAAAArdvarks');
393+
}
394+
359395
public function test_search_works_on_updated_page_content()
360396
{
361397
$page = $this->entities->page();

0 commit comments

Comments
 (0)