]> BookStack Code Mirror - bookstack/blob - tests/Entity/SearchOptionsTest.php
Added testing to favourite system
[bookstack] / tests / Entity / SearchOptionsTest.php
1 <?php namespace Tests\Entity;
2
3 use BookStack\Entities\Tools\SearchOptions;
4 use Tests\TestCase;
5
6 class SearchOptionsTest extends TestCase
7 {
8     public function test_from_string_parses_a_search_string_properly()
9     {
10         $options = SearchOptions::fromString('cat "dog" [tag=good] {is_tree}');
11
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);
16     }
17
18     public function test_to_string_includes_all_items_in_the_correct_format()
19     {
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' => ''];
26
27         $output = $options->toString();
28         foreach (explode(' ', $expected) as $term) {
29             $this->assertStringContainsString($term, $output);
30         }
31     }
32
33     public function test_correct_filter_values_are_set_from_string()
34     {
35         $opts = SearchOptions::fromString('{is_tree} {name:dan} {cat:happy}');
36
37         $this->assertEquals([
38             'is_tree' => '',
39             'name' => 'dan',
40             'cat' => 'happy',
41         ], $opts->filters);
42     }
43 }