mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Search: Added structure for search term inputs
Sets things up to allow more complex terms ready to handle negation.
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
namespace Tests\Entity;
|
||||
|
||||
use BookStack\Search\SearchOptions;
|
||||
use BookStack\Search\SearchOptionSet;
|
||||
use Illuminate\Http\Request;
|
||||
use Tests\TestCase;
|
||||
|
||||
@ -12,27 +13,27 @@ class SearchOptionsTest extends TestCase
|
||||
{
|
||||
$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);
|
||||
$this->assertEquals(['cat'], $options->searches->toValueArray());
|
||||
$this->assertEquals(['dog'], $options->exacts->toValueArray());
|
||||
$this->assertEquals(['tag=good'], $options->tags->toValueArray());
|
||||
$this->assertEquals(['is_tree' => ''], $options->filters->toValueMap());
|
||||
}
|
||||
|
||||
public function test_from_string_properly_parses_escaped_quotes()
|
||||
{
|
||||
$options = SearchOptions::fromString('"\"cat\"" surprise "\"\"" "\"donkey" "\"" "\\\\"');
|
||||
|
||||
$this->assertEquals(['"cat"', '""', '"donkey', '"', '\\'], $options->exacts);
|
||||
$this->assertEquals(['"cat"', '""', '"donkey', '"', '\\'], $options->exacts->toValueArray());
|
||||
}
|
||||
|
||||
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' => ''];
|
||||
$options->searches = SearchOptionSet::fromValueArray(['cat']);
|
||||
$options->exacts = SearchOptionSet::fromValueArray(['dog']);
|
||||
$options->tags = SearchOptionSet::fromValueArray(['tag=good']);
|
||||
$options->filters = SearchOptionSet::fromMapArray(['is_tree' => '']);
|
||||
|
||||
$output = $options->toString();
|
||||
foreach (explode(' ', $expected) as $term) {
|
||||
@ -43,7 +44,7 @@ class SearchOptionsTest extends TestCase
|
||||
public function test_to_string_escapes_as_expected()
|
||||
{
|
||||
$options = new SearchOptions();
|
||||
$options->exacts = ['"cat"', '""', '"donkey', '"', '\\', '\\"'];
|
||||
$options->exacts = SearchOptionSet::fromValueArray(['"cat"', '""', '"donkey', '"', '\\', '\\"']);
|
||||
|
||||
$output = $options->toString();
|
||||
$this->assertEquals('"\"cat\"" "\"\"" "\"donkey" "\"" "\\\\" "\\\\\""', $output);
|
||||
@ -57,14 +58,14 @@ class SearchOptionsTest extends TestCase
|
||||
'is_tree' => '',
|
||||
'name' => 'dan',
|
||||
'cat' => 'happy',
|
||||
], $opts->filters);
|
||||
], $opts->filters->toValueMap());
|
||||
}
|
||||
public function test_it_cannot_parse_out_empty_exacts()
|
||||
{
|
||||
$options = SearchOptions::fromString('"" test ""');
|
||||
|
||||
$this->assertEmpty($options->exacts);
|
||||
$this->assertCount(1, $options->searches);
|
||||
$this->assertEmpty($options->exacts->toValueArray());
|
||||
$this->assertCount(1, $options->searches->toValueArray());
|
||||
}
|
||||
|
||||
public function test_from_request_properly_parses_exacts_from_search_terms()
|
||||
@ -74,7 +75,7 @@ class SearchOptionsTest extends TestCase
|
||||
]);
|
||||
|
||||
$options = SearchOptions::fromRequest($request);
|
||||
$this->assertEquals(["biscuits"], $options->searches);
|
||||
$this->assertEquals(['"cheese"', '""', '"baked', 'beans"'], $options->exacts);
|
||||
$this->assertEquals(["biscuits"], $options->searches->toValueArray());
|
||||
$this->assertEquals(['"cheese"', '""', '"baked', 'beans"'], $options->exacts->toValueArray());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user