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