3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test::More tests => 3;
23 use_ok('Koha::SearchEngine::Zebra::QueryBuilder');
25 subtest 'build_authorities_query' => sub {
29 ['mainmainentry'], ['and'], [''], ['contains'], ['any'], '',
32 my $expected_result = {
33 marclist => ['mainmainentry'],
36 operator => ['contains'],
39 orderby => 'HeadingAsc',
42 Koha::SearchEngine::Zebra::QueryBuilder->build_authorities_query( @test_search );
44 $built_search, $expected_result,
45 "We are simply hashifying our array of refs/values, should otherwise not be altered"
47 $expected_result->{value} = ['"any"'];
48 $test_search[4] = ['"any"'];
50 Koha::SearchEngine::Zebra::QueryBuilder->build_authorities_query( @test_search );
52 $built_search, $expected_result,
53 "The same should hold true if the search contains double quotes which will be escaped during searching by search_auth_compat subroutine"
57 subtest 'build_query_compat() tests' => sub {
61 my $search = Test::MockModule->new('C4::Search');
62 $search->mock( 'buildQuery', sub { return ( 'error', 'query', 'simple_query', 'query_cgi', 'query_desc', 'limit', 'limit_cgi', 'limit_desc', 'query_type' ) } );
63 my $qb = Koha::SearchEngine::Zebra::QueryBuilder->new();
66 ( undef, $query ) = $qb->build_query_compat( undef, undef, undef, undef, undef, undef, undef, { suppress => 1 } );
67 is( $query, '(query) not Suppress=1', 'Suppress part of the query added correctly');
69 ( undef, $query ) = $qb->build_query_compat( undef, undef, undef, undef, undef, undef, undef, { suppress => 0 } );
70 is( $query, 'query', 'Suppress part of the query not added');
72 $search->mock( 'buildQuery', sub { return ( 'error', 'query', 'simple_query', 'query_cgi', 'query_desc', 'limit', 'limit_cgi', 'limit_desc', 'pqf' ) } );
73 ( undef, $query ) = $qb->build_query_compat( undef, undef, undef, undef, undef, undef, undef, { suppress => 1 } );
74 is( $query, '@not query @attr 14=1 @attr 1=9011 1', 'Suppress part of the query added correctly (PQF)');
76 ( undef, $query ) = $qb->build_query_compat( undef, undef, undef, undef, undef, undef, undef, { suppress => 0 } );
77 is( $query, 'query', 'Suppress part of the query not added (PQF)');