|
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 => 3; |
| 21 |
|
| 22 |
BEGIN { |
| 23 |
use_ok('C4::Search'); |
| 24 |
can_ok('C4::Search', |
| 25 |
qw/_build_initial_query/); |
| 26 |
} |
| 27 |
|
| 28 |
subtest "_build_initial_query tests" => sub { |
| 29 |
|
| 30 |
plan tests => 20; |
| 31 |
|
| 32 |
my ($query,$query_cgi,$query_desc,$previous_operand); |
| 33 |
# all params have values |
| 34 |
my $params = { |
| 35 |
query => "query", |
| 36 |
query_cgi => "query_cgi", |
| 37 |
query_desc => "query_desc", |
| 38 |
operator => "operator", |
| 39 |
parsed_operand => "parsed_operand", |
| 40 |
original_operand => "original_operand", |
| 41 |
index => "index", |
| 42 |
index_plus => "index_plus", |
| 43 |
indexes_set => "indexes_set", |
| 44 |
previous_operand => "previous_operand" |
| 45 |
}; |
| 46 |
|
| 47 |
($query,$query_cgi,$query_desc,$previous_operand) = |
| 48 |
C4::Search::_build_initial_query($params); |
| 49 |
is( $query, "query operator parsed_operand", |
| 50 |
"\$query built correctly"); |
| 51 |
is( $query_cgi, "query_cgi&op=%20operator%20&idx=index&q=original_operand", |
| 52 |
"\$query_cgi built correctly"); |
| 53 |
is( $query_desc, "query_desc operator index_plus original_operand", |
| 54 |
"\$query_desc build correctly"); |
| 55 |
is( $previous_operand, "previous_operand", |
| 56 |
"\$query build correctly"); |
| 57 |
|
| 58 |
# no operator |
| 59 |
$params = { |
| 60 |
query => "query", |
| 61 |
query_cgi => "query_cgi", |
| 62 |
query_desc => "query_desc", |
| 63 |
operator => undef, |
| 64 |
parsed_operand => "parsed_operand", |
| 65 |
original_operand => "original_operand", |
| 66 |
index => "index", |
| 67 |
index_plus => "index_plus", |
| 68 |
indexes_set => "indexes_set", |
| 69 |
previous_operand => "previous_operand" |
| 70 |
}; |
| 71 |
|
| 72 |
($query,$query_cgi,$query_desc,$previous_operand) = |
| 73 |
C4::Search::_build_initial_query($params); |
| 74 |
is( $query, "query and parsed_operand", |
| 75 |
"\$query built correctly (no operator)"); |
| 76 |
is( $query_cgi, "query_cgi&op=%20and%20&idx=index&q=original_operand", |
| 77 |
"\$query_cgi built correctly (no operator)"); |
| 78 |
is( $query_desc, "query_desc and index_plus original_operand", |
| 79 |
"\$query_desc build correctly (no operator)"); |
| 80 |
is( $previous_operand, "previous_operand", |
| 81 |
"\$query build correctly (no operator)"); |
| 82 |
|
| 83 |
# no previous operand |
| 84 |
$params = { |
| 85 |
query => "query", |
| 86 |
query_cgi => "query_cgi", |
| 87 |
query_desc => "query_desc", |
| 88 |
operator => "operator", |
| 89 |
parsed_operand => "parsed_operand", |
| 90 |
original_operand => "original_operand", |
| 91 |
index => "index", |
| 92 |
index_plus => "index_plus", |
| 93 |
indexes_set => "indexes_set", |
| 94 |
previous_operand => undef |
| 95 |
}; |
| 96 |
|
| 97 |
($query,$query_cgi,$query_desc,$previous_operand) = |
| 98 |
C4::Search::_build_initial_query($params); |
| 99 |
is( $query, "queryparsed_operand", |
| 100 |
"\$query built correctly (no previous operand)"); |
| 101 |
is( $query_cgi, "query_cgi&idx=index&q=original_operand", |
| 102 |
"\$query_cgi built correctly (no previous operand)"); |
| 103 |
is( $query_desc, "query_descindex_plus original_operand", |
| 104 |
"\$query_desc build correctly (no previous operand)"); |
| 105 |
is( $previous_operand, 1, |
| 106 |
"\$query build correctly (no previous operand)"); |
| 107 |
|
| 108 |
# no index passed |
| 109 |
$params = { |
| 110 |
query => "query", |
| 111 |
query_cgi => "query_cgi", |
| 112 |
query_desc => "query_desc", |
| 113 |
operator => "operator", |
| 114 |
parsed_operand => "parsed_operand", |
| 115 |
original_operand => "original_operand", |
| 116 |
index => undef, |
| 117 |
index_plus => "index_plus", |
| 118 |
indexes_set => "indexes_set", |
| 119 |
previous_operand => "previous_operand" |
| 120 |
}; |
| 121 |
|
| 122 |
($query,$query_cgi,$query_desc,$previous_operand) = |
| 123 |
C4::Search::_build_initial_query($params); |
| 124 |
is( $query, "query operator parsed_operand", |
| 125 |
"\$query built correctly (no index passed)"); |
| 126 |
is( $query_cgi, "query_cgi&op=%20operator%20&q=original_operand", |
| 127 |
"\$query_cgi built correctly (no index passed)"); |
| 128 |
is( $query_desc, "query_desc operator index_plus original_operand", |
| 129 |
"\$query_desc build correctly (no index passed)"); |
| 130 |
is( $previous_operand, "previous_operand", |
| 131 |
"\$query build correctly (no index passed)"); |
| 132 |
|
| 133 |
# no index_plus passed |
| 134 |
$params = { |
| 135 |
query => "query", |
| 136 |
query_cgi => "query_cgi", |
| 137 |
query_desc => "query_desc", |
| 138 |
operator => "operator", |
| 139 |
parsed_operand => "parsed_operand", |
| 140 |
original_operand => "original_operand", |
| 141 |
index => "index", |
| 142 |
index_plus => undef, |
| 143 |
indexes_set => "indexes_set", |
| 144 |
previous_operand => "previous_operand" |
| 145 |
}; |
| 146 |
|
| 147 |
($query,$query_cgi,$query_desc,$previous_operand) = |
| 148 |
C4::Search::_build_initial_query($params); |
| 149 |
is( $query, "query operator parsed_operand", |
| 150 |
"\$query built correctly (no index_plus passed)"); |
| 151 |
is( $query_cgi, "query_cgi&op=%20operator%20&idx=index&q=original_operand", |
| 152 |
"\$query_cgi built correctly (no index_plus passed)"); |
| 153 |
is( $query_desc, "query_desc operator original_operand", |
| 154 |
"\$query_desc build correctly (no index_plus passed)"); |
| 155 |
is( $previous_operand, "previous_operand", |
| 156 |
"\$query build correctly (no index_plus passed)"); |
| 157 |
|
| 158 |
}; |
| 159 |
|
| 160 |
|
| 161 |
1; |