View | Details | Raw Unified | Return to bug 20664
Collapse All | Expand All

(-)a/t/db_dependent/Items.t (-4 / +97 lines)
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
use Test::Warn;
39
use Test::Warn;
39
40
40
my $schema = Koha::Database->new->schema;
41
my $schema = Koha::Database->new->schema;
Lines 888-899 subtest 'tests for GetMarcItem' => sub { Link Here
888
            cn_sort          => "",
889
            cn_sort          => "",
889
        }
890
        }
890
    });
891
    });
891
    my ($itemtag, $item_num_subfield )=C4::Biblio::GetMarcFromKohaField("items.itemnumber");
892
    my $get_itemnumber = $item1->itemnumber;
892
    my $get_itemnumber = $item1->itemnumber;
893
    my $item1_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item1->itemnumber );
893
    my $item1_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item1->itemnumber );
894
    my (undef, undef, $itemnumber2 ) = AddItemFromMarc( $item1_marc, $biblio->{biblionumber} );
894
    my (undef, undef, $itemnumber2 ) = AddItemFromMarc( $item1_marc, $biblio->{biblionumber} );
895
    my $item2_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $itemnumber2 );
895
    my $item2_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $itemnumber2 );
896
    ($itemtag, $item_num_subfield )=C4::Biblio::GetMarcFromKohaField("items.itemnumber"); #get itemnumber tag
896
    my ($itemtag, $item_num_subfield )=C4::Biblio::GetMarcFromKohaField("items.itemnumber"); #get itemnumber tag
897
    $item1_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #and remove it
897
    $item1_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #and remove it
898
    $item2_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #because it won't match
898
    $item2_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #because it won't match
899
    is_deeply( $item1_marc, $item2_marc, "The Marc should match if the items are the same");
899
    is_deeply( $item1_marc, $item2_marc, "The Marc should match if the items are the same");
Lines 901-906 subtest 'tests for GetMarcItem' => sub { Link Here
901
901
902
};
902
};
903
903
904
subtest 'tests for GetMarcItemFields' => sub {
905
906
    plan tests => 5;
907
908
    $schema->storage->txn_begin;
909
    #Setup the information we need
910
    my $builder  = t::lib::TestBuilder->new;
911
    my $library  = $builder->build({ source => 'Branch', });
912
    my $itemtype = $builder->build({ source => 'Itemtype', });
913
    my $biblio   = $builder->build({
914
        source => 'Biblio',
915
        value=>{
916
            frameworkcode => "",
917
        }
918
    });
919
    my $biblioitem = $builder->build({
920
        source => 'Biblioitem',
921
        value => { biblionumber => $biblio->{biblionumber} },
922
    });
923
    my @items;
924
    my $item1 = $builder->build_object({
925
        class => 'Koha::Items',
926
        value => {
927
            biblionumber     => $biblio->{biblionumber},
928
            biblioitemnumber => $biblioitem->{biblioitemnumber},
929
            itype            => $itemtype->{itemtype},
930
            homebranch       => $library->{branchcode},
931
            barcode          => undef,
932
            restricted       => 1,
933
            itemcallnumber   => "",
934
            cn_sort          => "",
935
            withdrawn        => 0,
936
        }
937
    });
938
    push @items, GetItem( $item1->itemnumber );
939
    my $item2 = $builder->build_object({
940
        class => 'Koha::Items',
941
        value => {
942
            biblionumber     => $biblio->{biblionumber},
943
            biblioitemnumber => $biblioitem->{biblioitemnumber},
944
            itype            => $itemtype->{itemtype},
945
            homebranch       => $library->{branchcode},
946
            barcode          => undef,
947
            restricted       => 1,
948
            itemcallnumber   => "",
949
            cn_sort          => "",
950
            withdrawn        => 0,
951
        }
952
    });
953
    push @items, GetItem( $item2->itemnumber );
954
    my $item3 = $builder->build_object({
955
        class => 'Koha::Items',
956
        value => {
957
            biblionumber     => $biblio->{biblionumber},
958
            biblioitemnumber => $biblioitem->{biblioitemnumber},
959
            itype            => $itemtype->{itemtype},
960
            homebranch       => $library->{branchcode},
961
            barcode          => undef,
962
            restricted       => 1,
963
            itemcallnumber   => "",
964
            cn_sort          => "",
965
            withdrawn        => 1,
966
        }
967
    });
968
    push @items, GetItem( $item3->itemnumber );
969
970
    #Get the marc for our items individually for comparison later
971
    my $item1_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item1->itemnumber );
972
    my $item2_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item2->itemnumber );
973
    my $item3_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item3->itemnumber );
974
    my ($itemtag, $item_num_subfield )=C4::Biblio::GetMarcFromKohaField("items.itemnumber"); #get itemnumber tag
975
    $item1_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #and remove it
976
    $item2_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #because it won't match
977
978
    #Testing with hidden items
979
    my $opachiddenitems = "
980
        withdrawn: [1]";
981
    my $hidingrules = YAML::Load($opachiddenitems);
982
    my $marc_items = C4::Items::GetMarcItemFields( $biblio->{biblionumber}, [], $hidingrules );
983
    @$marc_items[0]->delete_subfield(code => $item_num_subfield);
984
    @$marc_items[1]->delete_subfield(code => $item_num_subfield);
985
    is(scalar @$marc_items, 2, "We should not get a hidden item");
986
    is_deeply( $item1_marc->field($itemtag), @$marc_items[0], "We should get the first item");
987
    is_deeply( $item2_marc->field($itemtag), @$marc_items[1], "We should also get the second item");
988
989
    #Testing with specified items
990
    $marc_items = C4::Items::GetMarcItemFields( $biblio->{biblionumber}, [ $item3->itemnumber ], undef );
991
    is(scalar @$marc_items,1,"We should only get the specifically requested item");
992
    is_deeply( $item3_marc->field($itemtag), @$marc_items[0], "We should get the third item when explicitly requested");
993
994
    $schema->storage->txn_rollback;
995
996
};
997
904
# Helper method to set up a Biblio.
998
# Helper method to set up a Biblio.
905
sub get_biblio {
999
sub get_biblio {
906
    my ( $frameworkcode ) = @_;
1000
    my ( $frameworkcode ) = @_;
907
- 

Return to bug 20664