Lines 187-193
subtest '_split_query() tests' => sub {
Link Here
|
187 |
}; |
187 |
}; |
188 |
|
188 |
|
189 |
subtest '_clean_search_term() tests' => sub { |
189 |
subtest '_clean_search_term() tests' => sub { |
190 |
plan tests => 12; |
190 |
plan tests => 24; |
191 |
|
191 |
|
192 |
my $qb; |
192 |
my $qb; |
193 |
ok( |
193 |
ok( |
Lines 195-200
subtest '_clean_search_term() tests' => sub {
Link Here
|
195 |
'Creating a new QueryBuilder object' |
195 |
'Creating a new QueryBuilder object' |
196 |
); |
196 |
); |
197 |
|
197 |
|
|
|
198 |
t::lib::Mocks::mock_preference('QueryAutoTruncate', 0); |
199 |
|
198 |
my $res = $qb->_clean_search_term('an=123'); |
200 |
my $res = $qb->_clean_search_term('an=123'); |
199 |
is($res, 'koha-auth-number:123', 'equals sign replaced with colon'); |
201 |
is($res, 'koha-auth-number:123', 'equals sign replaced with colon'); |
200 |
|
202 |
|
Lines 207-232
subtest '_clean_search_term() tests' => sub {
Link Here
|
207 |
$res = $qb->_clean_search_term('"unbalanced "quotes"'); |
209 |
$res = $qb->_clean_search_term('"unbalanced "quotes"'); |
208 |
is($res, ' unbalanced quotes ', 'unbalanced quotes removed'); |
210 |
is($res, ' unbalanced quotes ', 'unbalanced quotes removed'); |
209 |
|
211 |
|
|
|
212 |
$res = $qb->_clean_search_term(':test query'); |
213 |
is($res, 'test query', 'remove colon at the start'); |
214 |
|
215 |
$res = $qb->_clean_search_term('test query\:'); |
216 |
is($res, 'test query', 'remove colon at the end'); |
217 |
|
210 |
$res = $qb->_clean_search_term('test : query'); |
218 |
$res = $qb->_clean_search_term('test : query'); |
211 |
is($res, 'test query', 'dangling colon removed'); |
219 |
is($res, 'test query', 'dangling colon removed'); |
212 |
|
220 |
|
213 |
$res = $qb->_clean_search_term('test :: query'); |
221 |
$res = $qb->_clean_search_term('test :: query'); |
214 |
is($res, 'test query', 'dangling double colon removed'); |
222 |
is($res, 'test query', 'dangling double colon removed'); |
215 |
|
223 |
|
216 |
$res = $qb->_clean_search_term('test "another : query"'); |
224 |
$res = $qb->_clean_search_term('test "another : query"'); |
217 |
is($res, 'test "another : query"', 'quoted dangling colon not removed'); |
225 |
is($res, 'test "another : query"', 'quoted dangling colon not removed'); |
218 |
|
226 |
|
219 |
$res = $qb->_clean_search_term('test {another part}'); |
227 |
$res = $qb->_clean_search_term('host-item:test:n'); |
220 |
is($res, 'test "another part"', 'curly brackets replaced correctly'); |
228 |
is($res, 'host-item:test\:n', 'screen colons properly'); |
|
|
229 |
|
230 |
$res = $qb->_clean_search_term('host-item:test:n:test:and more'); |
231 |
is($res, 'host-item:test\:n\:test\:and more', 'screen multiple colons properly'); |
232 |
|
233 |
$res = $qb->_clean_search_term('host-item:te st:n'); |
234 |
is($res, 'host-item:te st:n', 'leave colons as they are'); |
235 |
|
236 |
$res = $qb->_clean_search_term('test!'); |
237 |
is($res, 'test', 'remove exclamation sign at the end of the line'); |
238 |
|
239 |
$res = $qb->_clean_search_term('test! and more'); |
240 |
is($res, 'test and more', 'remove exclamation sign at with space after it'); |
241 |
|
242 |
$res = $qb->_clean_search_term('!test'); |
243 |
is($res, '!test', 'exclamation sign left untouched'); |
244 |
|
245 |
$res = $qb->_clean_search_term('test [123 TO 345]'); |
246 |
is($res, 'test [123 TO 345]', 'keep inculsive range untouched'); |
247 |
|
248 |
$res = $qb->_clean_search_term('test [test TO TEST} [and] {123 TO 456]'); |
249 |
is($res, 'test [test TO TEST} \[and\] {123 TO 456]', 'keep exclusive range untouched'); |
250 |
|
251 |
$res = $qb->_clean_search_term('test [test TO TEST} ["[and] {123 TO 456]" "[balanced]"]'); |
252 |
is($res, 'test [test TO TEST} \["[and] {123 TO 456]" "[balanced]"\]', 'keep exclusive range untouched'); |
253 |
|
254 |
$res = $qb->_clean_search_term('test[]test TO TEST] [ {123 to 345}}'); |
255 |
is($res, 'test\[\]test TO TEST\] \[ \{123 to 345\}\}', 'screen all square and curly brackets'); |
256 |
|
257 |
t::lib::Mocks::mock_preference('QueryRegexEscapeOptions', 'escape'); |
258 |
|
259 |
$res = $qb->_clean_search_term('test inside regexps /this [a-z]/ and \/not [a-z]\/ and that [a-z] [a TO z]'); |
260 |
is($res, 'test inside regexps \/this \[a-z\]\/ and \/not \[a-z\]\/ and that \[a-z\] [a TO z]', 'behaviour with QueryRegexEscapeOptions set to "escape"'); |
261 |
|
262 |
t::lib::Mocks::mock_preference('QueryRegexEscapeOptions', 'dont_escape'); |
221 |
|
263 |
|
222 |
$res = $qb->_clean_search_term('test {another part'); |
264 |
$res = $qb->_clean_search_term('test inside regexps /this [a-z]/ /this2 [a-z]/ [but] /this3 [a-z]/ and \/not [a-z]\/ and that [a-z] [a TO z]'); |
223 |
is($res, 'test another part', 'unbalanced curly brackets replaced correctly'); |
265 |
is($res, 'test inside regexps /this [a-z]/ /this2 [a-z]/ \[but\] /this3 [a-z]/ and \/not \[a-z\]\/ and that \[a-z\] [a TO z]', 'behaviour with QueryRegexEscapeOptions set to "dont_escape"'); |
224 |
|
266 |
|
225 |
$res = $qb->_clean_search_term('ti:test AND kw:test'); |
267 |
$res = $qb->_clean_search_term('ti:test AND kw:test'); |
226 |
is($res, 'title:test AND test', 'ti converted to title, kw converted to empty string, dangling colon removed with space preserved'); |
268 |
is($res, 'title:test AND test', 'ti converted to title, kw converted to empty string, dangling colon removed with space preserved'); |
227 |
|
269 |
|
228 |
$res = $qb->_clean_search_term('kw:test'); |
270 |
$res = $qb->_clean_search_term('kw:test'); |
229 |
is($res, 'test', 'kw converted to empty string, dangling colon removed with space preserved'); |
271 |
is($res, 'test', 'kw converted to empty string, dangling colon is removed'); |
230 |
}; |
272 |
}; |
231 |
|
273 |
|
232 |
subtest '_join_queries' => sub { |
274 |
subtest '_join_queries' => sub { |
233 |
- |
|
|