Bug 21716: Escape publisher in item search
[koha.git] / t / db_dependent / QueryParser.t
blob58120d7dd20dff7f342eaa72297f70dcea20dcc9
1 #!/usr/bin/perl
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>.
18 use Modern::Perl;
20 use Test::More tests => 7;
22 use File::Basename;
23 use t::lib::Mocks;
24 use C4::Context;
26 t::lib::Mocks::mock_preference( "UseQueryParser", 1 );
27 my $QParser = C4::Context->queryparser();
29 # Check initialization correctly parsed the config file
30 ok( defined $QParser && ref($QParser) eq "Koha::QueryParser::Driver::PQF"
31 , 'C4::Context successfully created a QP object' );
33 is( $QParser->search_class_count, 4,
34 "Initialized 4 search classes" );
35 is( scalar(@{$QParser->search_fields()->{'keyword'}}), 111,
36 "Correct number of search fields for 'keyword' class");
37 is( scalar(@{$QParser->search_fields()->{'author'}}), 5,
38 "Correct number of search fields for 'author' class");
39 is( scalar(@{$QParser->search_fields()->{'subject'}}), 12,
40 "Correct number of search fields for 'subject' class");
41 is( scalar(@{$QParser->search_fields()->{'title'}}), 5,
42 "Correct number of search fields for 'title' class");
44 # Load C4::Context 4 times with different randomization seeds
45 $ENV{ PERL_PERTURB_KEYS } = "1";
46 my $hash_seed = "AB123";
47 my $default_search_class1 = get_default_search_class();
48 $hash_seed = "CD456";
49 my $default_search_class2 = get_default_search_class();
50 $hash_seed = "ABCDE";
51 my $default_search_class3 = get_default_search_class();
52 $hash_seed = "123456";
53 my $default_search_class4 = get_default_search_class();
55 ok( $default_search_class1 eq 'keyword' &&
56 $default_search_class2 eq 'keyword' &&
57 $default_search_class3 eq 'keyword' &&
58 $default_search_class4 eq 'keyword',
59 "C4::Context correctly sets the default search class to 'keyword' (Bug 12738)");
61 sub get_default_search_class {
62 # get the default search class from a forked proccess
63 # that just loads C4::Context
64 $ENV{ PERL_HASH_SEED } = $hash_seed;
65 my $running_dir = dirname(__FILE__);
66 my $default_search_class = qx/$running_dir\/default_search_class.pl/;
68 return $default_search_class;