3 namespace Tests\Entity;
5 use BookStack\Search\SearchOptions;
8 class SearchOptionsTest extends TestCase
10 public function test_from_string_parses_a_search_string_properly()
12 $options = SearchOptions::fromString('cat "dog" [tag=good] {is_tree}');
14 $this->assertEquals(['cat'], $options->searches);
15 $this->assertEquals(['dog'], $options->exacts);
16 $this->assertEquals(['tag=good'], $options->tags);
17 $this->assertEquals(['is_tree' => ''], $options->filters);
20 public function test_to_string_includes_all_items_in_the_correct_format()
22 $expected = 'cat "dog" [tag=good] {is_tree}';
23 $options = new SearchOptions();
24 $options->searches = ['cat'];
25 $options->exacts = ['dog'];
26 $options->tags = ['tag=good'];
27 $options->filters = ['is_tree' => ''];
29 $output = $options->toString();
30 foreach (explode(' ', $expected) as $term) {
31 $this->assertStringContainsString($term, $output);
35 public function test_correct_filter_values_are_set_from_string()
37 $opts = SearchOptions::fromString('{is_tree} {name:dan} {cat:happy}');