Lines 585-590
subtest 'Koha::Item(s) tests' => sub {
Link Here
|
585 |
$schema->storage->txn_rollback; |
585 |
$schema->storage->txn_rollback; |
586 |
}; |
586 |
}; |
587 |
|
587 |
|
|
|
588 |
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { |
589 |
plan tests => 11; |
590 |
|
591 |
$schema->storage->txn_begin(); |
592 |
|
593 |
my $builder = t::lib::TestBuilder->new; |
594 |
my $library1 = $builder->build({ |
595 |
source => 'Branch', |
596 |
}); |
597 |
my $library2 = $builder->build({ |
598 |
source => 'Branch', |
599 |
}); |
600 |
my $itemtype = $builder->build({ |
601 |
source => 'Itemtype', |
602 |
}); |
603 |
|
604 |
my $biblio = $builder->build_sample_biblio(); |
605 |
my $item_infos = [ |
606 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, |
607 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, |
608 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, |
609 |
{ homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} }, |
610 |
{ homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} }, |
611 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} }, |
612 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} }, |
613 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} }, |
614 |
]; |
615 |
my $number_of_items = scalar @$item_infos; |
616 |
my $number_of_items_with_homebranch_is_CPL = |
617 |
grep { $_->{homebranch} eq $library1->{branchcode} } @$item_infos; |
618 |
|
619 |
my @itemnumbers; |
620 |
for my $item_info (@$item_infos) { |
621 |
my $itemnumber = $builder->build_sample_item( |
622 |
{ |
623 |
biblionumber => $biblio->biblionumber, |
624 |
homebranch => $item_info->{homebranch}, |
625 |
holdingbranch => $item_info->{holdingbranch}, |
626 |
itype => $itemtype->{itemtype} |
627 |
} |
628 |
)->itemnumber; |
629 |
|
630 |
push @itemnumbers, $itemnumber; |
631 |
} |
632 |
|
633 |
my $host_item = $builder->build_sample_item({ homebranch => $library2->{branchcode} }); |
634 |
my $child_field = PrepHostMarcField( $host_item->biblionumber, $host_item->itemnumber, 'MARC21'); |
635 |
my $child_record = $biblio->metadata->record; |
636 |
$child_record->append_fields($child_field); |
637 |
ModBiblio( $child_record, $biblio->biblionumber, '' ); |
638 |
|
639 |
# Emptied the OpacHiddenItems pref |
640 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', '' ); |
641 |
|
642 |
my ($itemfield) = |
643 |
C4::Biblio::GetMarcFromKohaField( 'items.itemnumber' ); |
644 |
my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber }); |
645 |
warning_is { C4::Biblio::EmbedItemsInMarcBiblio() } |
646 |
{ carped => 'EmbedItemsInMarcBiblio: No MARC record passed' }, |
647 |
'Should carp is no record passed.'; |
648 |
|
649 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
650 |
marc_record => $record, |
651 |
biblionumber => $biblio->biblionumber }); |
652 |
my @items = $record->field($itemfield); |
653 |
is( scalar @items, $number_of_items, 'Should return all items' ); |
654 |
|
655 |
my $marc_with_items = C4::Biblio::GetMarcBiblio({ |
656 |
biblionumber => $biblio->biblionumber, |
657 |
embed_items => 1 }); |
658 |
is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches'); |
659 |
|
660 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
661 |
marc_record => $record, |
662 |
biblionumber => $biblio->biblionumber, |
663 |
embed_host_items => 1 |
664 |
}); |
665 |
@items = $record->field($itemfield); |
666 |
is( scalar @items, $number_of_items + 1, 'Should return all items plus host items' ); |
667 |
|
668 |
$marc_with_items = C4::Biblio::GetMarcBiblio({ |
669 |
biblionumber => $biblio->biblionumber, |
670 |
embed_items => 1, |
671 |
embed_host_items => 1 |
672 |
}); |
673 |
is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches'); |
674 |
|
675 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
676 |
marc_record => $record, |
677 |
biblionumber => $biblio->biblionumber, |
678 |
item_numbers => [ $itemnumbers[1], $itemnumbers[3] ] }); |
679 |
@items = $record->field($itemfield); |
680 |
is( scalar @items, 2, 'Should return all items present in the list' ); |
681 |
|
682 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
683 |
marc_record => $record, |
684 |
biblionumber => $biblio->biblionumber, |
685 |
opac => 1 }); |
686 |
@items = $record->field($itemfield); |
687 |
is( scalar @items, $number_of_items, 'Should return all items for opac' ); |
688 |
|
689 |
my $opachiddenitems = " |
690 |
homebranch: ['$library1->{branchcode}']"; |
691 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); |
692 |
|
693 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
694 |
marc_record => $record, |
695 |
biblionumber => $biblio->biblionumber }); |
696 |
@items = $record->field($itemfield); |
697 |
is( scalar @items, |
698 |
$number_of_items, |
699 |
'Even with OpacHiddenItems set, all items should have been embedded' ); |
700 |
|
701 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
702 |
marc_record => $record, |
703 |
biblionumber => $biblio->biblionumber, |
704 |
opac => 1 }); |
705 |
@items = $record->field($itemfield); |
706 |
is( |
707 |
scalar @items, |
708 |
$number_of_items - $number_of_items_with_homebranch_is_CPL, |
709 |
'For OPAC, the pref OpacHiddenItems should have been take into account. Only items with homebranch ne CPL should have been embedded' |
710 |
); |
711 |
|
712 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
713 |
marc_record => $record, |
714 |
biblionumber => $biblio->biblionumber, |
715 |
opac => 1, |
716 |
embed_host_items => 1 |
717 |
}); |
718 |
@items = $record->field($itemfield); |
719 |
is( |
720 |
scalar @items, |
721 |
$number_of_items - $number_of_items_with_homebranch_is_CPL + 1, |
722 |
'For OPAC, the pref OpacHiddenItems should have been take into account and host items embedded. Only items with homebranch ne CPL should have been embedded' |
723 |
); |
724 |
|
725 |
|
726 |
$opachiddenitems = " |
727 |
homebranch: ['$library1->{branchcode}', '$library2->{branchcode}']"; |
728 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); |
729 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
730 |
marc_record => $record, |
731 |
biblionumber => $biblio->biblionumber, |
732 |
opac => 1 }); |
733 |
@items = $record->field($itemfield); |
734 |
is( |
735 |
scalar @items, |
736 |
0, |
737 |
'For OPAC, If all items are hidden, no item should have been embedded' |
738 |
); |
739 |
|
740 |
$schema->storage->txn_rollback; |
741 |
}; |
742 |
|
588 |
subtest 'get_hostitemnumbers_of' => sub { |
743 |
subtest 'get_hostitemnumbers_of' => sub { |
589 |
plan tests => 3; |
744 |
plan tests => 3; |
590 |
|
745 |
|
591 |
- |
|
|