forked from Koha-Community/Koha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearch.t
executable file
·163 lines (143 loc) · 5.97 KB
/
Search.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/perl
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 3;
use t::lib::Mocks;
# Mock the DB connexion and C4::Context
my $context = t::lib::Mocks::mock_dbh;
use_ok('C4::Search');
can_ok('C4::Search',
qw/_build_initial_query/);
subtest "_build_initial_query tests" => sub {
plan tests => 20;
my ($query,$query_cgi,$query_desc,$previous_operand);
# all params have values
my $params = {
query => "query",
query_cgi => "query_cgi",
query_desc => "query_desc",
operator => "operator",
parsed_operand => "parsed_operand",
original_operand => "original_operand",
index => "index",
index_plus => "index_plus",
indexes_set => "indexes_set",
previous_operand => "previous_operand"
};
($query,$query_cgi,$query_desc,$previous_operand) =
C4::Search::_build_initial_query($params);
is( $query, "query operator parsed_operand",
"\$query built correctly");
is( $query_cgi, "query_cgi&op=%20operator%20&idx=index&q=original_operand",
"\$query_cgi built correctly");
is( $query_desc, "query_desc operator index_plus original_operand",
"\$query_desc build correctly");
is( $previous_operand, "previous_operand",
"\$query build correctly");
# no operator
$params = {
query => "query",
query_cgi => "query_cgi",
query_desc => "query_desc",
operator => undef,
parsed_operand => "parsed_operand",
original_operand => "original_operand",
index => "index",
index_plus => "index_plus",
indexes_set => "indexes_set",
previous_operand => "previous_operand"
};
($query,$query_cgi,$query_desc,$previous_operand) =
C4::Search::_build_initial_query($params);
is( $query, "query and parsed_operand",
"\$query built correctly (no operator)");
is( $query_cgi, "query_cgi&op=%20and%20&idx=index&q=original_operand",
"\$query_cgi built correctly (no operator)");
is( $query_desc, "query_desc and index_plus original_operand",
"\$query_desc build correctly (no operator)");
is( $previous_operand, "previous_operand",
"\$query build correctly (no operator)");
# no previous operand
$params = {
query => "query",
query_cgi => "query_cgi",
query_desc => "query_desc",
operator => "operator",
parsed_operand => "parsed_operand",
original_operand => "original_operand",
index => "index",
index_plus => "index_plus",
indexes_set => "indexes_set",
previous_operand => undef
};
($query,$query_cgi,$query_desc,$previous_operand) =
C4::Search::_build_initial_query($params);
is( $query, "queryparsed_operand",
"\$query built correctly (no previous operand)");
is( $query_cgi, "query_cgi&idx=index&q=original_operand",
"\$query_cgi built correctly (no previous operand)");
is( $query_desc, "query_descindex_plus original_operand",
"\$query_desc build correctly (no previous operand)");
is( $previous_operand, 1,
"\$query build correctly (no previous operand)");
# no index passed
$params = {
query => "query",
query_cgi => "query_cgi",
query_desc => "query_desc",
operator => "operator",
parsed_operand => "parsed_operand",
original_operand => "original_operand",
index => undef,
index_plus => "index_plus",
indexes_set => "indexes_set",
previous_operand => "previous_operand"
};
($query,$query_cgi,$query_desc,$previous_operand) =
C4::Search::_build_initial_query($params);
is( $query, "query operator parsed_operand",
"\$query built correctly (no index passed)");
is( $query_cgi, "query_cgi&op=%20operator%20&q=original_operand",
"\$query_cgi built correctly (no index passed)");
is( $query_desc, "query_desc operator index_plus original_operand",
"\$query_desc build correctly (no index passed)");
is( $previous_operand, "previous_operand",
"\$query build correctly (no index passed)");
# no index_plus passed
$params = {
query => "query",
query_cgi => "query_cgi",
query_desc => "query_desc",
operator => "operator",
parsed_operand => "parsed_operand",
original_operand => "original_operand",
index => "index",
index_plus => undef,
indexes_set => "indexes_set",
previous_operand => "previous_operand"
};
($query,$query_cgi,$query_desc,$previous_operand) =
C4::Search::_build_initial_query($params);
is( $query, "query operator parsed_operand",
"\$query built correctly (no index_plus passed)");
is( $query_cgi, "query_cgi&op=%20operator%20&idx=index&q=original_operand",
"\$query_cgi built correctly (no index_plus passed)");
is( $query_desc, "query_desc operator original_operand",
"\$query_desc build correctly (no index_plus passed)");
is( $previous_operand, "previous_operand",
"\$query build correctly (no index_plus passed)");
};
1;