Bug 18374: (QA follow-up) Tidy up code
[koha-ffzg.git] / t / db_dependent / Koha_SearchEngine_Elasticsearch_Search.t
index 8afa74b..f547fcb 100644 (file)
@@ -102,18 +102,38 @@ subtest 'build_query tests' => sub {
     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', '' );
 
-    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" );
+    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"
+    );
+
+    # Ensure reserved words are not truncated
+    ( 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"
+    );
+
+    ( 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"
+    );
 };