Bugzilla – Attachment 68706 Details for
Bug 16660
Elasticsearch broken if OpacSuppression is activated
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16660: (followup) Unit tests
Bug-16660-followup-Unit-tests.patch (text/plain), 7.68 KB, created by
Kyle M Hall (khall)
on 2017-10-27 13:34:18 UTC
(
hide
)
Description:
Bug 16660: (followup) Unit tests
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2017-10-27 13:34:18 UTC
Size:
7.68 KB
patch
obsolete
>From efa5adb07f8fee6df066c1fea707c34b01c1dda1 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 20 Oct 2017 10:26:04 -0300 >Subject: [PATCH] Bug 16660: (followup) Unit tests > >This patch adds unit tests for the introduced changes in >build_query_compat. > >It removes a warning too. > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > Koha/SearchEngine/Zebra/QueryBuilder.pm | 2 +- > t/Koha/SearchEngine/Zebra/QueryBuilder.t | 78 ++++++++++++++++++++++ > t/Search/Zebra/QueryBuilder.t | 38 ----------- > .../Koha_SearchEngine_Elasticsearch_Search.t | 16 ++++- > 4 files changed, 94 insertions(+), 40 deletions(-) > create mode 100644 t/Koha/SearchEngine/Zebra/QueryBuilder.t > delete mode 100644 t/Search/Zebra/QueryBuilder.t > >diff --git a/Koha/SearchEngine/Zebra/QueryBuilder.pm b/Koha/SearchEngine/Zebra/QueryBuilder.pm >index 8021eff..2fc1e1a 100644 >--- a/Koha/SearchEngine/Zebra/QueryBuilder.pm >+++ b/Koha/SearchEngine/Zebra/QueryBuilder.pm >@@ -44,7 +44,7 @@ sub build_query_compat { > # > # add OPAC suppression - requires at least one item indexed with Suppress > if ($params->{suppress}) { >- if ( $query_type eq 'pqf' ) { >+ if ( defined $query_type and $query_type eq 'pqf' ) { > #$query = "($query) && -(suppress:1)"; #QP syntax > $query = '@not '.$query.' @attr 14=1 @attr 1=9011 1'; #PQF syntax > } else { >diff --git a/t/Koha/SearchEngine/Zebra/QueryBuilder.t b/t/Koha/SearchEngine/Zebra/QueryBuilder.t >new file mode 100644 >index 0000000..809eb3a >--- /dev/null >+++ b/t/Koha/SearchEngine/Zebra/QueryBuilder.t >@@ -0,0 +1,78 @@ >+#!/usr/bin/perl >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 3; >+use Test::MockModule; >+ >+use_ok('Koha::SearchEngine::Zebra::QueryBuilder'); >+ >+subtest 'build_authorities_query' => sub { >+ plan tests => 2; >+ >+ my @test_search = ( >+ ['mainmainentry'], ['and'], [''], ['contains'], ['any'], '', >+ 'HeadingAsc' >+ ); >+ my $expected_result = { >+ marclist => ['mainmainentry'], >+ and_or => ['and'], >+ excluding => [''], >+ operator => ['contains'], >+ value => ['any'], >+ authtypecode => '', >+ orderby => 'HeadingAsc', >+ }; >+ my $built_search = >+ Koha::SearchEngine::Zebra::QueryBuilder->build_authorities_query( @test_search ); >+ is_deeply( >+ $built_search, $expected_result, >+ "We are simply hashifying our array of refs/values, should otherwise not be altered" >+ ); >+ $expected_result->{value} = ['"any"']; >+ $test_search[4] = ['"any"']; >+ $built_search = >+ Koha::SearchEngine::Zebra::QueryBuilder->build_authorities_query( @test_search ); >+ is_deeply( >+ $built_search, $expected_result, >+ "The same should hold true if the search contains double quotes which will be escaped during searching by search_auth_compat subroutine" >+ ); >+}; >+ >+subtest 'build_query_compat() tests' => sub { >+ >+ plan tests => 4; >+ >+ my $search = Test::MockModule->new('C4::Search'); >+ $search->mock( 'buildQuery', sub { return ( 'error', 'query', 'simple_query', 'query_cgi', 'query_desc', 'limit', 'limit_cgi', 'limit_desc', 'query_type' ) } ); >+ my $qb = Koha::SearchEngine::Zebra::QueryBuilder->new(); >+ my $query; >+ >+ ( undef, $query ) = $qb->build_query_compat( undef, undef, undef, undef, undef, undef, undef, { suppress => 1 } ); >+ is( $query, '(query) not Suppress=1', 'Suppress part of the query added correctly'); >+ >+ ( undef, $query ) = $qb->build_query_compat( undef, undef, undef, undef, undef, undef, undef, { suppress => 0 } ); >+ is( $query, 'query', 'Suppress part of the query not added'); >+ >+ $search->mock( 'buildQuery', sub { return ( 'error', 'query', 'simple_query', 'query_cgi', 'query_desc', 'limit', 'limit_cgi', 'limit_desc', 'pqf' ) } ); >+ ( undef, $query ) = $qb->build_query_compat( undef, undef, undef, undef, undef, undef, undef, { suppress => 1 } ); >+ is( $query, '@not query @attr 14=1 @attr 1=9011 1', 'Suppress part of the query added correctly (PQF)'); >+ >+ ( undef, $query ) = $qb->build_query_compat( undef, undef, undef, undef, undef, undef, undef, { suppress => 0 } ); >+ is( $query, 'query', 'Suppress part of the query not added (PQF)'); >+}; >diff --git a/t/Search/Zebra/QueryBuilder.t b/t/Search/Zebra/QueryBuilder.t >deleted file mode 100644 >index f0608ec..0000000 >--- a/t/Search/Zebra/QueryBuilder.t >+++ /dev/null >@@ -1,38 +0,0 @@ >-#!/usr/bin/env perl >- >-use Modern::Perl; >- >-use Test::More tests => 2; >-use_ok('Koha::SearchEngine::Zebra::QueryBuilder'); >- >-subtest 'build_authorities_query' => sub { >- plan tests => 2; >- >- my @test_search = ( >- ['mainmainentry'], ['and'], [''], ['contains'], ['any'], '', >- 'HeadingAsc' >- ); >- my $expected_result = { >- marclist => ['mainmainentry'], >- and_or => ['and'], >- excluding => [''], >- operator => ['contains'], >- value => ['any'], >- authtypecode => '', >- orderby => 'HeadingAsc', >- }; >- my $built_search = >- Koha::SearchEngine::Zebra::QueryBuilder->build_authorities_query( @test_search ); >- is_deeply( >- $built_search, $expected_result, >- "We are simply hashifying our array of refs/values, should otherwise not be altered" >- ); >- $expected_result->{value} = ['"any"']; >- $test_search[4] = ['"any"']; >- $built_search = >- Koha::SearchEngine::Zebra::QueryBuilder->build_authorities_query( @test_search ); >- is_deeply( >- $built_search, $expected_result, >- "The same should hold true if the search contains double quotes which will be escaped during searching by search_auth_compat subroutine" >- ); >-}; >diff --git a/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t b/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t >index 74d5069..b96a8b3 100644 >--- a/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t >+++ b/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t >@@ -81,7 +81,7 @@ subtest 'json2marc' => sub { > }; > > subtest 'build_query tests' => sub { >- plan tests => 16; >+ plan tests => 18; > > t::lib::Mocks::mock_preference('DisplayLibraryFacets','both'); > my $query = $builder->build_query(); >@@ -178,5 +178,19 @@ subtest 'build_query tests' => sub { > '(title:"donald duck")', > "query of specific field is not truncated when surrouned by quotes" > ); >+ >+ ( undef, $query ) = $builder->build_query_compat( undef, ['title:"donald duck"'], undef, undef, undef, undef, undef, { suppress => 1 } ); >+ is( >+ $query->{query}{query_string}{query}, >+ '(title:"donald duck") AND suppress:0', >+ "query of specific field is added AND suppress:0" >+ ); >+ >+ ( undef, $query ) = $builder->build_query_compat( undef, ['title:"donald duck"'], undef, undef, undef, undef, undef, { suppress => 0 } ); >+ is( >+ $query->{query}{query_string}{query}, >+ '(title:"donald duck")', >+ "query of specific field is not added AND suppress:0" >+ ); > }; > >-- >2.10.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 16660
:
60727
|
68224
|
68280
|
68320
|
68321
|
68322
|
68704
|
68705
| 68706