From bd1309491ba6af60634531b6042e868cb125fc7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Tue, 7 Oct 2025 11:45:02 -0300 Subject: [PATCH] Bug 40966: Regression tests Tests verify that whole_record and weighted_fields parameters are correctly included in the query_cgi string returned by build_query_compat(), ensuring these parameters are preserved in facet links and pagination. To test: 1. Apply this patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t => FAIL: The values are not being passed around --- .../SearchEngine/Elasticsearch/QueryBuilder.t | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t index a47dd32a3d4..0f9ed8239ee 100755 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t @@ -252,7 +252,7 @@ subtest 'build_authorities_query_compat() tests' => sub { }; subtest 'build_query tests' => sub { - plan tests => 69; + plan tests => 72; my $qb; @@ -342,6 +342,28 @@ subtest 'build_query tests' => sub { is( $query_cgi, 'idx=ti&q=%22donald%20duck%22&idx=au&q=walt%20disney', 'query cgi ok for multiterm query' ); is( $query_desc, '(title:("donald duck")) (author:(walt disney))', 'query desc ok for multiterm query' ); + # Test whole_record and weighted_fields parameters in query_cgi + ( undef, $query, $simple_query, $query_cgi, $query_desc ) = $qb->build_query_compat( + undef, ['test'], ['kw'], undef, undef, undef, undef, + { whole_record => 1, weighted_fields => 1 } + ); + is( + $query_cgi, 'idx=kw&q=test&weighted_fields=1&whole_record=1', + 'query_cgi includes whole_record and weighted_fields parameters' + ); + + ( undef, $query, $simple_query, $query_cgi, $query_desc ) = $qb->build_query_compat( + undef, ['test'], ['kw'], undef, undef, undef, undef, + { whole_record => 1 } + ); + is( $query_cgi, 'idx=kw&q=test&whole_record=1', 'query_cgi includes whole_record parameter only' ); + + ( undef, $query, $simple_query, $query_cgi, $query_desc ) = $qb->build_query_compat( + undef, ['test'], ['kw'], undef, undef, undef, undef, + { weighted_fields => 1 } + ); + is( $query_cgi, 'idx=kw&q=test&weighted_fields=1', 'query_cgi includes weighted_fields parameter only' ); + ( undef, $query ) = $qb->build_query_compat( undef, ['2019'], ['yr,st-year'] ); is( $query->{query}{bool}{must}[0]{query_string}{query}, -- 2.51.0