|
Lines 665-670
subtest 'Koha::Item(s) tests' => sub {
Link Here
|
| 665 |
$schema->storage->txn_rollback; |
665 |
$schema->storage->txn_rollback; |
| 666 |
}; |
666 |
}; |
| 667 |
|
667 |
|
|
|
668 |
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { |
| 669 |
plan tests => 11; |
| 670 |
|
| 671 |
$schema->storage->txn_begin(); |
| 672 |
|
| 673 |
my $builder = t::lib::TestBuilder->new; |
| 674 |
my $library1 = $builder->build({ |
| 675 |
source => 'Branch', |
| 676 |
}); |
| 677 |
my $library2 = $builder->build({ |
| 678 |
source => 'Branch', |
| 679 |
}); |
| 680 |
my $itemtype = $builder->build({ |
| 681 |
source => 'Itemtype', |
| 682 |
}); |
| 683 |
|
| 684 |
my $biblio = $builder->build_sample_biblio(); |
| 685 |
my $item_infos = [ |
| 686 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, |
| 687 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, |
| 688 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, |
| 689 |
{ homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} }, |
| 690 |
{ homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} }, |
| 691 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} }, |
| 692 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} }, |
| 693 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} }, |
| 694 |
]; |
| 695 |
my $number_of_items = scalar @$item_infos; |
| 696 |
my $number_of_items_with_homebranch_is_CPL = |
| 697 |
grep { $_->{homebranch} eq $library1->{branchcode} } @$item_infos; |
| 698 |
|
| 699 |
my @itemnumbers; |
| 700 |
for my $item_info (@$item_infos) { |
| 701 |
my $itemnumber = $builder->build_sample_item( |
| 702 |
{ |
| 703 |
biblionumber => $biblio->biblionumber, |
| 704 |
homebranch => $item_info->{homebranch}, |
| 705 |
holdingbranch => $item_info->{holdingbranch}, |
| 706 |
itype => $itemtype->{itemtype} |
| 707 |
} |
| 708 |
)->itemnumber; |
| 709 |
|
| 710 |
push @itemnumbers, $itemnumber; |
| 711 |
} |
| 712 |
|
| 713 |
my $host_item = $builder->build_sample_item({ homebranch => $library2->{branchcode} }); |
| 714 |
my $child_field = PrepHostMarcField( $host_item->biblionumber, $host_item->itemnumber, 'MARC21'); |
| 715 |
my $child_record = $biblio->metadata->record; |
| 716 |
$child_record->append_fields($child_field); |
| 717 |
ModBiblio( $child_record, $biblio->biblionumber, '' ); |
| 718 |
|
| 719 |
# Emptied the OpacHiddenItems pref |
| 720 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', '' ); |
| 721 |
|
| 722 |
my ($itemfield) = |
| 723 |
C4::Biblio::GetMarcFromKohaField( 'items.itemnumber' ); |
| 724 |
my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber }); |
| 725 |
warning_is { C4::Biblio::EmbedItemsInMarcBiblio() } |
| 726 |
{ carped => 'EmbedItemsInMarcBiblio: No MARC record passed' }, |
| 727 |
'Should carp is no record passed.'; |
| 728 |
|
| 729 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
| 730 |
marc_record => $record, |
| 731 |
biblionumber => $biblio->biblionumber }); |
| 732 |
my @items = $record->field($itemfield); |
| 733 |
is( scalar @items, $number_of_items, 'Should return all items' ); |
| 734 |
|
| 735 |
my $marc_with_items = C4::Biblio::GetMarcBiblio({ |
| 736 |
biblionumber => $biblio->biblionumber, |
| 737 |
embed_items => 1 }); |
| 738 |
is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches'); |
| 739 |
|
| 740 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
| 741 |
marc_record => $record, |
| 742 |
biblionumber => $biblio->biblionumber, |
| 743 |
embed_host_items => 1 |
| 744 |
}); |
| 745 |
@items = $record->field($itemfield); |
| 746 |
is( scalar @items, $number_of_items + 1, 'Should return all items plus host items' ); |
| 747 |
|
| 748 |
$marc_with_items = C4::Biblio::GetMarcBiblio({ |
| 749 |
biblionumber => $biblio->biblionumber, |
| 750 |
embed_items => 1, |
| 751 |
embed_host_items => 1 |
| 752 |
}); |
| 753 |
is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches'); |
| 754 |
|
| 755 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
| 756 |
marc_record => $record, |
| 757 |
biblionumber => $biblio->biblionumber, |
| 758 |
item_numbers => [ $itemnumbers[1], $itemnumbers[3] ] }); |
| 759 |
@items = $record->field($itemfield); |
| 760 |
is( scalar @items, 2, 'Should return all items present in the list' ); |
| 761 |
|
| 762 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
| 763 |
marc_record => $record, |
| 764 |
biblionumber => $biblio->biblionumber, |
| 765 |
opac => 1 }); |
| 766 |
@items = $record->field($itemfield); |
| 767 |
is( scalar @items, $number_of_items, 'Should return all items for opac' ); |
| 768 |
|
| 769 |
my $opachiddenitems = " |
| 770 |
homebranch: ['$library1->{branchcode}']"; |
| 771 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); |
| 772 |
|
| 773 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
| 774 |
marc_record => $record, |
| 775 |
biblionumber => $biblio->biblionumber }); |
| 776 |
@items = $record->field($itemfield); |
| 777 |
is( scalar @items, |
| 778 |
$number_of_items, |
| 779 |
'Even with OpacHiddenItems set, all items should have been embedded' ); |
| 780 |
|
| 781 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
| 782 |
marc_record => $record, |
| 783 |
biblionumber => $biblio->biblionumber, |
| 784 |
opac => 1 }); |
| 785 |
@items = $record->field($itemfield); |
| 786 |
is( |
| 787 |
scalar @items, |
| 788 |
$number_of_items - $number_of_items_with_homebranch_is_CPL, |
| 789 |
'For OPAC, the pref OpacHiddenItems should have been take into account. Only items with homebranch ne CPL should have been embedded' |
| 790 |
); |
| 791 |
|
| 792 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
| 793 |
marc_record => $record, |
| 794 |
biblionumber => $biblio->biblionumber, |
| 795 |
opac => 1, |
| 796 |
embed_host_items => 1 |
| 797 |
}); |
| 798 |
@items = $record->field($itemfield); |
| 799 |
is( |
| 800 |
scalar @items, |
| 801 |
$number_of_items - $number_of_items_with_homebranch_is_CPL + 1, |
| 802 |
'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' |
| 803 |
); |
| 804 |
|
| 805 |
|
| 806 |
$opachiddenitems = " |
| 807 |
homebranch: ['$library1->{branchcode}', '$library2->{branchcode}']"; |
| 808 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); |
| 809 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
| 810 |
marc_record => $record, |
| 811 |
biblionumber => $biblio->biblionumber, |
| 812 |
opac => 1 }); |
| 813 |
@items = $record->field($itemfield); |
| 814 |
is( |
| 815 |
scalar @items, |
| 816 |
0, |
| 817 |
'For OPAC, If all items are hidden, no item should have been embedded' |
| 818 |
); |
| 819 |
|
| 820 |
$schema->storage->txn_rollback; |
| 821 |
}; |
| 822 |
|
| 668 |
subtest 'get_hostitemnumbers_of' => sub { |
823 |
subtest 'get_hostitemnumbers_of' => sub { |
| 669 |
plan tests => 3; |
824 |
plan tests => 3; |
| 670 |
|
825 |
|
| 671 |
- |
|
|