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>.
20 use Test::More tests => 3;
24 # Mock the DB connexion and C4::Context
25 my $context = new Test::MockModule('C4::Context');
26 $context->mock( '_new_dbh', sub {
27 my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
28 || die "Cannot create handle: $DBI::errstr\n";
34 qw/_build_initial_query/);
36 subtest "_build_initial_query tests" => sub {
40 my ($query,$query_cgi,$query_desc,$previous_operand);
41 # all params have values
44 query_cgi => "query_cgi",
45 query_desc => "query_desc",
46 operator => "operator",
47 parsed_operand => "parsed_operand",
48 original_operand => "original_operand",
50 index_plus => "index_plus",
51 indexes_set => "indexes_set",
52 previous_operand => "previous_operand"
55 ($query,$query_cgi,$query_desc,$previous_operand) =
56 C4::Search::_build_initial_query($params);
57 is( $query, "query operator parsed_operand",
58 "\$query built correctly");
59 is( $query_cgi, "query_cgi&op=%20operator%20&idx=index&q=original_operand",
60 "\$query_cgi built correctly");
61 is( $query_desc, "query_desc operator index_plus original_operand",
62 "\$query_desc build correctly");
63 is( $previous_operand, "previous_operand",
64 "\$query build correctly");
69 query_cgi => "query_cgi",
70 query_desc => "query_desc",
72 parsed_operand => "parsed_operand",
73 original_operand => "original_operand",
75 index_plus => "index_plus",
76 indexes_set => "indexes_set",
77 previous_operand => "previous_operand"
80 ($query,$query_cgi,$query_desc,$previous_operand) =
81 C4::Search::_build_initial_query($params);
82 is( $query, "query and parsed_operand",
83 "\$query built correctly (no operator)");
84 is( $query_cgi, "query_cgi&op=%20and%20&idx=index&q=original_operand",
85 "\$query_cgi built correctly (no operator)");
86 is( $query_desc, "query_desc and index_plus original_operand",
87 "\$query_desc build correctly (no operator)");
88 is( $previous_operand, "previous_operand",
89 "\$query build correctly (no operator)");
94 query_cgi => "query_cgi",
95 query_desc => "query_desc",
96 operator => "operator",
97 parsed_operand => "parsed_operand",
98 original_operand => "original_operand",
100 index_plus => "index_plus",
101 indexes_set => "indexes_set",
102 previous_operand => undef
105 ($query,$query_cgi,$query_desc,$previous_operand) =
106 C4::Search::_build_initial_query($params);
107 is( $query, "queryparsed_operand",
108 "\$query built correctly (no previous operand)");
109 is( $query_cgi, "query_cgi&idx=index&q=original_operand",
110 "\$query_cgi built correctly (no previous operand)");
111 is( $query_desc, "query_descindex_plus original_operand",
112 "\$query_desc build correctly (no previous operand)");
113 is( $previous_operand, 1,
114 "\$query build correctly (no previous operand)");
119 query_cgi => "query_cgi",
120 query_desc => "query_desc",
121 operator => "operator",
122 parsed_operand => "parsed_operand",
123 original_operand => "original_operand",
125 index_plus => "index_plus",
126 indexes_set => "indexes_set",
127 previous_operand => "previous_operand"
130 ($query,$query_cgi,$query_desc,$previous_operand) =
131 C4::Search::_build_initial_query($params);
132 is( $query, "query operator parsed_operand",
133 "\$query built correctly (no index passed)");
134 is( $query_cgi, "query_cgi&op=%20operator%20&q=original_operand",
135 "\$query_cgi built correctly (no index passed)");
136 is( $query_desc, "query_desc operator index_plus original_operand",
137 "\$query_desc build correctly (no index passed)");
138 is( $previous_operand, "previous_operand",
139 "\$query build correctly (no index passed)");
141 # no index_plus passed
144 query_cgi => "query_cgi",
145 query_desc => "query_desc",
146 operator => "operator",
147 parsed_operand => "parsed_operand",
148 original_operand => "original_operand",
151 indexes_set => "indexes_set",
152 previous_operand => "previous_operand"
155 ($query,$query_cgi,$query_desc,$previous_operand) =
156 C4::Search::_build_initial_query($params);
157 is( $query, "query operator parsed_operand",
158 "\$query built correctly (no index_plus passed)");
159 is( $query_cgi, "query_cgi&op=%20operator%20&idx=index&q=original_operand",
160 "\$query_cgi built correctly (no index_plus passed)");
161 is( $query_desc, "query_desc operator original_operand",
162 "\$query_desc build correctly (no index_plus passed)");
163 is( $previous_operand, "previous_operand",
164 "\$query build correctly (no index_plus passed)");