Bug 16699: Remove requirement from borrowernumberQueryParam
[koha.git] / t / Search.t
blob5618eadb72fe4e5c6a393bc72bee45670ca576df
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 => 3;
21 use t::lib::Mocks;
23 # Mock the DB connexion and C4::Context
24 my $context = t::lib::Mocks::mock_dbh;
26 use_ok('C4::Search');
27 can_ok('C4::Search',
28 qw/_build_initial_query/);
30 subtest "_build_initial_query tests" => sub {
32 plan tests => 20;
34 my ($query,$query_cgi,$query_desc,$previous_operand);
35 # all params have values
36 my $params = {
37 query => "query",
38 query_cgi => "query_cgi",
39 query_desc => "query_desc",
40 operator => "operator",
41 parsed_operand => "parsed_operand",
42 original_operand => "original_operand",
43 index => "index",
44 index_plus => "index_plus",
45 indexes_set => "indexes_set",
46 previous_operand => "previous_operand"
49 ($query,$query_cgi,$query_desc,$previous_operand) =
50 C4::Search::_build_initial_query($params);
51 is( $query, "query operator parsed_operand",
52 "\$query built correctly");
53 is( $query_cgi, "query_cgi&op=%20operator%20&idx=index&q=original_operand",
54 "\$query_cgi built correctly");
55 is( $query_desc, "query_desc operator index_plus original_operand",
56 "\$query_desc build correctly");
57 is( $previous_operand, "previous_operand",
58 "\$query build correctly");
60 # no operator
61 $params = {
62 query => "query",
63 query_cgi => "query_cgi",
64 query_desc => "query_desc",
65 operator => undef,
66 parsed_operand => "parsed_operand",
67 original_operand => "original_operand",
68 index => "index",
69 index_plus => "index_plus",
70 indexes_set => "indexes_set",
71 previous_operand => "previous_operand"
74 ($query,$query_cgi,$query_desc,$previous_operand) =
75 C4::Search::_build_initial_query($params);
76 is( $query, "query and parsed_operand",
77 "\$query built correctly (no operator)");
78 is( $query_cgi, "query_cgi&op=%20and%20&idx=index&q=original_operand",
79 "\$query_cgi built correctly (no operator)");
80 is( $query_desc, "query_desc and index_plus original_operand",
81 "\$query_desc build correctly (no operator)");
82 is( $previous_operand, "previous_operand",
83 "\$query build correctly (no operator)");
85 # no previous operand
86 $params = {
87 query => "query",
88 query_cgi => "query_cgi",
89 query_desc => "query_desc",
90 operator => "operator",
91 parsed_operand => "parsed_operand",
92 original_operand => "original_operand",
93 index => "index",
94 index_plus => "index_plus",
95 indexes_set => "indexes_set",
96 previous_operand => undef
99 ($query,$query_cgi,$query_desc,$previous_operand) =
100 C4::Search::_build_initial_query($params);
101 is( $query, "queryparsed_operand",
102 "\$query built correctly (no previous operand)");
103 is( $query_cgi, "query_cgi&idx=index&q=original_operand",
104 "\$query_cgi built correctly (no previous operand)");
105 is( $query_desc, "query_descindex_plus original_operand",
106 "\$query_desc build correctly (no previous operand)");
107 is( $previous_operand, 1,
108 "\$query build correctly (no previous operand)");
110 # no index passed
111 $params = {
112 query => "query",
113 query_cgi => "query_cgi",
114 query_desc => "query_desc",
115 operator => "operator",
116 parsed_operand => "parsed_operand",
117 original_operand => "original_operand",
118 index => undef,
119 index_plus => "index_plus",
120 indexes_set => "indexes_set",
121 previous_operand => "previous_operand"
124 ($query,$query_cgi,$query_desc,$previous_operand) =
125 C4::Search::_build_initial_query($params);
126 is( $query, "query operator parsed_operand",
127 "\$query built correctly (no index passed)");
128 is( $query_cgi, "query_cgi&op=%20operator%20&q=original_operand",
129 "\$query_cgi built correctly (no index passed)");
130 is( $query_desc, "query_desc operator index_plus original_operand",
131 "\$query_desc build correctly (no index passed)");
132 is( $previous_operand, "previous_operand",
133 "\$query build correctly (no index passed)");
135 # no index_plus passed
136 $params = {
137 query => "query",
138 query_cgi => "query_cgi",
139 query_desc => "query_desc",
140 operator => "operator",
141 parsed_operand => "parsed_operand",
142 original_operand => "original_operand",
143 index => "index",
144 index_plus => undef,
145 indexes_set => "indexes_set",
146 previous_operand => "previous_operand"
149 ($query,$query_cgi,$query_desc,$previous_operand) =
150 C4::Search::_build_initial_query($params);
151 is( $query, "query operator parsed_operand",
152 "\$query built correctly (no index_plus passed)");
153 is( $query_cgi, "query_cgi&op=%20operator%20&idx=index&q=original_operand",
154 "\$query_cgi built correctly (no index_plus passed)");
155 is( $query_desc, "query_desc operator original_operand",
156 "\$query_desc build correctly (no index_plus passed)");
157 is( $previous_operand, "previous_operand",
158 "\$query build correctly (no index_plus passed)");