Lines 1-5
Link Here
|
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# Copyright 2016 BibLibre Morgane Alonso |
1 |
# Copyright 2016 BibLibre Morgane Alonso |
4 |
# |
2 |
# |
5 |
# This file is part of Koha |
3 |
# This file is part of Koha |
Lines 23-32
use t::lib::TestBuilder;
Link Here
|
23 |
use t::lib::Mocks; |
21 |
use t::lib::Mocks; |
24 |
use Test::MockModule; |
22 |
use Test::MockModule; |
25 |
use Test::MockObject; |
23 |
use Test::MockObject; |
26 |
use Test::More tests => 45; |
24 |
use Test::More tests => 49; |
|
|
25 |
use Test::Exception; |
27 |
use Koha::Database; |
26 |
use Koha::Database; |
28 |
use Koha::Patrons; |
27 |
use Koha::Patrons; |
29 |
use Koha::Subscriptions; |
28 |
use Koha::Subscriptions; |
|
|
29 |
use Koha::DateUtils qw(dt_from_string); |
30 |
use Koha::Util::Normalize; |
31 |
use Koha::Reading_suggestions; |
30 |
|
32 |
|
31 |
use HTTP::Status qw(:constants :is status_message); |
33 |
use HTTP::Status qw(:constants :is status_message); |
32 |
|
34 |
|
Lines 42-48
my $post_request = 0;
Link Here
|
42 |
my $query = {}; |
44 |
my $query = {}; |
43 |
|
45 |
|
44 |
t::lib::Mocks::mock_config( 'mana_config', 'https://foo.bar'); |
46 |
t::lib::Mocks::mock_config( 'mana_config', 'https://foo.bar'); |
45 |
|
|
|
46 |
is(Koha::SharedContent::get_sharing_url(), 'https://foo.bar', 'Mana URL'); |
47 |
is(Koha::SharedContent::get_sharing_url(), 'https://foo.bar', 'Mana URL'); |
47 |
|
48 |
|
48 |
my $result = Koha::SharedContent::search_entities('report', $query); |
49 |
my $result = Koha::SharedContent::search_entities('report', $query); |
Lines 240-243
is($query{resource}, 'subscription', 'Check ressource');
Link Here
|
240 |
|
241 |
|
241 |
is($request->uri->path, '/subscription/12.json/increment/foo', 'Path is subscription'); |
242 |
is($request->uri->path, '/subscription/12.json/increment/foo', 'Path is subscription'); |
242 |
|
243 |
|
|
|
244 |
# Reading pair. |
245 |
my $record1 = MARC::Record->new(); |
246 |
my $record2 = MARC::Record->new(); |
247 |
my $record3 = MARC::Record->new(); |
248 |
my $record4 = MARC::Record->new(); |
249 |
|
250 |
my $id1 = '9783161484100'; |
251 |
my $id2 = '9780321496942'; |
252 |
my $id3 = '9780914378266'; |
253 |
my $id4 = '9780491001304'; |
254 |
|
255 |
my $field1 = MARC::Field->new('020','','','a' => $id1); |
256 |
my $field2 = MARC::Field->new('020','','','a' => $id2); |
257 |
my $field3 = MARC::Field->new('020','','','a' => $id3); |
258 |
my $field4 = MARC::Field->new('020','','','a' => $id4); |
259 |
|
260 |
$record1->append_fields( $field1 ); |
261 |
$record2->append_fields( $field2 ); |
262 |
$record3->append_fields( $field3 ); |
263 |
$record4->append_fields( $field4 ); |
264 |
|
265 |
my %biblionumbers; |
266 |
my ($biblionumber1) = C4::Biblio::AddBiblio($record1, ''); |
267 |
$biblionumbers{biblio1} = $biblionumber1; |
268 |
my ($biblionumber2) = C4::Biblio::AddBiblio($record2, ''); |
269 |
$biblionumbers{biblio2} = $biblionumber2; |
270 |
my ($biblionumber3) = C4::Biblio::AddBiblio($record3, ''); |
271 |
$biblionumbers{biblio3} = $biblionumber3; |
272 |
my ($biblionumber4) = C4::Biblio::AddBiblio($record4, ''); |
273 |
$biblionumbers{biblio4} = $biblionumber4; |
274 |
|
275 |
my $biblio1 = Koha::Biblios->find( $biblionumber1 ); |
276 |
my $biblio2 = Koha::Biblios->find( $biblionumber2 ); |
277 |
my $biblio3 = Koha::Biblios->find( $biblionumber3 ); |
278 |
my $biblio4 = Koha::Biblios->find( $biblionumber4 ); |
279 |
|
280 |
my $item1_0 = $builder->build({source => 'Item', value => { |
281 |
biblionumber => $biblio1->biblionumber |
282 |
} |
283 |
}); |
284 |
my $item1_1 = $builder->build({source => 'Item', value => { |
285 |
biblionumber => $biblio1->biblionumber |
286 |
} |
287 |
}); |
288 |
my $item1_2 = $builder->build({source => 'Item', value => { |
289 |
biblionumber => $biblio1->biblionumber |
290 |
} |
291 |
}); |
292 |
my $item1_3 = $builder->build({source => 'Item', value => { |
293 |
biblionumber => $biblio1->biblionumber |
294 |
} |
295 |
}); |
296 |
my $item1_4 = $builder->build({source => 'Item', value => { |
297 |
biblionumber => $biblio1->biblionumber |
298 |
} |
299 |
}); |
300 |
my $item1_5 = $builder->build({source => 'Item', value => { |
301 |
biblionumber => $biblio1->biblionumber |
302 |
} |
303 |
}); |
304 |
my $item2_0 = $builder->build({source => 'Item', value => { |
305 |
biblionumber => $biblio2->biblionumber |
306 |
} |
307 |
}); |
308 |
my $item3_0 = $builder->build({source => 'Item', value => { |
309 |
biblionumber => $biblio3->biblionumber |
310 |
} |
311 |
}); |
312 |
my $item4_0 = $builder->build({source => 'Item', value => { |
313 |
biblionumber => $biblio4->biblionumber |
314 |
} |
315 |
}); |
316 |
my $item3_1 = $builder->build({source => 'Item', value => { |
317 |
biblionumber => $biblio3->biblionumber |
318 |
} |
319 |
}); |
320 |
|
321 |
my $item4_1 = $builder->build({source => 'Item', value => { |
322 |
biblionumber => $biblio4->biblionumber |
323 |
} |
324 |
}); |
325 |
|
326 |
|
327 |
my $now=DateTime->now()->strftime('%F'); |
328 |
my $yesterday = DateTime->now()->add(days => -1)->strftime('%F'); |
329 |
|
330 |
my $issue1 = $builder->build({source => 'Issue', value => { |
331 |
itemnumber => $item1_0->{itemnumber}, |
332 |
issuedate => $now |
333 |
} |
334 |
}); |
335 |
#issue1 and issue2 test if we create a pair between todays issues and an older one |
336 |
my $issue2 = $builder->build({source => 'Issue', value => { |
337 |
borrowernumber => $issue1->{borrowernumber}, |
338 |
itemnumber => $item2_0->{itemnumber}, |
339 |
issuedate => $yesterday |
340 |
} |
341 |
}); |
342 |
my $issue3 = $builder->build({source => 'Issue', value => { |
343 |
itemnumber => $item3_0->{itemnumber}, |
344 |
issuedate => $now |
345 |
} |
346 |
}); |
347 |
#issue3 and issue4 test if we create a pair between 2 todays issues (and not mixing borrowers) |
348 |
my $issue4 = $builder->build({source => 'Issue', value => { |
349 |
borrowernumber => $issue3->{borrowernumber}, |
350 |
itemnumber => $item4_0->{itemnumber}, |
351 |
issuedate => $now |
352 |
} |
353 |
}); |
354 |
#issue1 and issue5 test if we can create more than one pair for a single borrower |
355 |
my $issue5 = $builder->build({source => 'Issue', value => { |
356 |
borrowernumber => $issue1->{borrowernumber}, |
357 |
itemnumber => $item3_1->{itemnumber}, |
358 |
issuedate => $yesterday |
359 |
} |
360 |
}); |
361 |
#issue6 test if a borrower with a single issues does not create any pair |
362 |
my $issue6 = $builder->build({source => 'Issue', value => { |
363 |
itemnumber => $item1_1->{itemnumber}, |
364 |
issuedate => $now |
365 |
} |
366 |
}); |
367 |
|
368 |
#issue1 and issue7 test pairs are created between todays issues and old_issues table |
369 |
my $issue7 = $builder->build({source => 'OldIssue', value => { |
370 |
borrowernumber => $issue1->{borrowernumber}, |
371 |
itemnumber => $item4_1->{itemnumber}, |
372 |
issuedate => $yesterday |
373 |
} |
374 |
}); |
375 |
my $issue8 = $builder->build({source => 'OldIssue', value => { |
376 |
itemnumber => $item1_0->{itemnumber}, |
377 |
issuedate => $now |
378 |
} |
379 |
}); |
380 |
#issue8 and issue9 test that no pairs are created between old_issues issues |
381 |
my $issue9 = $builder->build({source => 'OldIssue', value => { |
382 |
borrowernumber => $issue8->{borrowernumber}, |
383 |
itemnumber => $item2_0->{itemnumber}, |
384 |
issuedate => $yesterday |
385 |
} |
386 |
}); |
387 |
|
388 |
my $issue10 = $builder->build({source => 'Issue', value => { |
389 |
itemnumber => $item1_2->{itemnumber}, |
390 |
issuedate => $now |
391 |
} |
392 |
}); |
393 |
#issue10 and issue11 test that no pairs are created between same biblio |
394 |
my $issue11 = $builder->build({source => 'Issue', value => { |
395 |
borrowernumber => $issue10->{borrowernumber}, |
396 |
itemnumber => $item1_3->{itemnumber}, |
397 |
issuedate => $yesterday |
398 |
} |
399 |
}); |
400 |
|
401 |
my $issue12 = $builder->build({source => 'Issue', value => { |
402 |
itemnumber => $item1_4->{itemnumber}, |
403 |
issuedate => $yesterday |
404 |
} |
405 |
}); |
406 |
#issue12 and issue13 test that no pairs are created between two issues from yesterday |
407 |
my $issue13 = $builder->build({source => 'Issue', value => { |
408 |
borrowernumber => $issue12->{borrowernumber}, |
409 |
itemnumber => $item1_5->{itemnumber}, |
410 |
issuedate => $yesterday |
411 |
} |
412 |
}); |
413 |
|
414 |
|
415 |
|
416 |
|
417 |
my $issue_50 = $builder->build({source => 'Issue', value => { |
418 |
issuedate => $now |
419 |
} |
420 |
}); |
421 |
|
422 |
#creating more than 50 issues for a specific borrower to check if, as expected, no pairs are created for this borrower |
423 |
for (my $i = 0; $i <= 50; $i++){ |
424 |
$builder->build({source => 'Issue', value => { |
425 |
borrowernumber => $issue6->{borrowernumber}, |
426 |
issuedate => $now |
427 |
}}); |
428 |
}; |
429 |
|
430 |
|
431 |
|
432 |
my @reading_pairs = Koha::SharedContent::extract_reading_pairs(); |
433 |
subtest 'Create pair' => sub { |
434 |
plan tests => 5; |
435 |
|
436 |
is($#reading_pairs, 3, "There are four pairs as exepected"); |
437 |
|
438 |
subtest '1st pair is as expected' => sub { |
439 |
plan tests => 4; |
440 |
|
441 |
is($reading_pairs[0]->{documentid1}, $id1, "1st pair documentid1 is $id1 as expected"); |
442 |
is($reading_pairs[0]->{documentid2}, $id2, "1st pair documentid2 is $id2 as expected"); |
443 |
is($reading_pairs[0]->{idtype1}, "isbn", "1st pair idtype1 is isbn as expected"); |
444 |
is($reading_pairs[0]->{idtype2}, "isbn", "1st pair idtype2 is isbn as expected"); |
445 |
}; |
446 |
|
447 |
subtest '2nd pair is as expected' => sub { |
448 |
plan tests => 4; |
449 |
|
450 |
is($reading_pairs[1]->{documentid1}, $id1, "2nd pair documentid1 is $id1 as expected"); |
451 |
is($reading_pairs[1]->{documentid2}, $id3, "2nd pair documentid2 is $id3 as expected"); |
452 |
is($reading_pairs[1]->{idtype1}, "isbn", "2nd pair idtype1 is isbn as expected"); |
453 |
is($reading_pairs[1]->{idtype2}, "isbn", "2nd pair idtype2 is isbn as expected"); |
454 |
}; |
455 |
|
456 |
subtest '3rd pair is as expected' => sub { |
457 |
plan tests => 4; |
458 |
|
459 |
is($reading_pairs[2]->{documentid1}, $id3, "3rd pair documentid1 is $id3 is as expected"); |
460 |
is($reading_pairs[2]->{documentid2}, $id4, "3rd pair documentid2 is $id4 as expected"); |
461 |
is($reading_pairs[2]->{idtype1}, "isbn", "3rd pair idtype1 is isbn as expected"); |
462 |
is($reading_pairs[2]->{idtype2}, "isbn", "3rd pair idtype2 is isbn as expected"); |
463 |
}; |
464 |
|
465 |
subtest '4th pair is as expected' => sub { |
466 |
plan tests => 4; |
467 |
|
468 |
is($reading_pairs[3]->{documentid1}, $id1, "4th pair documentid1 is $id4 as expected"); |
469 |
is($reading_pairs[3]->{documentid2}, $id4, "4th pair documentid2 is $id4 as expected"); |
470 |
is($reading_pairs[3]->{idtype1}, "isbn", "4th pair idtype1 is isbn as expected"); |
471 |
is($reading_pairs[3]->{idtype2}, "isbn", "4th pair idtype2 is isbn as expected"); |
472 |
}; |
473 |
}; |
474 |
|
475 |
subtest 'get_identifier_field_marc' => sub { |
476 |
plan tests => 28; |
477 |
|
478 |
t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' ); |
479 |
my ($fields_ref, $inds1_ref) = Koha::SharedContent::get_identifier_field_marc(); |
480 |
is($fields_ref->{isbn}, "010", "UNIMARC isbn is in fields 010"); |
481 |
is($fields_ref->{issn}, "011", "UNIMARC issn is in fields 011"); |
482 |
is($fields_ref->{ismn}, "013", "UNIMARC ismn is in fields 013"); |
483 |
is($fields_ref->{isrn}, "015", "UNIMARC isrn is in fields 015"); |
484 |
is($fields_ref->{isrc}, "016", "UNIMARC isbn is in fields 016"); |
485 |
is($fields_ref->{upc}, "072", "UNIMARC upc is in fields 072"); |
486 |
is($fields_ref->{ean}, "073", "UNIMARC ean is in fields 073"); |
487 |
|
488 |
is($inds1_ref->{isbn}, "", "UNIMARC isbn does not use inds1"); |
489 |
is($inds1_ref->{issn}, "", "UNIMARC issn does not use inds1"); |
490 |
is($inds1_ref->{ismn}, "", "UNIMARC ismn does not use inds1"); |
491 |
is($inds1_ref->{isrn}, "", "UNIMARC isrn does not use inds1"); |
492 |
is($inds1_ref->{isrc}, "", "UNIMARC isbn does not use inds1"); |
493 |
is($inds1_ref->{upc}, "", "UNIMARC upc does not use inds1"); |
494 |
is($inds1_ref->{ean}, "", "UNIMARC ean does not use inds1"); |
495 |
|
496 |
t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); |
497 |
($fields_ref, $inds1_ref) = Koha::SharedContent::get_identifier_field_marc(); |
498 |
is($fields_ref->{isbn}, "020", "MARC21 isbn is in fields 020"); |
499 |
is($fields_ref->{issn}, "022", "MARC21 issn is in fields 022"); |
500 |
is($fields_ref->{ismn}, "024", "MARC21 ismn is in fields 024"); |
501 |
is($fields_ref->{isrn}, "027", "MARC21 isrn is in fields 027"); |
502 |
is($fields_ref->{isrc}, "024", "MARC21 isbn is in fields 024"); |
503 |
is($fields_ref->{upc}, "024", "MARC21 upc is in fields 024"); |
504 |
is($fields_ref->{ean}, "024", "MARC21 ean is in fields 024"); |
505 |
|
506 |
is($inds1_ref->{isbn}, "", "MARC21 isbn does not use inds1"); |
507 |
is($inds1_ref->{issn}, "", "MARC21 issn does not use inds1"); |
508 |
is($inds1_ref->{ismn}, " and \@ind1=\"2\"", "MARC21 ismn inds1 is 2"); |
509 |
is($inds1_ref->{isrn}, "", "MARC21 isrn does not use inds1"); |
510 |
is($inds1_ref->{isrc}, " and \@ind1=\"0\"", "MARC21 isbn inds1 is 0"); |
511 |
is($inds1_ref->{upc}, " and \@ind1=\"1\"", "MARC21 upc inds1 is 1"); |
512 |
is($inds1_ref->{ean}, " and \@ind1=\"3\"", "MARC21 ean inds1 is 3"); |
513 |
|
514 |
}; |
515 |
|
516 |
subtest 'Get identifiers' => sub { |
517 |
plan tests => 10; |
518 |
|
519 |
subtest '1 isbn' => sub { |
520 |
plan tests => 3; |
521 |
|
522 |
my $result = Koha::SharedContent::get_identifiers($biblio1->biblionumber); |
523 |
is($result->{idtype}, "isbn", "idtype"); |
524 |
is($result->{documentids}, $id1, "documentid"); |
525 |
is($result->{code}, 200, "code"); |
526 |
}; |
527 |
|
528 |
subtest '2 isbn' => sub { |
529 |
plan tests => 3; |
530 |
|
531 |
my $record = MARC::Record->new(); |
532 |
my $ida = '9783161484100'; |
533 |
my $idb = '9782765410058'; |
534 |
my $fielda = MARC::Field->new('020','','','a' => $ida); |
535 |
my $fieldb = MARC::Field->new('020','','','a' => $idb); |
536 |
$record->append_fields( $fielda ); |
537 |
$record->append_fields( $fieldb ); |
538 |
my ($biblionumber) = C4::Biblio::AddBiblio($record, ''); |
539 |
$biblionumbers{isbn2} = $biblionumber; |
540 |
|
541 |
my $result = Koha::SharedContent::get_identifiers($biblionumber); |
542 |
is($result->{idtype}, "isbn", "idtype"); |
543 |
is($result->{documentids}, "$ida $idb", "documentids"); |
544 |
is($result->{code}, 200, "code"); |
545 |
}; |
546 |
|
547 |
subtest '2 ean' => sub { |
548 |
plan tests => 3; |
549 |
|
550 |
my $ida = '9783161484100'; |
551 |
my $idb = '9782266247306'; |
552 |
my $record = MARC::Record->new(); |
553 |
my $fielda = MARC::Field->new('024','3','','a' => $ida); |
554 |
my $fieldb = MARC::Field->new('024','3','','a' => $idb); |
555 |
$record->append_fields( $fielda ); |
556 |
$record->append_fields( $fieldb ); |
557 |
my ($biblionumber) = C4::Biblio::AddBiblio($record, ''); |
558 |
$biblionumbers{ean2} = $biblionumber; |
559 |
|
560 |
my $result = Koha::SharedContent::get_identifiers($biblionumber); |
561 |
is($result->{idtype}, "ean", "idtype"); |
562 |
is($result->{documentids}, "$ida $idb", "documentids"); |
563 |
is($result->{code}, 200, "code"); |
564 |
}; |
565 |
|
566 |
subtest '2 issn' => sub { |
567 |
plan tests => 3; |
568 |
|
569 |
my $ida = '0335-4725'; |
570 |
my $idb = '0151-0282'; |
571 |
my $record = MARC::Record->new(); |
572 |
my $fielda = MARC::Field->new('022','','','a' => $ida); |
573 |
my $fieldb = MARC::Field->new('022','','','a' => $idb); |
574 |
$record->append_fields( $fielda ); |
575 |
$record->append_fields( $fieldb ); |
576 |
my ($biblionumber) = C4::Biblio::AddBiblio($record, ''); |
577 |
$biblionumbers{issn2} = $biblionumber; |
578 |
|
579 |
my $result = Koha::SharedContent::get_identifiers($biblionumber); |
580 |
is($result->{idtype}, "issn", "idtype"); |
581 |
is($result->{documentids}, "$ida $idb", "documentids"); |
582 |
is($result->{code}, 200, "code"); |
583 |
}; |
584 |
|
585 |
subtest '2 ismn' => sub { |
586 |
plan tests => 3; |
587 |
|
588 |
my $ida = '9790260000438'; |
589 |
my $idb = '9790000001213'; |
590 |
my $record = MARC::Record->new(); |
591 |
my $fielda = MARC::Field->new('024','2','','a' => $ida); |
592 |
my $fieldb = MARC::Field->new('024','2','','a' => $idb); |
593 |
$record->append_fields( $fielda ); |
594 |
$record->append_fields( $fieldb ); |
595 |
my ($biblionumber) = C4::Biblio::AddBiblio($record, ''); |
596 |
$biblionumbers{ismn2} = $biblionumber; |
597 |
|
598 |
my $result = Koha::SharedContent::get_identifiers($biblionumber); |
599 |
is($result->{idtype}, "ismn", "idtype"); |
600 |
is($result->{documentids}, "$ida $idb", "documentids"); |
601 |
is($result->{code}, 200, "code"); |
602 |
}; |
603 |
|
604 |
subtest '2 isrn' => sub { |
605 |
plan tests => 3; |
606 |
|
607 |
my $ida = 'METPRO-CB-TR--74-216'; |
608 |
my $idb = 'COUCOU-ICI--00-45'; |
609 |
my $record = MARC::Record->new(); |
610 |
my $fielda = MARC::Field->new('027','','','a' => $ida); |
611 |
my $fieldb = MARC::Field->new('027','','','a' => $idb); |
612 |
$record->append_fields( $fielda ); |
613 |
$record->append_fields( $fieldb ); |
614 |
my ($biblionumber) = C4::Biblio::AddBiblio($record, ''); |
615 |
$biblionumbers{isrn2} = $biblionumber; |
616 |
|
617 |
my $result = Koha::SharedContent::get_identifiers($biblionumber); |
618 |
is($result->{idtype}, "isrn", "idtype"); |
619 |
is($result->{documentids}, "$ida $idb", "documentids"); |
620 |
is($result->{code}, 200, "code"); |
621 |
}; |
622 |
|
623 |
subtest '2 isrc' => sub { |
624 |
plan tests => 3; |
625 |
|
626 |
my $ida = 'FRAB50712345'; |
627 |
my $idb = 'FRR091240970'; |
628 |
my $record = MARC::Record->new(); |
629 |
my $fielda = MARC::Field->new('024','0','','a' => $ida); |
630 |
my $fieldb = MARC::Field->new('024','0','','a' => $idb); |
631 |
$record->append_fields( $fielda ); |
632 |
$record->append_fields( $fieldb ); |
633 |
my ($biblionumber) = C4::Biblio::AddBiblio($record, ''); |
634 |
$biblionumbers{isrc2} = $biblionumber; |
635 |
|
636 |
my $result = Koha::SharedContent::get_identifiers($biblionumber); |
637 |
is($result->{idtype}, "isrc", "idtype"); |
638 |
is($result->{documentids}, "$ida $idb", "documentids"); |
639 |
is($result->{code}, 200, "code"); |
640 |
}; |
641 |
|
642 |
subtest '2 upc' => sub { |
643 |
plan tests => 3; |
644 |
|
645 |
my $ida = '036000291452'; |
646 |
my $idb = '123601057072'; |
647 |
my $record = MARC::Record->new(); |
648 |
my $fielda = MARC::Field->new('024','1','','a' => $ida); |
649 |
my $fieldb = MARC::Field->new('024','1','','a' => $idb); |
650 |
$record->append_fields( $fielda ); |
651 |
$record->append_fields( $fieldb ); |
652 |
my ($biblionumber) = C4::Biblio::AddBiblio($record, ''); |
653 |
$biblionumbers{upc2} = $biblionumber; |
654 |
|
655 |
my $result = Koha::SharedContent::get_identifiers($biblionumber); |
656 |
is($result->{idtype}, "upc", "idtype"); |
657 |
is($result->{documentids}, "$ida $idb", "documentids"); |
658 |
is($result->{code}, 200, "code"); |
659 |
}; |
660 |
|
661 |
subtest 'invalid isbn' => sub { |
662 |
plan tests => 2; |
663 |
|
664 |
my $ida = '=af~faf5efg thg'; |
665 |
my $record = MARC::Record->new(); |
666 |
my $fielda = MARC::Field->new('020','','','a' => $ida); |
667 |
$record->append_fields( $fielda ); |
668 |
my ($biblionumber) = C4::Biblio::AddBiblio($record, ''); |
669 |
$biblionumbers{isbn_invalid} = $biblionumber; |
670 |
|
671 |
my $result = Koha::SharedContent::get_identifiers($biblionumber); |
672 |
is($result->{code}, 404, "code"); |
673 |
is($result->{message}, "No usable id found", "message"); |
674 |
}; |
675 |
|
676 |
subtest 'no id' => sub { |
677 |
plan tests => 2; |
678 |
my $record = MARC::Record->new(); |
679 |
my ($biblionumber) = C4::Biblio::AddBiblio($record, ''); |
680 |
$biblionumbers{no_id} = $biblionumber; |
681 |
|
682 |
my $result = Koha::SharedContent::get_identifiers($biblionumber); |
683 |
is($result->{code}, 404, "code"); |
684 |
is($result->{message}, "No usable id found", "message"); |
685 |
}; |
686 |
}; |
687 |
|
688 |
my $record5 = MARC::Record->new(); |
689 |
my $record6 = MARC::Record->new(); |
690 |
|
691 |
my $id5 = '9780596003067'; |
692 |
my $id6 = '9780596527211'; |
693 |
|
694 |
my $field5 = MARC::Field->new('024','3','','a' => $id5); |
695 |
my $field6 = MARC::Field->new('020','','','a' => $id6); |
696 |
|
697 |
$record5->append_fields( $field5 ); |
698 |
$record6->append_fields( $field6 ); |
699 |
|
700 |
my ($biblionumber5) = C4::Biblio::AddBiblio($record5, ''); |
701 |
$biblionumbers{biblio5} = $biblionumber5; |
702 |
my ($biblionumber6) = C4::Biblio::AddBiblio($record6, ''); |
703 |
$biblionumbers{biblio6} = $biblionumber6; |
704 |
|
705 |
print "bib5 = $biblionumber5, bib6=$biblionumber6\n"; |
706 |
my $item5_0 = $builder->build({source => 'Item', value => { |
707 |
biblionumber => $biblionumber5 |
708 |
} |
709 |
}); |
710 |
my $item6_0 = $builder->build({source => 'Item', value => { |
711 |
biblionumber => $biblionumber6 |
712 |
} |
713 |
}); |
714 |
|
715 |
sub mock_ask_mana_reading_suggestion { |
716 |
my ($params) = @_; |
717 |
my $start = $params->{start}; |
718 |
my $end = $params->{end}; |
719 |
my $code = $params->{code}; |
720 |
my $msg = $params->{msg}; |
721 |
|
722 |
if (!$start || !$end){ |
723 |
return {code => $code, msg => $msg} |
724 |
}; |
725 |
|
726 |
my @docs = ( |
727 |
{idtype => "isbn", documentid => "9783161484100"}, #biblio1 0 |
728 |
{idtype => "ean", documentid => "9783161484100"}, #biblio1 1 |
729 |
{idtype => "isbn", documentid => "9780321496942"}, #biblio2 2 |
730 |
{idtype => "issn", documentid => "0335-4725"}, #issn2 3 |
731 |
{idtype => "ismn", documentid => "9790260000438"}, #ismn2 4 |
732 |
{idtype => "isbn", documentid => "9780914378266"}, #biblio3 5 |
733 |
{idtype => "isbn", documentid => "9780491001304"}, #biblio4 6 |
734 |
{idtype => "ean", documentid => "9782259025669"}, #not in database 7 |
735 |
{idtype => "isrn", documentid => "METPRO-CB-TR--74-216"}, #isrn2 8 |
736 |
{idtype => "isrc", documentid => "FRAB50712345"}, #isrc2 9 |
737 |
{idtype => "upc", documentid => "036000291452"}, #upc2 10 |
738 |
{idtype => "isbn", documentid => "9782379891113"}, #not in datbase 11 |
739 |
{idtype => "ean", documentid => "9782266247306"}, #ean2 12 |
740 |
{idtype => "ean", documentid => "9780596003067"}, #biblio5 13 |
741 |
{idtype => "isbn", documentid => "9780596527211"}, #biblio6 14 |
742 |
); |
743 |
my @slice = @docs[$start..$end]; |
744 |
my $ref = \@slice; |
745 |
|
746 |
return {code => $code, data => $ref}; |
747 |
}; |
748 |
|
749 |
subtest 'get reading pair' => sub { |
750 |
plan tests => 7; |
751 |
|
752 |
subtest 'biblio1' => sub { |
753 |
plan tests => 12; |
754 |
|
755 |
my $module = Test::MockModule->new('Koha::SharedContent'); |
756 |
$module->mock('ask_mana_reading_suggestion', sub {return mock_ask_mana_reading_suggestion{code => 200, start => 2, end => 14}}); |
757 |
my $biblionumber = $biblionumbers{biblio1}; |
758 |
my $local_suggestions; |
759 |
eval{ |
760 |
$local_suggestions = Koha::Reading_suggestions->find( $biblionumber )->unblessed(); |
761 |
}; |
762 |
|
763 |
my $result = Koha::SharedContent::get_reading_suggestion($biblionumber, $local_suggestions); |
764 |
is($result->{code}, 200, "code ok"); |
765 |
is($result->{data}[0]->{biblionumber}, $biblionumbers{biblio2}, "1st suggestion"); |
766 |
is($result->{data}[1]->{biblionumber}, $biblionumbers{issn2}, "2nd suggestion"); |
767 |
is($result->{data}[2]->{biblionumber}, $biblionumbers{ismn2}, "3rd suggestion"); |
768 |
is($result->{data}[3]->{biblionumber}, $biblionumbers{biblio3}, "4th suggestion"); |
769 |
is($result->{data}[4]->{biblionumber}, $biblionumbers{biblio4}, "5th suggestion"); |
770 |
is($result->{data}[5]->{biblionumber}, $biblionumbers{isrn2}, "6th suggestion"); |
771 |
is($result->{data}[6]->{biblionumber}, $biblionumbers{isrc2}, "7th suggestion"); |
772 |
is($result->{data}[7]->{biblionumber}, $biblionumbers{upc2}, "8th suggestion"); |
773 |
is($result->{data}[8]->{biblionumber}, $biblionumbers{ean2}, "9th suggestion"); |
774 |
is($result->{data}[9]->{biblionumber}, $biblionumbers{biblio5}, "10th suggestion"); |
775 |
is(exists($result->{data}[10]), '', "no 11th suggestion"); |
776 |
}; |
777 |
|
778 |
|
779 |
subtest 'biblio2' => sub { |
780 |
plan tests => 7; |
781 |
|
782 |
my $module = Test::MockModule->new('Koha::SharedContent'); |
783 |
$module->mock('ask_mana_reading_suggestion', sub {return mock_ask_mana_reading_suggestion{code => 200, start => 5, end => 10}}); |
784 |
my $biblionumber = $biblionumbers{biblio2}; |
785 |
my $local_suggestions; |
786 |
eval{ |
787 |
$local_suggestions = Koha::Reading_suggestions->find( $biblionumber )->unblessed(); |
788 |
}; |
789 |
|
790 |
my $result = Koha::SharedContent::get_reading_suggestion($biblionumber, $local_suggestions); |
791 |
is($result->{code}, 200, "code ok"); |
792 |
is($result->{data}[0]->{biblionumber}, $biblionumbers{biblio3}, "1st suggestion"); |
793 |
is($result->{data}[1]->{biblionumber}, $biblionumbers{biblio4}, "2nd suggestion"); |
794 |
is($result->{data}[2]->{biblionumber}, $biblionumbers{isrn2}, "3rd suggestion"); |
795 |
is($result->{data}[3]->{biblionumber}, $biblionumbers{isrc2}, "4th suggestion"); |
796 |
is($result->{data}[4]->{biblionumber}, $biblionumbers{upc2}, "5th suggestion"); |
797 |
is(exists($result->{data}[5]), '', "no 6th suggestion"); |
798 |
}; |
799 |
|
800 |
subtest 'biblio1 suggestion in koha db' => sub { |
801 |
plan tests => 11; |
802 |
|
803 |
my $dbh = C4::Context->dbh; |
804 |
my $db_query = q{ |
805 |
SELECT |
806 |
biblionumber, biblionumber1, biblionumber2, biblionumber3, biblionumber4, biblionumber5, biblionumber6, biblionumber6, biblionumber7, biblionumber8, biblionumber9, biblionumber10 |
807 |
FROM reading_suggestion |
808 |
WHERE |
809 |
biblionumber = '}.$biblionumbers{biblio1}.q{' |
810 |
}; |
811 |
my $sth = $dbh->prepare( $db_query ); |
812 |
$sth->execute; |
813 |
my $row = $sth->fetchrow_hashref; |
814 |
|
815 |
is($row->{biblionumber}, $biblionumbers{biblio1}, "biblionumber"); |
816 |
is($row->{biblionumber1}, $biblionumbers{biblio2}, "biblionumber1"); |
817 |
is($row->{biblionumber2}, $biblionumbers{issn2}, "biblionumber2"); |
818 |
is($row->{biblionumber3}, $biblionumbers{ismn2}, "biblionumber3"); |
819 |
is($row->{biblionumber4}, $biblionumbers{biblio3}, "biblionumber4"); |
820 |
is($row->{biblionumber5}, $biblionumbers{biblio4}, "biblionumber5"); |
821 |
is($row->{biblionumber6}, $biblionumbers{isrn2}, "biblionumber6"); |
822 |
is($row->{biblionumber7}, $biblionumbers{isrc2}, "biblionumber7"); |
823 |
is($row->{biblionumber8}, $biblionumbers{upc2}, "biblionumber8"); |
824 |
is($row->{biblionumber9}, $biblionumbers{ean2}, "biblionumber9"); |
825 |
is($row->{biblionumber10}, $biblionumbers{biblio5}, "biblionumber10"); |
826 |
}; |
827 |
|
828 |
subtest 'biblio2 suggestion in koha db' => sub { |
829 |
plan tests => 11; |
830 |
|
831 |
my $dbh = C4::Context->dbh; |
832 |
my $db_query = q{ |
833 |
SELECT |
834 |
biblionumber, biblionumber1, biblionumber2, biblionumber3, biblionumber4, biblionumber5, biblionumber6, biblionumber6, biblionumber7, biblionumber8, biblionumber9, biblionumber10 |
835 |
FROM reading_suggestion |
836 |
WHERE |
837 |
biblionumber = '}.$biblionumbers{biblio2}.q{' |
838 |
}; |
839 |
my $sth = $dbh->prepare( $db_query ); |
840 |
$sth->execute; |
841 |
my $row = $sth->fetchrow_hashref; |
842 |
|
843 |
is($row->{biblionumber}, $biblionumbers{biblio2}, "biblionumber"); |
844 |
is($row->{biblionumber1}, $biblionumbers{biblio3}, "biblionumber1"); |
845 |
is($row->{biblionumber2}, $biblionumbers{biblio4}, "biblionumber2"); |
846 |
is($row->{biblionumber3}, $biblionumbers{isrn2}, "biblionumber3"); |
847 |
is($row->{biblionumber4}, $biblionumbers{isrc2}, "biblionumber4"); |
848 |
is($row->{biblionumber5}, $biblionumbers{upc2}, "biblionumber5"); |
849 |
is($row->{biblionumber6}, undef, "biblionumber6"); |
850 |
is($row->{biblionumber7}, undef, "biblionumber7"); |
851 |
is($row->{biblionumber8}, undef, "biblionumber8"); |
852 |
is($row->{biblionumber9}, undef, "biblionumber9"); |
853 |
is($row->{biblionumber10}, undef, "biblionumber10"); |
854 |
}; |
855 |
|
856 |
|
857 |
subtest 'error code from mana with message' => sub { |
858 |
plan tests => 2; |
859 |
|
860 |
my $module = Test::MockModule->new('Koha::SharedContent'); |
861 |
$module->mock('ask_mana_reading_suggestion', sub {return mock_ask_mana_reading_suggestion{code => 401, msg => "Error 401"}}); |
862 |
|
863 |
my $biblionumber = $biblionumbers{biblio2}; |
864 |
my $local_suggestions; |
865 |
eval{ |
866 |
$local_suggestions = Koha::Reading_suggestions->find( $biblionumber )->unblessed(); |
867 |
}; |
868 |
|
869 |
my $result = Koha::SharedContent::get_reading_suggestion($biblionumber, $local_suggestions); |
870 |
|
871 |
is($result->{code}, 401, "code"); |
872 |
is($result->{message}, "Error 401", "message"); |
873 |
}; |
874 |
|
875 |
subtest 'error code from mana' => sub { |
876 |
plan tests => 2; |
877 |
|
878 |
my $module = Test::MockModule->new('Koha::SharedContent'); |
879 |
$module->mock('ask_mana_reading_suggestion', sub {return mock_ask_mana_reading_suggestion{code => 401}}); |
880 |
|
881 |
my $biblionumber = $biblionumbers{biblio2}; |
882 |
my $local_suggestions; |
883 |
eval{ |
884 |
$local_suggestions = Koha::Reading_suggestions->find( $biblionumber )->unblessed(); |
885 |
}; |
886 |
|
887 |
my $result = Koha::SharedContent::get_reading_suggestion($biblionumber, $local_suggestions); |
888 |
|
889 |
is($result->{code}, 401, "code"); |
890 |
is($result->{message}, undef, "message"); |
891 |
}; |
892 |
|
893 |
subtest 'error without code or message from mana' => sub { |
894 |
plan tests => 2; |
895 |
|
896 |
my $module = Test::MockModule->new('Koha::SharedContent'); |
897 |
$module->mock('ask_mana_reading_suggestion', sub {return mock_ask_mana_reading_suggestion{}}); |
898 |
|
899 |
my $biblionumber = $biblionumbers{biblio2}; |
900 |
my $local_suggestions; |
901 |
eval{ |
902 |
$local_suggestions = Koha::Reading_suggestions->find( $biblionumber )->unblessed(); |
903 |
}; |
904 |
|
905 |
my $result = Koha::SharedContent::get_reading_suggestion($biblionumber, $local_suggestions); |
906 |
|
907 |
is($result->{code}, 400, "code"); |
908 |
is($result->{message}, "Unknown error", "message"); |
909 |
}; |
910 |
|
911 |
}; |
912 |
|
243 |
$schema->storage->txn_rollback; |
913 |
$schema->storage->txn_rollback; |
244 |
- |
|
|