Lines 19-30
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 6; |
22 |
use Test::More tests => 7; |
23 |
|
23 |
|
24 |
use Test::Exception; |
24 |
use Test::Exception; |
25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
26 |
|
26 |
|
27 |
use MARC::Field; |
27 |
use MARC::Field; |
|
|
28 |
use Mojo::JSON qw(encode_json); |
28 |
|
29 |
|
29 |
use C4::Items; |
30 |
use C4::Items; |
30 |
use C4::Biblio qw( AddBiblio ModBiblio GetMarcFromKohaField ); |
31 |
use C4::Biblio qw( AddBiblio ModBiblio GetMarcFromKohaField ); |
Lines 322-324
subtest 'pickup_locations() tests' => sub {
Link Here
|
322 |
|
323 |
|
323 |
$schema->storage->txn_rollback; |
324 |
$schema->storage->txn_rollback; |
324 |
}; |
325 |
}; |
325 |
- |
326 |
|
|
|
327 |
subtest 'api_query_fixer() tests' => sub { |
328 |
|
329 |
plan tests => 2; |
330 |
|
331 |
my $rs = Koha::Biblios->new; |
332 |
|
333 |
subtest 'JSON query tests' => sub { |
334 |
|
335 |
plan tests => 6; |
336 |
|
337 |
my $query = encode_json( { collection_issn => { "-like" => "\%asd" } } ); |
338 |
is( |
339 |
$rs->api_query_fixer($query), '{"biblioitem.collection_issn":{"-like":"%asd"}}', |
340 |
'Query adapted for biblioitem attributes' |
341 |
); |
342 |
$query = encode_json( { author => { "-like" => "\%asd" } } ); |
343 |
is( $rs->api_query_fixer($query), $query, 'Query unchanged for non-biblioitem attributes' ); |
344 |
$query = encode_json( { author => { "-like" => "an age_restriction" } } ); |
345 |
is( $rs->api_query_fixer($query), $query, 'Query unchanged because quotes are expected for the match' ); |
346 |
|
347 |
$query = encode_json( { "biblio.collection_issn" => { "-like" => "\%asd" } } ); |
348 |
is( |
349 |
$rs->api_query_fixer( $query, 'biblio' ), '{"biblio.biblioitem.collection_issn":{"-like":"%asd"}}', |
350 |
'Query adapted for biblioitem attributes, context is kept, match using context' |
351 |
); |
352 |
$query = encode_json( { collection_issn => { "-like" => "\%asd" } } ); |
353 |
is( $rs->api_query_fixer( $query, 'biblio' ), $query, 'Query unchanged because no match for context' ); |
354 |
$query = encode_json( { author => { "-like" => "a biblio.age_restriction" } } ); |
355 |
is( |
356 |
$rs->api_query_fixer( $query, 'biblio' ), $query, |
357 |
'Query unchanged because quotes are expected for the match' |
358 |
); |
359 |
}; |
360 |
|
361 |
subtest 'order_by tests' => sub { |
362 |
|
363 |
plan tests => 6; |
364 |
|
365 |
my $query = encode_json( { collection_issn => { "-like" => "\%asd" } } ); |
366 |
is( |
367 |
$rs->api_query_fixer( $query, undef, 1 ), '{"biblioitem.collection_issn":{"-like":"%asd"}}', |
368 |
'Query adapted for biblioitem attributes' |
369 |
); |
370 |
$query = encode_json( { author => { "-like" => "\%asd" } } ); |
371 |
is( $rs->api_query_fixer( $query, undef, 1 ), $query, 'Query unchanged for non-biblioitem attributes' ); |
372 |
$query = encode_json( { author => { "-like" => "an age_restriction" } } ); |
373 |
is( |
374 |
$rs->api_query_fixer( $query, undef, 1 ), '{"author":{"-like":"an biblioitem.age_restriction"}}', |
375 |
'Query changed because quotes are not expected for the match' |
376 |
); |
377 |
|
378 |
$query = encode_json( { "banana.collection_issn" => { "-like" => "\%asd" } } ); |
379 |
is( |
380 |
$rs->api_query_fixer( $query, 'banana', 1 ), '{"banana.biblioitem.collection_issn":{"-like":"%asd"}}', |
381 |
'Query adapted for biblioitem attributes' |
382 |
); |
383 |
$query = encode_json( { author => { "-like" => "\%asd" } } ); |
384 |
is( $rs->api_query_fixer( $query, 'banana', 1 ), $query, 'Query unchanged for non-biblioitem attributes' ); |
385 |
$query = encode_json( { author => { "-like" => "a banana.age_restriction" } } ); |
386 |
is( |
387 |
$rs->api_query_fixer( $query, 'banana', 1 ), '{"author":{"-like":"a banana.biblioitem.age_restriction"}}', |
388 |
'Query changed because quotes are not expected for the match' |
389 |
); |
390 |
} |
391 |
}; |