forked from BookStackApp/BookStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchOptionsTest.php
More file actions
45 lines (37 loc) · 1.33 KB
/
Copy pathSearchOptionsTest.php
File metadata and controls
45 lines (37 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Tests\Entity;
use BookStack\Search\SearchOptions;
use Tests\TestCase;
class SearchOptionsTest extends TestCase
{
public function test_from_string_parses_a_search_string_properly()
{
$options = SearchOptions::fromString('cat "dog" [tag=good] {is_tree}');
$this->assertEquals(['cat'], $options->searches);
$this->assertEquals(['dog'], $options->exacts);
$this->assertEquals(['tag=good'], $options->tags);
$this->assertEquals(['is_tree' => ''], $options->filters);
}
public function test_to_string_includes_all_items_in_the_correct_format()
{
$expected = 'cat "dog" [tag=good] {is_tree}';
$options = new SearchOptions();
$options->searches = ['cat'];
$options->exacts = ['dog'];
$options->tags = ['tag=good'];
$options->filters = ['is_tree' => ''];
$output = $options->toString();
foreach (explode(' ', $expected) as $term) {
$this->assertStringContainsString($term, $output);
}
}
public function test_correct_filter_values_are_set_from_string()
{
$opts = SearchOptions::fromString('{is_tree} {name:dan} {cat:happy}');
$this->assertEquals([
'is_tree' => '',
'name' => 'dan',
'cat' => 'happy',
], $opts->filters);
}
}