Skip to content

Commit 51287d5

Browse files
committed
Searching: Fixed some form search issues
- Form was not retaining certain filters - Form request handling of entity type set wrong filter name Added test to cover.
1 parent c314a60 commit 51287d5

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

app/Search/SearchOptions.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static function fromRequest(Request $request): self
7373
}
7474

7575
if (isset($inputs['types']) && count($inputs['types']) < 4) {
76-
$cleanedFilters[] = new FilterSearchOption(implode('|', $inputs['types']), 'types');
76+
$cleanedFilters[] = new FilterSearchOption(implode('|', $inputs['types']), 'type');
7777
}
7878

7979
$instance->filters = new SearchOptionSet($cleanedFilters);
@@ -235,11 +235,14 @@ public function getAdditionalOptionsString(): string
235235
{
236236
$options = [];
237237

238-
// Non-[created/updated]-by-me options
238+
// Handle filters without UI support
239239
$userFilters = ['updated_by', 'created_by', 'owned_by'];
240+
$unsupportedFilters = ['is_template', 'sort_by'];
240241
foreach ($this->filters->all() as $filter) {
241242
if (in_array($filter->getKey(), $userFilters, true) && $filter->value !== null && $filter->value !== 'me') {
242243
$options[] = $filter;
244+
} else if (in_array($filter->getKey(), $unsupportedFilters, true)) {
245+
$options[] = $filter;
243246
}
244247
}
245248

tests/Entity/EntitySearchTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,8 @@ public function test_backslashes_can_be_searched_upon()
573573

574574
public function test_searches_with_terms_without_controls_includes_them_in_extras()
575575
{
576-
$resp = $this->asEditor()->get('/search?term=' . urlencode('test {updated_by:dan} {created_by:dan} -{viewed_by_me} -[a=b] -"dog"'));
577-
$this->withHtml($resp)->assertFieldHasValue('extras', '{updated_by:dan} {created_by:dan} -"dog" -[a=b] -{viewed_by_me}');
576+
$resp = $this->asEditor()->get('/search?term=' . urlencode('test {updated_by:dan} {created_by:dan} -{viewed_by_me} -[a=b] -"dog" {is_template} {sort_by:last_commented}'));
577+
$this->withHtml($resp)->assertFieldHasValue('extras', '{updated_by:dan} {created_by:dan} {is_template} {sort_by:last_commented} -"dog" -[a=b] -{viewed_by_me}');
578578
}
579579

580580
public function test_negated_searches_dont_show_in_inputs()

tests/Entity/SearchOptionsTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,19 @@ public function test_from_request_properly_parses_exacts_from_search_terms()
113113
$this->assertEquals(['"cheese"', '""', '"baked', 'beans"'], $options->exacts->toValueArray());
114114
}
115115

116+
public function test_from_request_properly_parses_provided_types()
117+
{
118+
$request = new Request([
119+
'search' => '',
120+
'types' => ['page', 'book'],
121+
]);
122+
123+
$options = SearchOptions::fromRequest($request);
124+
$filters = $options->filters->toValueMap();
125+
$this->assertCount(1, $filters);
126+
$this->assertEquals('page|book', $filters['type'] ?? 'notfound');
127+
}
128+
116129
public function test_from_request_properly_parses_out_extras_as_string()
117130
{
118131
$request = new Request([

0 commit comments

Comments
 (0)