3 namespace Tests\Search;
5 use BookStack\Entities\Models\Book;
6 use BookStack\Entities\Models\Bookshelf;
9 class SiblingSearchTest extends TestCase
11 public function test_sibling_search_for_pages()
13 $chapter = $this->entities->chapterHasPages();
14 $this->assertGreaterThan(2, count($chapter->pages), 'Ensure we\'re testing with at least 1 sibling');
15 $page = $chapter->pages->first();
17 $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$page->id}&entity_type=page");
18 $search->assertSuccessful();
19 foreach ($chapter->pages as $page) {
20 $search->assertSee($page->name);
23 $search->assertDontSee($chapter->name);
26 public function test_sibling_search_for_pages_without_chapter()
28 $page = $this->entities->pageNotWithinChapter();
29 $bookChildren = $page->book->getDirectVisibleChildren();
30 $this->assertGreaterThan(2, count($bookChildren), 'Ensure we\'re testing with at least 1 sibling');
32 $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$page->id}&entity_type=page");
33 $search->assertSuccessful();
34 foreach ($bookChildren as $child) {
35 $search->assertSee($child->name);
38 $search->assertDontSee($page->book->name);
41 public function test_sibling_search_for_chapters()
43 $chapter = $this->entities->chapter();
44 $bookChildren = $chapter->book->getDirectVisibleChildren();
45 $this->assertGreaterThan(2, count($bookChildren), 'Ensure we\'re testing with at least 1 sibling');
47 $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$chapter->id}&entity_type=chapter");
48 $search->assertSuccessful();
49 foreach ($bookChildren as $child) {
50 $search->assertSee($child->name);
53 $search->assertDontSee($chapter->book->name);
56 public function test_sibling_search_for_books()
58 $books = Book::query()->take(10)->get();
59 $book = $books->first();
60 $this->assertGreaterThan(2, count($books), 'Ensure we\'re testing with at least 1 sibling');
62 $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$book->id}&entity_type=book");
63 $search->assertSuccessful();
64 foreach ($books as $expectedBook) {
65 $search->assertSee($expectedBook->name);
69 public function test_sibling_search_for_shelves()
71 $shelves = Bookshelf::query()->take(10)->get();
72 $shelf = $shelves->first();
73 $this->assertGreaterThan(2, count($shelves), 'Ensure we\'re testing with at least 1 sibling');
75 $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$shelf->id}&entity_type=bookshelf");
76 $search->assertSuccessful();
77 foreach ($shelves as $expectedShelf) {
78 $search->assertSee($expectedShelf->name);
82 public function test_sibling_search_for_books_provides_results_in_alphabetical_order()
84 $contextBook = $this->entities->book();
85 $searchBook = $this->entities->book();
87 $searchBook->name = 'Zebras';
90 $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextBook->id}&entity_type=book");
91 $this->withHtml($search)->assertElementNotContains('a:first-child', 'Zebras');
93 $searchBook->name = '1AAAAAAArdvarks';
96 $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextBook->id}&entity_type=book");
97 $this->withHtml($search)->assertElementContains('a:first-child', '1AAAAAAArdvarks');
100 public function test_sibling_search_for_shelves_provides_results_in_alphabetical_order()
102 $contextShelf = $this->entities->shelf();
103 $searchShelf = $this->entities->shelf();
105 $searchShelf->name = 'Zebras';
106 $searchShelf->save();
108 $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextShelf->id}&entity_type=bookshelf");
109 $this->withHtml($search)->assertElementNotContains('a:first-child', 'Zebras');
111 $searchShelf->name = '1AAAAAAArdvarks';
112 $searchShelf->save();
114 $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextShelf->id}&entity_type=bookshelf");
115 $this->withHtml($search)->assertElementContains('a:first-child', '1AAAAAAArdvarks');