1 <?php namespace Tests\Entity;
3 use BookStack\Entities\Tools\SearchOptions;
6 class SearchOptionsTest extends TestCase
8 public function test_from_string_parses_a_search_string_properly()
10 $options = SearchOptions::fromString('cat "dog" [tag=good] {is_tree}');
12 $this->assertEquals(['cat'], $options->searches);
13 $this->assertEquals(['dog'], $options->exacts);
14 $this->assertEquals(['tag=good'], $options->tags);
15 $this->assertEquals(['is_tree' => ''], $options->filters);
18 public function test_to_string_includes_all_items_in_the_correct_format()
20 $expected = 'cat "dog" [tag=good] {is_tree}';
21 $options = new SearchOptions;
22 $options->searches = ['cat'];
23 $options->exacts = ['dog'];
24 $options->tags = ['tag=good'];
25 $options->filters = ['is_tree' => ''];
27 $output = $options->toString();
28 foreach (explode(' ', $expected) as $term) {
29 $this->assertStringContainsString($term, $output);
33 public function test_correct_filter_values_are_set_from_string()
35 $opts = SearchOptions::fromString('{is_tree} {name:dan} {cat:happy}');