From 6458ebec71b60baf2abe10ddf205b15b028bc279 Mon Sep 17 00:00:00 2001 From: Kovah Date: Thu, 4 Feb 2021 16:28:39 +0100 Subject: [PATCH] Allow search of broken links only --- app/Http/Requests/SearchRequest.php | 12 +++++++----- resources/lang/en_US/search.php | 4 +--- tests/Controller/API/SearchLinksTest.php | 8 +++++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/Http/Requests/SearchRequest.php b/app/Http/Requests/SearchRequest.php index 840b8ccd..4f21cb67 100644 --- a/app/Http/Requests/SearchRequest.php +++ b/app/Http/Requests/SearchRequest.php @@ -29,9 +29,10 @@ class SearchRequest extends FormRequest public function rules() { return [ - 'query' => 'bail|required_without_all:only_lists,only_tags', - 'only_lists' => 'bail|required_without_all:query,only_tags', - 'only_tags' => 'bail|required_without_all:query,only_lists', + 'query' => 'bail|required_without_all:only_lists,only_tags,broken_only', + 'only_lists' => 'bail|required_without_all:query,only_tags,broken_only', + 'only_tags' => 'bail|required_without_all:query,only_lists,broken_only', + 'broken_only' => 'bail|required_without_all:query,only_lists,only_tags', ]; } @@ -44,8 +45,9 @@ class SearchRequest extends FormRequest { return [ 'query.required_without_all' => trans('search.validation_query_missing'), - 'only_lists.required_without_all' => trans('search.validation_lists_missing'), - 'only_tags.required_without_all' => trans('search.validation_tags_missing'), + 'only_lists.required_without_all' => trans('search.validation_query_missing'), + 'only_tags.required_without_all' => trans('search.validation_query_missing'), + 'broken_only.required_without_all' => trans('search.validation_query_missing'), ]; } } diff --git a/resources/lang/en_US/search.php b/resources/lang/en_US/search.php index 0c994016..940c2bdc 100644 --- a/resources/lang/en_US/search.php +++ b/resources/lang/en_US/search.php @@ -23,7 +23,5 @@ return [ 'no_results' => 'No results found.', - 'validation_query_missing' => 'A search query must be present if no lists or tags were provided.', - 'validation_lists_missing' => 'A list must be present if no query or some tags were provided.', - 'validation_tags_missing' => 'A tag must be present if no query or some lists were provided.', + 'validation_query_missing' => 'You must either enter a search query, or select a list, a tag or enable searching for broken links.', ]; diff --git a/tests/Controller/API/SearchLinksTest.php b/tests/Controller/API/SearchLinksTest.php index c6efcd68..95902a49 100644 --- a/tests/Controller/API/SearchLinksTest.php +++ b/tests/Controller/API/SearchLinksTest.php @@ -21,11 +21,13 @@ class SearchLinksTest extends ApiTestCase public function testWithoutQuery(): void { $response = $this->getJsonAuthorized('api/v1/search/links'); + $msg = 'You must either enter a search query, or select a list, a tag or enable searching for broken links.'; $response->assertJsonValidationErrors([ - 'query' => 'A search query must be present if no lists or tags were provided.', - 'only_lists' => 'A list must be present if no query or some tags were provided.', - 'only_tags' => 'A tag must be present if no query or some lists were provided.', + 'query' => $msg, + 'only_lists' => $msg, + 'only_tags' => $msg, + 'broken_only' => $msg, ]); }