Line 0
Link Here
|
0 |
- |
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 => 1; |
21 |
use t::lib::Mocks; |
22 |
use t::lib::TestBuilder; |
23 |
use Test::MockModule; |
24 |
|
25 |
use Koha::Database; |
26 |
use Koha::SearchEngine::Zebra::QueryBuilder; |
27 |
|
28 |
my $schema = Koha::Database->new->schema; |
29 |
|
30 |
subtest 'build_query_compat() SearchLimitLibrary tests' => sub { |
31 |
|
32 |
plan tests => 18; |
33 |
|
34 |
$schema->storage->txn_begin; |
35 |
|
36 |
my $builder = t::lib::TestBuilder->new; |
37 |
|
38 |
my $branch_1 = $builder->build_object({ class => 'Koha::Libraries' }); |
39 |
my $branch_2 = $builder->build_object({ class => 'Koha::Libraries' }); |
40 |
my $group = $builder->build_object({ class => 'Koha::Library::Groups', value => { |
41 |
ft_search_groups_opac => 1, |
42 |
ft_search_groups_staff => 1, |
43 |
parent_id => undef, |
44 |
branchcode => undef |
45 |
} |
46 |
}); |
47 |
my $group_1 = $builder->build_object({ class => 'Koha::Library::Groups', value => { |
48 |
parent_id => $group->id, |
49 |
branchcode => $branch_1->id |
50 |
} |
51 |
}); |
52 |
my $group_2 = $builder->build_object({ class => 'Koha::Library::Groups', value => { |
53 |
parent_id => $group->id, |
54 |
branchcode => $branch_2->id |
55 |
} |
56 |
}); |
57 |
my $groupid = $group->id; |
58 |
my @branchcodes = sort { $a cmp $b } ( $branch_1->id, $branch_2->id ); |
59 |
|
60 |
|
61 |
my $query_builder = Koha::SearchEngine::Zebra::QueryBuilder->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); |
62 |
t::lib::Mocks::mock_preference('SearchLimitLibrary', 'both'); |
63 |
diag(" SearchLimitLibrary set to 'both'"); |
64 |
my ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) = |
65 |
$query_builder->build_query_compat( undef, undef, undef, [ "branch:CPL" ], undef, undef, undef, undef ); |
66 |
is( $limit, "(homebranch= CPL or holdingbranch= CPL)", "Branch limit expanded to home/holding branch"); |
67 |
is( $limit_desc, "(homebranch: CPL or holdingbranch: CPL)", "Limit description correctly expanded"); |
68 |
is( $limit_cgi, "&limit=branch%3ACPL", "Limit cgi does not get expanded"); |
69 |
( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) = |
70 |
$query_builder->build_query_compat( undef, undef, undef, [ "multibranchlimit:$groupid" ], undef, undef, undef, undef ); |
71 |
is( $limit, "(homebranch= $branchcodes[0] or homebranch= $branchcodes[1] or holdingbranch= $branchcodes[0] or holdingbranch= $branchcodes[1])", "Multibranch limit expanded to home/holding branches"); |
72 |
is( $limit_desc, "(homebranch: $branchcodes[0] or homebranch: $branchcodes[1] or holdingbranch: $branchcodes[0] or holdingbranch: $branchcodes[1])", "Multibranch limit description correctly expanded"); |
73 |
is( $limit_cgi, "&limit=multibranchlimit%3A$groupid", "Multibranch limit cgi does not get expanded"); |
74 |
|
75 |
t::lib::Mocks::mock_preference('SearchLimitLibrary', 'homebranch'); |
76 |
diag(" SearchLimitLibrary set to 'homebranch'"); |
77 |
( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) = |
78 |
$query_builder->build_query_compat( undef, undef, undef, [ "branch:CPL" ], undef, undef, undef, undef ); |
79 |
is( $limit, "(homebranch= CPL)", "branch limit expanded to home branch"); |
80 |
is( $limit_desc, "(homebranch: CPL)", "limit description correctly expanded"); |
81 |
is( $limit_cgi, "&limit=branch%3ACPL", "limit cgi does not get expanded"); |
82 |
( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) = |
83 |
$query_builder->build_query_compat( undef, undef, undef, [ "multibranchlimit:$groupid" ], undef, undef, undef, undef ); |
84 |
is( $limit, "(homebranch= $branchcodes[0] or homebranch= $branchcodes[1])", "branch limit expanded to home branch"); |
85 |
is( $limit_desc, "(homebranch: $branchcodes[0] or homebranch: $branchcodes[1])", "limit description correctly expanded"); |
86 |
is( $limit_cgi, "&limit=multibranchlimit%3A$groupid", "Limit cgi does not get expanded"); |
87 |
|
88 |
t::lib::Mocks::mock_preference('SearchLimitLibrary', 'holdingbranch'); |
89 |
diag(" SearchLimitLibrary set to 'homebranch'"); |
90 |
( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) = |
91 |
$query_builder->build_query_compat( undef, undef, undef, [ "branch:CPL" ], undef, undef, undef, undef ); |
92 |
is( $limit, "(holdingbranch= CPL)", "branch limit expanded to holding branch"); |
93 |
is( $limit_desc, "(holdingbranch: CPL)", "Limit description correctly expanded"); |
94 |
is( $limit_cgi, "&limit=branch%3ACPL", "Limit cgi does not get expanded"); |
95 |
( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) = |
96 |
$query_builder->build_query_compat( undef, undef, undef, [ "multibranchlimit:$groupid" ], undef, undef, undef, undef ); |
97 |
is( $limit, "(holdingbranch= $branchcodes[0] or holdingbranch= $branchcodes[1])", "branch limit expanded to holding branch"); |
98 |
is( $limit_desc, "(holdingbranch: $branchcodes[0] or holdingbranch: $branchcodes[1])", "Limit description correctly expanded"); |
99 |
is( $limit_cgi, "&limit=multibranchlimit%3A$groupid", "Limit cgi does not get expanded"); |
100 |
|
101 |
}; |