From 0d14cae1113a846c8830fd19b29428aab90dd87f Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 12 Jun 2024 11:41:53 +0000 Subject: [PATCH] Bug 33407: (follow-up) Expand tests This expands the tests to cover all removed punctuation and confirm that it is not removed when not surrounded by spaces. It also shows that repeated punctuation is removed. I cannot make the slashes match in any case - can we get a follow up to prove that case Janusz? --- .../SearchEngine/Elasticsearch/QueryBuilder.t | 48 ++++++++++++++++--- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t index 237e387cfbc..a8e583eccc1 100755 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t @@ -449,13 +449,47 @@ subtest 'build_query tests' => sub { "query of boolean type field is not truncated even if QueryAutoTruncate is set" ); - ( undef, $query ) = - $qb->build_query_compat( undef, ['First title ; Second title : some & subtitle / Authors Name'] ); - is( - $query->{query}{query_string}{query}, - '(First* title* Second* title* some* subtitle* Authors* Name*)', - "ISBD punctualtion and problematic characters properly removed" - ); + subtest 'removal of punctuation surrounded by spaces when autotruncate enabled' => sub { + plan tests => 4; + ( undef, $query ) = + $qb->build_query_compat( undef, ['First title ; Second title : some & subtitle / Authors Name'] ); + is( + $query->{query}{query_string}{query}, + '(First* title* Second* title* some* subtitle* Authors* Name*)', + "ISBD punctuation and problematic characters surrounded by spaces properly removed" + ); + + ( undef, $query ) = + $qb->build_query_compat( undef, ['comma , period . equal = hyphen - slash / escaped_slash \/'] ); + is( + $query->{query}{query_string}{query}, + '(comma* period* equal* hyphen* slash* escaped_slash*)', + "Other problematic characters surrounded by spaces properly removed" + ); + + ( undef, $query ) = + $qb->build_query_compat( undef, [' &;,:=-/ &&&==&& ::-:: '] ); + is( + $query->{query}{query_string}{query}, + '()', + "Repeated problematic characters surrounded by spaces removed" + ); + + ( undef, $query ) = $qb->build_query_compat( + undef, + [ + '& amp& semicolon; ;colonsemi full: :full comma, ,comma dot. .dot =equal equal= hyphen- -hypen slash\\/ \\/slash' + ] + ); + is( + $query->{query}{query_string}{query}, + '(&* amp& semicolon; ;colonsemi* full* full* comma, ,comma* dot. .dot* equal* equal* hyphen- -hypen* slash\/ \/slash*)', + "ISBD punctuation and problematic characters not removed when not surrounded by spaces." + ); + + # Note above: semicolons and equals removed asthose are search field indicators - terms ending in punctuation + # are not truncated + }; ( undef, $query ) = $qb->build_query_compat( undef, ['J.R.R'] ); is( -- 2.39.2