Lines 724-729
subtest 'Koha::Item(s) tests' => sub {
Link Here
|
724 |
$schema->storage->txn_rollback; |
724 |
$schema->storage->txn_rollback; |
725 |
}; |
725 |
}; |
726 |
|
726 |
|
|
|
727 |
subtest 'C4::Biblio::EmbedItemsInMarcBiblio' => sub { |
728 |
plan tests => 11; |
729 |
|
730 |
$schema->storage->txn_begin(); |
731 |
|
732 |
my $builder = t::lib::TestBuilder->new; |
733 |
my $library1 = $builder->build({ |
734 |
source => 'Branch', |
735 |
}); |
736 |
my $library2 = $builder->build({ |
737 |
source => 'Branch', |
738 |
}); |
739 |
my $itemtype = $builder->build({ |
740 |
source => 'Itemtype', |
741 |
}); |
742 |
|
743 |
my $biblio = $builder->build_sample_biblio(); |
744 |
my $item_infos = [ |
745 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, |
746 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, |
747 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library1->{branchcode} }, |
748 |
{ homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} }, |
749 |
{ homebranch => $library2->{branchcode}, holdingbranch => $library2->{branchcode} }, |
750 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} }, |
751 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} }, |
752 |
{ homebranch => $library1->{branchcode}, holdingbranch => $library2->{branchcode} }, |
753 |
]; |
754 |
my $number_of_items = scalar @$item_infos; |
755 |
my $number_of_items_with_homebranch_is_CPL = |
756 |
grep { $_->{homebranch} eq $library1->{branchcode} } @$item_infos; |
757 |
|
758 |
my @itemnumbers; |
759 |
for my $item_info (@$item_infos) { |
760 |
my $itemnumber = $builder->build_sample_item( |
761 |
{ |
762 |
biblionumber => $biblio->biblionumber, |
763 |
homebranch => $item_info->{homebranch}, |
764 |
holdingbranch => $item_info->{holdingbranch}, |
765 |
itype => $itemtype->{itemtype} |
766 |
} |
767 |
)->itemnumber; |
768 |
|
769 |
push @itemnumbers, $itemnumber; |
770 |
} |
771 |
|
772 |
my $host_item = $builder->build_sample_item({ homebranch => $library2->{branchcode} }); |
773 |
my $child_field = PrepHostMarcField( $host_item->biblionumber, $host_item->itemnumber, 'MARC21'); |
774 |
my $child_record = $biblio->metadata->record; |
775 |
$child_record->append_fields($child_field); |
776 |
ModBiblio( $child_record, $biblio->biblionumber, '' ); |
777 |
|
778 |
# Emptied the OpacHiddenItems pref |
779 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', '' ); |
780 |
|
781 |
my ($itemfield) = |
782 |
C4::Biblio::GetMarcFromKohaField( 'items.itemnumber' ); |
783 |
my $record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber }); |
784 |
warning_is { C4::Biblio::EmbedItemsInMarcBiblio() } |
785 |
{ carped => 'EmbedItemsInMarcBiblio: No MARC record passed' }, |
786 |
'Should carp is no record passed.'; |
787 |
|
788 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
789 |
marc_record => $record, |
790 |
biblionumber => $biblio->biblionumber }); |
791 |
my @items = $record->field($itemfield); |
792 |
is( scalar @items, $number_of_items, 'Should return all items' ); |
793 |
|
794 |
my $marc_with_items = C4::Biblio::GetMarcBiblio({ |
795 |
biblionumber => $biblio->biblionumber, |
796 |
embed_items => 1 }); |
797 |
is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches'); |
798 |
|
799 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
800 |
marc_record => $record, |
801 |
biblionumber => $biblio->biblionumber, |
802 |
embed_host_items => 1 |
803 |
}); |
804 |
@items = $record->field($itemfield); |
805 |
is( scalar @items, $number_of_items + 1, 'Should return all items plus host items' ); |
806 |
|
807 |
$marc_with_items = C4::Biblio::GetMarcBiblio({ |
808 |
biblionumber => $biblio->biblionumber, |
809 |
embed_items => 1, |
810 |
embed_host_items => 1 |
811 |
}); |
812 |
is_deeply( $record, $marc_with_items, 'A direct call to GetMarcBiblio with items matches'); |
813 |
|
814 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
815 |
marc_record => $record, |
816 |
biblionumber => $biblio->biblionumber, |
817 |
item_numbers => [ $itemnumbers[1], $itemnumbers[3] ] }); |
818 |
@items = $record->field($itemfield); |
819 |
is( scalar @items, 2, 'Should return all items present in the list' ); |
820 |
|
821 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
822 |
marc_record => $record, |
823 |
biblionumber => $biblio->biblionumber, |
824 |
opac => 1 }); |
825 |
@items = $record->field($itemfield); |
826 |
is( scalar @items, $number_of_items, 'Should return all items for opac' ); |
827 |
|
828 |
my $opachiddenitems = " |
829 |
homebranch: ['$library1->{branchcode}']"; |
830 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); |
831 |
|
832 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
833 |
marc_record => $record, |
834 |
biblionumber => $biblio->biblionumber }); |
835 |
@items = $record->field($itemfield); |
836 |
is( scalar @items, |
837 |
$number_of_items, |
838 |
'Even with OpacHiddenItems set, all items should have been embedded' ); |
839 |
|
840 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
841 |
marc_record => $record, |
842 |
biblionumber => $biblio->biblionumber, |
843 |
opac => 1 }); |
844 |
@items = $record->field($itemfield); |
845 |
is( |
846 |
scalar @items, |
847 |
$number_of_items - $number_of_items_with_homebranch_is_CPL, |
848 |
'For OPAC, the pref OpacHiddenItems should have been take into account. Only items with homebranch ne CPL should have been embedded' |
849 |
); |
850 |
|
851 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
852 |
marc_record => $record, |
853 |
biblionumber => $biblio->biblionumber, |
854 |
opac => 1, |
855 |
embed_host_items => 1 |
856 |
}); |
857 |
@items = $record->field($itemfield); |
858 |
is( |
859 |
scalar @items, |
860 |
$number_of_items - $number_of_items_with_homebranch_is_CPL + 1, |
861 |
'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' |
862 |
); |
863 |
|
864 |
|
865 |
$opachiddenitems = " |
866 |
homebranch: ['$library1->{branchcode}', '$library2->{branchcode}']"; |
867 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); |
868 |
C4::Biblio::EmbedItemsInMarcBiblio({ |
869 |
marc_record => $record, |
870 |
biblionumber => $biblio->biblionumber, |
871 |
opac => 1 }); |
872 |
@items = $record->field($itemfield); |
873 |
is( |
874 |
scalar @items, |
875 |
0, |
876 |
'For OPAC, If all items are hidden, no item should have been embedded' |
877 |
); |
878 |
|
879 |
$schema->storage->txn_rollback; |
880 |
}; |
881 |
|
727 |
subtest 'get_hostitemnumbers_of' => sub { |
882 |
subtest 'get_hostitemnumbers_of' => sub { |
728 |
plan tests => 3; |
883 |
plan tests => 3; |
729 |
|
884 |
|
730 |
- |
|
|