Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
# |
3 |
# This file is part of Koha. |
4 |
# |
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. |
9 |
# |
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. |
14 |
# |
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>. |
17 |
|
18 |
use Modern::Perl; |
19 |
|
20 |
use Test::More tests => 3; |
21 |
use Test::MockModule; |
22 |
|
23 |
use_ok('Koha::SearchEngine::Zebra::QueryBuilder'); |
24 |
|
25 |
subtest 'build_authorities_query' => sub { |
26 |
plan tests => 2; |
27 |
|
28 |
my @test_search = ( |
29 |
['mainmainentry'], ['and'], [''], ['contains'], ['any'], '', |
30 |
'HeadingAsc' |
31 |
); |
32 |
my $expected_result = { |
33 |
marclist => ['mainmainentry'], |
34 |
and_or => ['and'], |
35 |
excluding => [''], |
36 |
operator => ['contains'], |
37 |
value => ['any'], |
38 |
authtypecode => '', |
39 |
orderby => 'HeadingAsc', |
40 |
}; |
41 |
my $built_search = |
42 |
Koha::SearchEngine::Zebra::QueryBuilder->build_authorities_query( @test_search ); |
43 |
is_deeply( |
44 |
$built_search, $expected_result, |
45 |
"We are simply hashifying our array of refs/values, should otherwise not be altered" |
46 |
); |
47 |
$expected_result->{value} = ['"any"']; |
48 |
$test_search[4] = ['"any"']; |
49 |
$built_search = |
50 |
Koha::SearchEngine::Zebra::QueryBuilder->build_authorities_query( @test_search ); |
51 |
is_deeply( |
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" |
54 |
); |
55 |
}; |
56 |
|
57 |
subtest 'build_query_compat() tests' => sub { |
58 |
|
59 |
plan tests => 4; |
60 |
|
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(); |
64 |
my $query; |
65 |
|
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'); |
68 |
|
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'); |
71 |
|
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)'); |
75 |
|
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)'); |
78 |
}; |