3 use Illuminate\Support\Facades\DB;
5 class EntitySearchTest extends TestCase
8 public function test_page_search()
10 $book = \BookStack\Book::all()->first();
11 $page = $book->pages->first();
15 ->type($page->name, 'term')
16 ->press('header-search-box-button')
17 ->see('Search Results')
20 ->seePageIs($page->getUrl());
23 public function test_invalid_page_search()
27 ->type('<p>test</p>', 'term')
28 ->press('header-search-box-button')
29 ->see('Search Results')
33 public function test_empty_search_redirects_back()
37 ->visit('/search/all')
41 public function test_book_search()
43 $book = \BookStack\Book::all()->first();
44 $page = $book->pages->last();
45 $chapter = $book->chapters->last();
48 ->visit('/search/book/' . $book->id . '?term=' . urlencode($page->name))
51 ->visit('/search/book/' . $book->id . '?term=' . urlencode($chapter->name))
52 ->see($chapter->name);
55 public function test_empty_book_search_redirects_back()
57 $book = \BookStack\Book::all()->first();
60 ->visit('/search/book/' . $book->id . '?term=')
61 ->seePageIs('/books');
65 public function test_pages_search_listing()
67 $page = \BookStack\Page::all()->last();
68 $this->asAdmin()->visit('/search/pages?term=' . $page->name)
69 ->see('Page Search Results')->see('.entity-list', $page->name);
72 public function test_chapters_search_listing()
74 $chapter = \BookStack\Chapter::all()->last();
75 $this->asAdmin()->visit('/search/chapters?term=' . $chapter->name)
76 ->see('Chapter Search Results')->seeInElement('.entity-list', $chapter->name);
79 public function test_search_quote_term_preparation()
81 $termString = '"192" cat "dog hat"';
82 $repo = $this->app[\BookStack\Repos\EntityRepo::class];
83 $preparedTerms = $repo->prepareSearchTerms($termString);
84 $this->assertTrue($preparedTerms === ['"192"','"dog hat"', 'cat']);
87 public function test_books_search_listing()
89 $book = \BookStack\Book::all()->last();
90 $this->asAdmin()->visit('/search/books?term=' . $book->name)
91 ->see('Book Search Results')->see('.entity-list', $book->name);
94 public function test_searching_hypen_doesnt_break()
96 $this->visit('/search/all?term=cat+-')
100 public function test_tag_search()
113 $pageA = \BookStack\Page::first();
114 $pageA->tags()->saveMany($newTags);
116 $pageB = \BookStack\Page::all()->last();
117 $pageB->tags()->create(['name' => 'animal', 'value' => 'dog']);
119 $this->asAdmin()->visit('/search/all?term=%5Banimal%5D')
120 ->seeLink($pageA->name)
121 ->seeLink($pageB->name);
123 $this->visit('/search/all?term=%5Bcolor%5D')
124 ->seeLink($pageA->name)
125 ->dontSeeLink($pageB->name);
127 $this->visit('/search/all?term=%5Banimal%3Dcat%5D')
128 ->seeLink($pageA->name)
129 ->dontSeeLink($pageB->name);
133 public function test_ajax_entity_search()
135 $page = \BookStack\Page::all()->last();
136 $notVisitedPage = \BookStack\Page::first();
137 $this->visit($page->getUrl());
138 $this->asAdmin()->visit('/ajax/search/entities?term=' . $page->name)->see('.entity-list', $page->name);
139 $this->asAdmin()->visit('/ajax/search/entities?types=book&term=' . $page->name)->dontSee('.entity-list', $page->name);
140 $this->asAdmin()->visit('/ajax/search/entities')->see('.entity-list', $page->name)->dontSee($notVisitedPage->name);