View | Details | Raw Unified | Return to bug 28847
Collapse All | Expand All

(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t (-1 / +74 lines)
Lines 22-28 use Test::Exception; Link Here
22
use Test::Warn;
22
use Test::Warn;
23
use t::lib::Mocks;
23
use t::lib::Mocks;
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
use Test::More tests => 6;
25
use Test::More tests => 7;
26
26
27
use List::Util qw( all );
27
use List::Util qw( all );
28
28
Lines 690-695 subtest 'build_query with weighted fields tests' => sub { Link Here
690
690
691
};
691
};
692
692
693
subtest 'build_query_compat() SearchLimitLibrary tests' => sub {
694
695
    plan tests => 18;
696
697
    $schema->storage->txn_begin;
698
699
    my $builder = t::lib::TestBuilder->new;
700
701
    my $branch_1 = $builder->build_object({ class => 'Koha::Libraries' });
702
    my $branch_2 = $builder->build_object({ class => 'Koha::Libraries' });
703
    my $group    = $builder->build_object({ class => 'Koha::Library::Groups', value => {
704
            ft_search_groups_opac => 1,
705
            ft_search_groups_staff => 1,
706
            parent_id => undef,
707
            branchcode => undef
708
        }
709
    });
710
    my $group_1  = $builder->build_object({ class => 'Koha::Library::Groups', value => {
711
            parent_id => $group->id,
712
            branchcode => $branch_1->id
713
        }
714
    });
715
    my $group_2  = $builder->build_object({ class => 'Koha::Library::Groups', value => {
716
            parent_id => $group->id,
717
            branchcode => $branch_2->id
718
        }
719
    });
720
    my $groupid = $group->id;
721
    my @branchcodes = sort { $a cmp $b } ( $branch_1->id, $branch_2->id );
722
723
724
    my $query_builder = Koha::SearchEngine::Elasticsearch::QueryBuilder->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
725
    t::lib::Mocks::mock_preference('SearchLimitLibrary', 'both');
726
    diag(" SearchLimitLibrary set to 'both'");
727
    my ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) =
728
        $query_builder->build_query_compat( undef, undef, undef, [ "branch:CPL" ], undef, undef, undef, undef );
729
    is( $limit, "(homebranch: CPL OR holdingbranch: CPL)", "Branch limit expanded to home/holding branch");
730
    is( $limit_desc, "(homebranch: CPL OR holdingbranch: CPL)", "Limit description correctly expanded");
731
    is( $limit_cgi, "&limit=branch%3ACPL", "Limit cgi does not get expanded");
732
    ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) =
733
        $query_builder->build_query_compat( undef, undef, undef, [ "multibranchlimit:$groupid" ], undef, undef, undef, undef );
734
    is( $limit, "(homebranch: $branchcodes[0] OR homebranch: $branchcodes[1] OR holdingbranch: $branchcodes[0] OR holdingbranch: $branchcodes[1])", "Multibranch limit expanded to home/holding branches");
735
    is( $limit_desc, "(homebranch: $branchcodes[0] OR homebranch: $branchcodes[1] OR holdingbranch: $branchcodes[0] OR holdingbranch: $branchcodes[1])", "Multibranch limit description correctly expanded");
736
    is( $limit_cgi, "&limit=multibranchlimit%3A$groupid", "Multibranch limit cgi does not get expanded");
737
738
    t::lib::Mocks::mock_preference('SearchLimitLibrary', 'homebranch');
739
    diag(" SearchLimitLibrary set to 'homebranch'");
740
    ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) =
741
        $query_builder->build_query_compat( undef, undef, undef, [ "branch:CPL" ], undef, undef, undef, undef );
742
    is( $limit, "(homebranch: CPL)", "branch limit expanded to home branch");
743
    is( $limit_desc, "(homebranch: CPL)", "limit description correctly expanded");
744
    is( $limit_cgi, "&limit=branch%3ACPL", "limit cgi does not get expanded");
745
    ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) =
746
        $query_builder->build_query_compat( undef, undef, undef, [ "multibranchlimit:$groupid" ], undef, undef, undef, undef );
747
    is( $limit, "(homebranch: $branchcodes[0] OR homebranch: $branchcodes[1])", "branch limit expanded to home branch");
748
    is( $limit_desc, "(homebranch: $branchcodes[0] OR homebranch: $branchcodes[1])", "limit description correctly expanded");
749
    is( $limit_cgi, "&limit=multibranchlimit%3A$groupid", "Limit cgi does not get expanded");
750
751
    t::lib::Mocks::mock_preference('SearchLimitLibrary', 'holdingbranch');
752
    diag(" SearchLimitLibrary set to 'homebranch'");
753
    ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) =
754
        $query_builder->build_query_compat( undef, undef, undef, [ "branch:CPL" ], undef, undef, undef, undef );
755
    is( $limit, "(holdingbranch: CPL)", "branch limit expanded to holding branch");
756
    is( $limit_desc, "(holdingbranch: CPL)", "Limit description correctly expanded");
757
    is( $limit_cgi, "&limit=branch%3ACPL", "Limit cgi does not get expanded");
758
    ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) =
759
        $query_builder->build_query_compat( undef, undef, undef, [ "multibranchlimit:$groupid" ], undef, undef, undef, undef );
760
    is( $limit, "(holdingbranch: $branchcodes[0] OR holdingbranch: $branchcodes[1])", "branch limit expanded to holding branch");
761
    is( $limit_desc, "(holdingbranch: $branchcodes[0] OR holdingbranch: $branchcodes[1])", "Limit description correctly expanded");
762
    is( $limit_cgi, "&limit=multibranchlimit%3A$groupid", "Limit cgi does not get expanded");
763
764
};
765
693
subtest "_convert_sort_fields() tests" => sub {
766
subtest "_convert_sort_fields() tests" => sub {
694
    plan tests => 3;
767
    plan tests => 3;
695
768
(-)a/t/db_dependent/Koha/SearchEngine/Zebra/QueryBuilder.t (-1 / +101 lines)
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
};

Return to bug 28847