Bug 19469: Remove use of Dumper on request.tt
[koha.git] / t / Search.t
blob0959c85de0574fe3ee45e81919299ad93174d0f5
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;
21 use t::lib::Mocks;
23 use Module::Load::Conditional qw/check_install/;
25 BEGIN {
26 if ( check_install( module => 'Test::DBIx::Class' ) ) {
27 plan tests => 3;
28 } else {
29 plan skip_all => "Need Test::DBIx::Class"
33 # Mock the DB connexion and C4::Context
34 use Test::DBIx::Class;
36 use_ok('C4::Search');
37 can_ok('C4::Search',
38 qw/_build_initial_query/);
40 subtest "_build_initial_query tests" => sub {
42 plan tests => 20;
44 my ($query,$query_cgi,$query_desc,$previous_operand);
45 # all params have values
46 my $params = {
47 query => "query",
48 query_cgi => "query_cgi",
49 query_desc => "query_desc",
50 operator => "operator",
51 parsed_operand => "parsed_operand",
52 original_operand => "original_operand",
53 index => "index",
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");
70 # no operator
71 $params = {
72 query => "query",
73 query_cgi => "query_cgi",
74 query_desc => "query_desc",
75 operator => undef,
76 parsed_operand => "parsed_operand",
77 original_operand => "original_operand",
78 index => "index",
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)");
95 # no previous operand
96 $params = {
97 query => "query",
98 query_cgi => "query_cgi",
99 query_desc => "query_desc",
100 operator => "operator",
101 parsed_operand => "parsed_operand",
102 original_operand => "original_operand",
103 index => "index",
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)");
120 # no index passed
121 $params = {
122 query => "query",
123 query_cgi => "query_cgi",
124 query_desc => "query_desc",
125 operator => "operator",
126 parsed_operand => "parsed_operand",
127 original_operand => "original_operand",
128 index => undef,
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
146 $params = {
147 query => "query",
148 query_cgi => "query_cgi",
149 query_desc => "query_desc",
150 operator => "operator",
151 parsed_operand => "parsed_operand",
152 original_operand => "original_operand",
153 index => "index",
154 index_plus => undef,
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)");