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>.
23 use Module
::Load
::Conditional qw
/check_install/;
26 if ( check_install
( module
=> 'Test::DBIx::Class' ) ) {
29 plan skip_all
=> "Need Test::DBIx::Class"
33 # Mock the DB connexion and C4::Context
34 use Test
::DBIx
::Class
;
38 qw
/_build_initial_query/);
40 subtest
"_build_initial_query tests" => sub {
44 my ($query,$query_cgi,$query_desc,$previous_operand);
45 # all params have values
48 query_cgi
=> "query_cgi",
49 query_desc
=> "query_desc",
50 operator
=> "operator",
51 parsed_operand
=> "parsed_operand",
52 original_operand
=> "original_operand",
54 index_plus
=> "index_plus",
55 indexes_set
=> "indexes_set",
56 previous_operand
=> "previous_operand"
59 ($query,$query_cgi,$query_desc,$previous_operand) =
60 C4
::Search
::_build_initial_query
($params);
61 is
( $query, "query operator parsed_operand",
62 "\$query built correctly");
63 is
( $query_cgi, "query_cgi&op=%20operator%20&idx=index&q=original_operand",
64 "\$query_cgi built correctly");
65 is
( $query_desc, "query_desc operator index_plus original_operand",
66 "\$query_desc build correctly");
67 is
( $previous_operand, "previous_operand",
68 "\$query build correctly");
73 query_cgi
=> "query_cgi",
74 query_desc
=> "query_desc",
76 parsed_operand
=> "parsed_operand",
77 original_operand
=> "original_operand",
79 index_plus
=> "index_plus",
80 indexes_set
=> "indexes_set",
81 previous_operand
=> "previous_operand"
84 ($query,$query_cgi,$query_desc,$previous_operand) =
85 C4
::Search
::_build_initial_query
($params);
86 is
( $query, "query and parsed_operand",
87 "\$query built correctly (no operator)");
88 is
( $query_cgi, "query_cgi&op=%20and%20&idx=index&q=original_operand",
89 "\$query_cgi built correctly (no operator)");
90 is
( $query_desc, "query_desc and index_plus original_operand",
91 "\$query_desc build correctly (no operator)");
92 is
( $previous_operand, "previous_operand",
93 "\$query build correctly (no operator)");
98 query_cgi
=> "query_cgi",
99 query_desc
=> "query_desc",
100 operator
=> "operator",
101 parsed_operand
=> "parsed_operand",
102 original_operand
=> "original_operand",
104 index_plus
=> "index_plus",
105 indexes_set
=> "indexes_set",
106 previous_operand
=> undef
109 ($query,$query_cgi,$query_desc,$previous_operand) =
110 C4
::Search
::_build_initial_query
($params);
111 is
( $query, "queryparsed_operand",
112 "\$query built correctly (no previous operand)");
113 is
( $query_cgi, "query_cgi&idx=index&q=original_operand",
114 "\$query_cgi built correctly (no previous operand)");
115 is
( $query_desc, "query_descindex_plus original_operand",
116 "\$query_desc build correctly (no previous operand)");
117 is
( $previous_operand, 1,
118 "\$query build correctly (no previous operand)");
123 query_cgi
=> "query_cgi",
124 query_desc
=> "query_desc",
125 operator
=> "operator",
126 parsed_operand
=> "parsed_operand",
127 original_operand
=> "original_operand",
129 index_plus
=> "index_plus",
130 indexes_set
=> "indexes_set",
131 previous_operand
=> "previous_operand"
134 ($query,$query_cgi,$query_desc,$previous_operand) =
135 C4
::Search
::_build_initial_query
($params);
136 is
( $query, "query operator parsed_operand",
137 "\$query built correctly (no index passed)");
138 is
( $query_cgi, "query_cgi&op=%20operator%20&q=original_operand",
139 "\$query_cgi built correctly (no index passed)");
140 is
( $query_desc, "query_desc operator index_plus original_operand",
141 "\$query_desc build correctly (no index passed)");
142 is
( $previous_operand, "previous_operand",
143 "\$query build correctly (no index passed)");
145 # no index_plus passed
148 query_cgi
=> "query_cgi",
149 query_desc
=> "query_desc",
150 operator
=> "operator",
151 parsed_operand
=> "parsed_operand",
152 original_operand
=> "original_operand",
155 indexes_set
=> "indexes_set",
156 previous_operand
=> "previous_operand"
159 ($query,$query_cgi,$query_desc,$previous_operand) =
160 C4
::Search
::_build_initial_query
($params);
161 is
( $query, "query operator parsed_operand",
162 "\$query built correctly (no index_plus passed)");
163 is
( $query_cgi, "query_cgi&op=%20operator%20&idx=index&q=original_operand",
164 "\$query_cgi built correctly (no index_plus passed)");
165 is
( $query_desc, "query_desc operator original_operand",
166 "\$query_desc build correctly (no index_plus passed)");
167 is
( $previous_operand, "previous_operand",
168 "\$query build correctly (no index_plus passed)");