Lines 32-38
use C4::Items;
Link Here
|
32 |
use t::lib::Mocks; |
32 |
use t::lib::Mocks; |
33 |
use t::lib::TestBuilder; |
33 |
use t::lib::TestBuilder; |
34 |
|
34 |
|
35 |
use Test::More tests => 15; |
35 |
use Test::More tests => 16; |
36 |
|
36 |
|
37 |
use Test::Warn; |
37 |
use Test::Warn; |
38 |
|
38 |
|
Lines 868-874
subtest 'tests for GetMarcItem' => sub {
Link Here
|
868 |
cn_sort => "", |
868 |
cn_sort => "", |
869 |
} |
869 |
} |
870 |
}); |
870 |
}); |
871 |
my ($itemtag, $item_num_subfield )=C4::Biblio::GetMarcFromKohaField("items.itemnumber",""); |
|
|
872 |
my $get_itemnumber = $item1->itemnumber; |
871 |
my $get_itemnumber = $item1->itemnumber; |
873 |
my $item1_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item1->itemnumber ); |
872 |
my $item1_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item1->itemnumber ); |
874 |
my (undef, undef, $itemnumber2 ) = AddItemFromMarc( $item1_marc, $biblio->{biblionumber} ); |
873 |
my (undef, undef, $itemnumber2 ) = AddItemFromMarc( $item1_marc, $biblio->{biblionumber} ); |
Lines 881-886
subtest 'tests for GetMarcItem' => sub {
Link Here
|
881 |
|
880 |
|
882 |
}; |
881 |
}; |
883 |
|
882 |
|
|
|
883 |
subtest 'tests for GetMarcItems' => sub { |
884 |
|
885 |
plan tests => 5; |
886 |
|
887 |
$schema->storage->txn_begin; |
888 |
#Setup the information we need |
889 |
my $builder = t::lib::TestBuilder->new; |
890 |
my $library = $builder->build({ source => 'Branch', }); |
891 |
my $itemtype = $builder->build({ source => 'Itemtype', }); |
892 |
my $biblio = $builder->build({ |
893 |
source => 'Biblio', |
894 |
value=>{ |
895 |
frameworkcode => "", |
896 |
} |
897 |
}); |
898 |
my $biblioitem = $builder->build({ |
899 |
source => 'Biblioitem', |
900 |
value => { biblionumber => $biblio->{biblionumber} }, |
901 |
}); |
902 |
my @items; |
903 |
my $item1 = $builder->build_object({ |
904 |
class => 'Koha::Items', |
905 |
value => { |
906 |
biblionumber => $biblio->{biblionumber}, |
907 |
biblioitemnumber => $biblioitem->{biblioitemnumber}, |
908 |
itype => $itemtype->{itemtype}, |
909 |
homebranch => $library->{branchcode}, |
910 |
barcode => undef, |
911 |
restricted => 1, |
912 |
itemcallnumber => "", |
913 |
cn_sort => "", |
914 |
withdrawn => 0, |
915 |
} |
916 |
}); |
917 |
push @items, GetItem( $item1->itemnumber ); |
918 |
my $item2 = $builder->build_object({ |
919 |
class => 'Koha::Items', |
920 |
value => { |
921 |
biblionumber => $biblio->{biblionumber}, |
922 |
biblioitemnumber => $biblioitem->{biblioitemnumber}, |
923 |
itype => $itemtype->{itemtype}, |
924 |
homebranch => $library->{branchcode}, |
925 |
barcode => undef, |
926 |
restricted => 1, |
927 |
itemcallnumber => "", |
928 |
cn_sort => "", |
929 |
withdrawn => 0, |
930 |
} |
931 |
}); |
932 |
push @items, GetItem( $item2->itemnumber ); |
933 |
my $item3 = $builder->build_object({ |
934 |
class => 'Koha::Items', |
935 |
value => { |
936 |
biblionumber => $biblio->{biblionumber}, |
937 |
biblioitemnumber => $biblioitem->{biblioitemnumber}, |
938 |
itype => $itemtype->{itemtype}, |
939 |
homebranch => $library->{branchcode}, |
940 |
barcode => undef, |
941 |
restricted => 1, |
942 |
itemcallnumber => "", |
943 |
cn_sort => "", |
944 |
withdrawn => 1, |
945 |
} |
946 |
}); |
947 |
push @items, GetItem( $item3->itemnumber ); |
948 |
|
949 |
#Get the marc for our items individually for comparison later |
950 |
my $item1_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item1->itemnumber ); |
951 |
my $item2_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item2->itemnumber ); |
952 |
my $item3_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item3->itemnumber ); |
953 |
my ($itemtag, $item_num_subfield )=C4::Biblio::GetMarcFromKohaField("items.itemnumber",""); #get itemnumber tag |
954 |
$item1_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #and remove it |
955 |
$item2_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #because it won't match |
956 |
|
957 |
#Testing with hidden items |
958 |
my $opachiddenitems = " |
959 |
withdrawn: [1]"; |
960 |
t::lib::Mocks::mock_preference( 'OpacHiddenItems', $opachiddenitems ); |
961 |
my @hidden = GetHiddenItemnumbers( @items ); |
962 |
my $marc_items = C4::Items::GetMarcItems( $biblio->{biblionumber}, \@hidden ); |
963 |
@$marc_items[0]->delete_subfield(code => $item_num_subfield); |
964 |
@$marc_items[1]->delete_subfield(code => $item_num_subfield); |
965 |
is(scalar @$marc_items,2,"We should not get a hidden item"); |
966 |
is_deeply( $item1_marc->field($itemtag), @$marc_items[0], "We should get the first item"); |
967 |
is_deeply( $item2_marc->field($itemtag), @$marc_items[1], "We should also get the second item"); |
968 |
|
969 |
#Testing with specified items |
970 |
$marc_items = C4::Items::GetMarcItems( $biblio->{biblionumber}, undef ,[ $item3->itemnumber ] ); |
971 |
is(scalar @$marc_items,1,"We should only get the specifically requested item"); |
972 |
is_deeply( $item3_marc->field($itemtag), @$marc_items[0], "We should get the third item when explicitly requested"); |
973 |
|
974 |
$schema->storage->txn_rollback; |
975 |
|
976 |
}; |
977 |
|
884 |
# Helper method to set up a Biblio. |
978 |
# Helper method to set up a Biblio. |
885 |
sub get_biblio { |
979 |
sub get_biblio { |
886 |
my ( $frameworkcode ) = @_; |
980 |
my ( $frameworkcode ) = @_; |
887 |
- |
|
|