$exactSearchB->assertStatus(200)->assertDontSee($page->name);
}
+ public function test_negated_searches()
+ {
+ $page = $this->entities->newPage(['name' => 'My new test negation page', 'html' => '<p>An angry tortoise wore trumpeted plimsoles</p>']);
+ $page->tags()->saveMany([new Tag(['name' => 'DonkCount', 'value' => '500'])]);
+ $page->created_by = $this->users->admin()->id;
+ $page->save();
+
+ $editor = $this->users->editor();
+ $this->actingAs($editor);
+
+ $exactSearch = $this->get('/search?term=' . urlencode('negation -"tortoise"'));
+ $exactSearch->assertStatus(200)->assertDontSeeText($page->name);
+
+ $tagSearchA = $this->get('/search?term=' . urlencode('negation [DonkCount=500]'));
+ $tagSearchA->assertStatus(200)->assertSeeText($page->name);
+ $tagSearchB = $this->get('/search?term=' . urlencode('negation -[DonkCount=500]'));
+ $tagSearchB->assertStatus(200)->assertDontSeeText($page->name);
+
+ $filterSearchA = $this->get('/search?term=' . urlencode('negation -{created_by:me}'));
+ $filterSearchA->assertStatus(200)->assertSeeText($page->name);
+ $page->created_by = $editor->id;
+ $page->save();
+ $filterSearchB = $this->get('/search?term=' . urlencode('negation -{created_by:me}'));
+ $filterSearchB->assertStatus(200)->assertDontSeeText($page->name);
+ }
+
public function test_search_terms_with_delimiters_are_converted_to_exact_matches()
{
$this->asEditor();
public function test_sibling_search_for_pages_without_chapter()
{
$page = $this->entities->pageNotWithinChapter();
- $bookChildren = $page->book->getDirectChildren();
+ $bookChildren = $page->book->getDirectVisibleChildren();
$this->assertGreaterThan(2, count($bookChildren), 'Ensure we\'re testing with at least 1 sibling');
$search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$page->id}&entity_type=page");
public function test_sibling_search_for_chapters()
{
$chapter = $this->entities->chapter();
- $bookChildren = $chapter->book->getDirectChildren();
+ $bookChildren = $chapter->book->getDirectVisibleChildren();
$this->assertGreaterThan(2, count($bookChildren), 'Ensure we\'re testing with at least 1 sibling');
$search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$chapter->id}&entity_type=chapter");
}
}
+ public function test_sibling_search_for_books_provides_results_in_alphabetical_order()
+ {
+ $contextBook = $this->entities->book();
+ $searchBook = $this->entities->book();
+
+ $searchBook->name = 'Zebras';
+ $searchBook->save();
+
+ $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextBook->id}&entity_type=book");
+ $this->withHtml($search)->assertElementNotContains('a:first-child', 'Zebras');
+
+ $searchBook->name = 'AAAAAAArdvarks';
+ $searchBook->save();
+
+ $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextBook->id}&entity_type=book");
+ $this->withHtml($search)->assertElementContains('a:first-child', 'AAAAAAArdvarks');
+ }
+
+ public function test_sibling_search_for_shelves_provides_results_in_alphabetical_order()
+ {
+ $contextShelf = $this->entities->shelf();
+ $searchShelf = $this->entities->shelf();
+
+ $searchShelf->name = 'Zebras';
+ $searchShelf->save();
+
+ $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextShelf->id}&entity_type=bookshelf");
+ $this->withHtml($search)->assertElementNotContains('a:first-child', 'Zebras');
+
+ $searchShelf->name = 'AAAAAAArdvarks';
+ $searchShelf->save();
+
+ $search = $this->actingAs($this->users->viewer())->get("/search/entity/siblings?entity_id={$contextShelf->id}&entity_type=bookshelf");
+ $this->withHtml($search)->assertElementContains('a:first-child', 'AAAAAAArdvarks');
+ }
+
public function test_search_works_on_updated_page_content()
{
$page = $this->entities->page();
$search->assertSee($page->getUrl(), false);
}
- public function test_searches_with_user_filters_adds_them_into_advanced_search_form()
+ public function test_searches_with_terms_without_controls_includes_them_in_extras()
+ {
+ $resp = $this->asEditor()->get('/search?term=' . urlencode('test {updated_by:dan} {created_by:dan} -{viewed_by_me} -[a=b] -"dog" {is_template} {sort_by:last_commented}'));
+ $this->withHtml($resp)->assertFieldHasValue('extras', '{updated_by:dan} {created_by:dan} {is_template} {sort_by:last_commented} -"dog" -[a=b] -{viewed_by_me}');
+ }
+
+ public function test_negated_searches_dont_show_in_inputs()
{
- $resp = $this->asEditor()->get('/search?term=' . urlencode('test {updated_by:dan} {created_by:dan}'));
- $this->withHtml($resp)->assertElementExists('form input[name="filters[updated_by]"][value="dan"]');
- $this->withHtml($resp)->assertElementExists('form input[name="filters[created_by]"][value="dan"]');
+ $resp = $this->asEditor()->get('/search?term=' . urlencode('-{created_by:me} -[a=b] -"dog"'));
+ $this->withHtml($resp)->assertElementNotExists('input[name="tags[]"][value="a=b"]');
+ $this->withHtml($resp)->assertElementNotExists('input[name="exact[]"][value="dog"]');
+ $this->withHtml($resp)->assertElementNotExists('input[name="filters[created_by]"][value="me"][checked="checked"]');
}
public function test_searches_with_user_filters_using_me_adds_them_into_advanced_search_form()