Bug 18374: QueryAutoTruncate unit tests
authorNick Clemens <nick@bywatersolutions.com>
Thu, 6 Apr 2017 18:27:50 +0000 (14:27 -0400)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 13 Oct 2017 16:01:12 +0000 (13:01 -0300)
To test:
1 - Apply just this patch - should fail
2 - Apply the other patch - should pass

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t

index 5c37200..8afa74b 100644 (file)
@@ -81,7 +81,7 @@ subtest 'json2marc' => sub {
 };
 
 subtest 'build_query tests' => sub {
-    plan tests => 6;
+    plan tests => 10;
 
     t::lib::Mocks::mock_preference('DisplayLibraryFacets','both');
     my $query = $builder->build_query();
@@ -101,5 +101,19 @@ subtest 'build_query tests' => sub {
         'homebranch added to facets if DisplayLibraryFacets=home' );
     ok( !defined $query->{aggregations}{holdingbranch},
         'holdingbranch not added to facets if DisplayLibraryFacets=home' );
+
+    t::lib::Mocks::mock_preference('QueryAutoTruncate','');
+    ( undef, $query ) = $builder->build_query_compat( undef, ['donald duck'] );
+    is( $query->{query}{query_string}{query}, "(donald duck)", "query not altered if QueryAutoTruncate disabled" );
+
+    t::lib::Mocks::mock_preference('QueryAutoTruncate','1');
+    ( undef, $query ) = $builder->build_query_compat( undef, ['donald duck'] );
+    is( $query->{query}{query_string}{query}, "(donald* duck*)", "simple query is auto truncated when QueryAutoTruncate enabled" );
+    ( undef, $query ) = $builder->build_query_compat( undef, ['donald or duck and mickey not mouse'] );
+    is( $query->{query}{query_string}{query}, "(donald* or duck* and mickey* not mouse*)", "reserved words are not affected by QueryAutoTruncate" ); #Ensure reserved words are not truncated
+    ( undef, $query ) = $builder->build_query_compat( undef, ['donald* duck*'] );
+    is( $query->{query}{query_string}{query}, "(donald* duck*)", "query with '*' is unaltered when QueryAutoTruncate is enabled" );
+
+
 };