View | Details | Raw Unified | Return to bug 28316
Collapse All | Expand All

(-)a/t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t (-6 / +41 lines)
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 => 22;
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-212 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', 'colon at the start removed');
214
215
    $res = $qb->_clean_search_term('test query:');
216
    is($res, 'test query', 'colon at the end removed');
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
Lines 216-226 subtest '_clean_search_term() tests' => sub { Link Here
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 host-item:te st:n');
220
    is($res, 'test "another part"', 'curly brackets replaced correctly');
228
    is($res, 'host-item:test\:n host-item:te st:n', 'screen colons properly');
229
230
    $res = $qb->_clean_search_term('test!');
231
    is($res, 'test\!', 'escape exclamation sign at the end of the line');
232
233
    $res = $qb->_clean_search_term('test! and more');
234
    is($res, 'test\! and more', 'escape exclamation sign at with space after it');
235
236
    $res = $qb->_clean_search_term('!test');
237
    is($res, '!test', 'exclamation sign left untouched');
238
239
    $res = $qb->_clean_search_term('test [123 TO 345]');
240
    is($res, 'test [123 TO 345]', 'keep inculsive range untouched');
241
242
    $res = $qb->_clean_search_term('test [test TO TEST} [and] {123 TO 456]');
243
    is($res, 'test [test TO TEST} \[and\] {123 TO 456]', 'keep exclusive range untouched');
244
245
    $res = $qb->_clean_search_term('test [test TO TEST} ["[and] {123 TO 456]" "[balanced]"]');
246
    is($res, 'test [test TO TEST} \["[and] {123 TO 456]" "[balanced]"\]', 'keep exclusive range untouched');
247
248
    $res = $qb->_clean_search_term('test[]test TO TEST] [ {123 to 345}}');
249
    is($res, 'test\[\]test TO TEST\] \[ \{123 to 345\}\}', 'screen all square and curly brackets');
250
251
    t::lib::Mocks::mock_preference('QueryRegexEscapeOptions', 'escape');
252
253
    $res = $qb->_clean_search_term('test inside regexps /this [a-z]/ and \/not [a-z]\/ and that [a-z] [a TO z]');
254
    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"');
255
256
    t::lib::Mocks::mock_preference('QueryRegexEscapeOptions', 'dont_escape');
221
257
222
    $res = $qb->_clean_search_term('test {another part');
258
    $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');
259
    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
260
225
    $res = $qb->_clean_search_term('ti:test AND kw:test');
261
    $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');
262
    is($res, 'title:test AND test', 'ti converted to title, kw converted to empty string, dangling colon removed with space preserved');
227
- 

Return to bug 28316