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

(-)a/t/db_dependent/Items.t (-4 / +94 lines)
Lines 33-39 use Koha::Caches; Link Here
33
use t::lib::Mocks;
33
use t::lib::Mocks;
34
use t::lib::TestBuilder;
34
use t::lib::TestBuilder;
35
35
36
use Test::More tests => 16;
36
use Test::More tests => 17;
37
37
38
use Test::Warn;
38
use Test::Warn;
39
39
Lines 984-997 subtest 'tests for GetMarcItem' => sub { Link Here
984
            cn_sort          => "",
984
            cn_sort          => "",
985
        }
985
        }
986
    });
986
    });
987
    my ($itemtag, $item_num_subfield )=C4::Biblio::GetMarcFromKohaField("items.itemnumber");
988
    my $get_itemnumber = $item1->itemnumber;
987
    my $get_itemnumber = $item1->itemnumber;
989
    my $item1_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item1->itemnumber );
988
    my $item1_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item1->itemnumber );
990
    my (undef, undef, $itemnumber2 ) = AddItemFromMarc( $item1_marc, $biblio->{biblionumber} );
989
    my (undef, undef, $itemnumber2 ) = AddItemFromMarc( $item1_marc, $biblio->{biblionumber} );
991
    my $item2_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $itemnumber2 );
990
    my $item2_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $itemnumber2 );
992
    ($itemtag, $item_num_subfield )=C4::Biblio::GetMarcFromKohaField("items.itemnumber"); #get itemnumber tag
991
    my ($itemtag, $item_num_subfield )=C4::Biblio::GetMarcFromKohaField("items.itemnumber"); #get itemnumber tag
993
    $item1_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #and remove it
992
    $item1_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #and remove it
994
    $item2_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #because it won't match
993
    $item2_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #because it won't match
995
    is_deeply( $item1_marc, $item2_marc, "The Marc should match if the items are the same");
994
    is_deeply( $item1_marc, $item2_marc, "The Marc should match if the items are the same");
996
    $schema->storage->txn_rollback;
995
    $schema->storage->txn_rollback;
997
};
996
};
998
- 
997
998
subtest 'tests for GetMarcItemFields' => sub {
999
    plan tests => 5;
1000
    $schema->storage->txn_begin;
1001
1002
    #Setup the information we need
1003
    my $builder  = t::lib::TestBuilder->new;
1004
    my $library  = $builder->build({ source => 'Branch', });
1005
    my $itemtype = $builder->build({ source => 'Itemtype', });
1006
    my $biblio   = $builder->build({
1007
        source => 'Biblio',
1008
        value=>{
1009
            frameworkcode => "",
1010
        }
1011
    });
1012
    my $biblioitem = $builder->build({
1013
        source => 'Biblioitem',
1014
        value => { biblionumber => $biblio->{biblionumber} },
1015
    });
1016
    my @items;
1017
    my $item1 = $builder->build_object({
1018
        class => 'Koha::Items',
1019
        value => {
1020
            biblionumber     => $biblio->{biblionumber},
1021
            biblioitemnumber => $biblioitem->{biblioitemnumber},
1022
            itype            => $itemtype->{itemtype},
1023
            homebranch       => $library->{branchcode},
1024
            barcode          => undef,
1025
            restricted       => 1,
1026
            itemcallnumber   => "",
1027
            cn_sort          => "",
1028
            withdrawn        => 0,
1029
        }
1030
    });
1031
    push @items, GetItem( $item1->itemnumber );
1032
    my $item2 = $builder->build_object({
1033
        class => 'Koha::Items',
1034
        value => {
1035
            biblionumber     => $biblio->{biblionumber},
1036
            biblioitemnumber => $biblioitem->{biblioitemnumber},
1037
            itype            => $itemtype->{itemtype},
1038
            homebranch       => $library->{branchcode},
1039
            barcode          => undef,
1040
            restricted       => 1,
1041
            itemcallnumber   => "",
1042
            cn_sort          => "",
1043
            withdrawn        => 0,
1044
        }
1045
    });
1046
    push @items, GetItem( $item2->itemnumber );
1047
    my $item3 = $builder->build_object({
1048
        class => 'Koha::Items',
1049
        value => {
1050
            biblionumber     => $biblio->{biblionumber},
1051
            biblioitemnumber => $biblioitem->{biblioitemnumber},
1052
            itype            => $itemtype->{itemtype},
1053
            homebranch       => $library->{branchcode},
1054
            barcode          => undef,
1055
            restricted       => 1,
1056
            itemcallnumber   => "",
1057
            cn_sort          => "",
1058
            withdrawn        => 1,
1059
        }
1060
    });
1061
    push @items, GetItem( $item3->itemnumber );
1062
1063
    #Get the marc for our items individually for comparison later
1064
    my $item1_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item1->itemnumber );
1065
    my $item2_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item2->itemnumber );
1066
    my $item3_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item3->itemnumber );
1067
    my ($itemtag, $item_num_subfield )=C4::Biblio::GetMarcFromKohaField("items.itemnumber"); #get itemnumber tag
1068
    $item1_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #and remove it
1069
    $item2_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #because it won't match
1070
1071
    #Testing with hidden items
1072
    my $opachiddenitems = "
1073
        withdrawn: [1]";
1074
    my $hidingrules = YAML::Load($opachiddenitems);
1075
    my $marc_items = C4::Items::GetMarcItemFields( $biblio->{biblionumber}, [], $hidingrules );
1076
    @$marc_items[0]->delete_subfield(code => $item_num_subfield);
1077
    @$marc_items[1]->delete_subfield(code => $item_num_subfield);
1078
    is(scalar @$marc_items, 2, "We should not get a hidden item");
1079
    is_deeply( $item1_marc->field($itemtag), @$marc_items[0], "We should get the first item");
1080
    is_deeply( $item2_marc->field($itemtag), @$marc_items[1], "We should also get the second item");
1081
1082
    #Testing with specified items
1083
    $marc_items = C4::Items::GetMarcItemFields( $biblio->{biblionumber}, [ $item3->itemnumber ], undef );
1084
    is(scalar @$marc_items,1,"We should only get the specifically requested item");
1085
    is_deeply( $item3_marc->field($itemtag), @$marc_items[0], "We should get the third item when explicitly requested");
1086
1087
    $schema->storage->txn_rollback;
1088
};

Return to bug 20664