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

(-)a/t/db_dependent/QueryParser.t (+70 lines)
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 => 7;
21
22
use File::Basename;
23
use C4::Context;
24
25
C4::Context->set_preference( "UseQueryParser", 1 );
26
my $QParser = C4::Context->queryparser();
27
28
# Check initialization correctly parsed the config file
29
ok( defined $QParser && ref($QParser) eq "Koha::QueryParser::Driver::PQF"
30
    , 'C4::Context successfully created a QP object' );
31
32
is( $QParser->search_class_count, 4,
33
    "Initialized 4 search classes" );
34
is( scalar(@{$QParser->search_fields()->{'keyword'}}), 111,
35
    "Correct number of search fields for 'keyword' class");
36
is( scalar(@{$QParser->search_fields()->{'author'}}), 5,
37
    "Correct number of search fields for 'author' class");
38
is( scalar(@{$QParser->search_fields()->{'subject'}}), 12,
39
    "Correct number of search fields for 'subject' class");
40
is( scalar(@{$QParser->search_fields()->{'title'}}), 5,
41
    "Correct number of search fields for 'title' class");
42
43
# Load C4::Context 4 times with different randomization seeds
44
$ENV{ PERL_PERTURB_KEYS } = "1";
45
my $hash_seed = "AB123";
46
my $default_search_class1 = get_default_search_class();
47
$hash_seed = "CD456";
48
my $default_search_class2 = get_default_search_class();
49
$hash_seed = "ABCDE";
50
my $default_search_class3 = get_default_search_class();
51
$hash_seed = "123456";
52
my $default_search_class4 = get_default_search_class();
53
54
ok( $default_search_class1 eq 'keyword' &&
55
    $default_search_class2 eq 'keyword' &&
56
    $default_search_class3 eq 'keyword' &&
57
    $default_search_class4 eq 'keyword',
58
    "C4::Context correctly sets the default search class to 'keyword' (Bug 12738)");
59
60
sub get_default_search_class {
61
    # get the default search class from a forked proccess
62
    # that just loads C4::Context
63
    $ENV{ PERL_HASH_SEED }    = $hash_seed;
64
    my $running_dir = dirname(__FILE__);
65
    my $default_search_class = qx/$running_dir\/default_search_class.pl/;
66
67
    return $default_search_class;
68
}
69
70
1;
(-)a/t/db_dependent/default_search_class.pl (-1 / +36 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
=head1 default_search_class.pl
21
22
The only purpose of this script is to load C4::Context and print
23
the default search class from the QueryParser object
24
25
=cut
26
27
use C4::Context;
28
29
C4::Context->set_preference("UseQueryParser","1");
30
31
my $QParser = C4::Context->queryparser();
32
my $default_search_class = $QParser->default_search_class();
33
34
print $default_search_class;
35
36
exit 0;

Return to bug 12738