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

(-)a/t/db_dependent/Items.t (-4 / +94 lines)
Lines 34-40 use Koha::AuthorisedValues; 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 => 16;
37
use Test::More tests => 17;
38
38
39
use Test::Warn;
39
use Test::Warn;
40
40
Lines 1023-1036 subtest 'tests for GetMarcItem' => sub { Link Here
1023
            cn_sort          => "",
1023
            cn_sort          => "",
1024
        }
1024
        }
1025
    });
1025
    });
1026
    my ($itemtag, $item_num_subfield )=C4::Biblio::GetMarcFromKohaField("items.itemnumber");
1027
    my $get_itemnumber = $item1->itemnumber;
1026
    my $get_itemnumber = $item1->itemnumber;
1028
    my $item1_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item1->itemnumber );
1027
    my $item1_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item1->itemnumber );
1029
    my (undef, undef, $itemnumber2 ) = AddItemFromMarc( $item1_marc, $biblio->{biblionumber} );
1028
    my (undef, undef, $itemnumber2 ) = AddItemFromMarc( $item1_marc, $biblio->{biblionumber} );
1030
    my $item2_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $itemnumber2 );
1029
    my $item2_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $itemnumber2 );
1031
    ($itemtag, $item_num_subfield )=C4::Biblio::GetMarcFromKohaField("items.itemnumber"); #get itemnumber tag
1030
    my ($itemtag, $item_num_subfield )=C4::Biblio::GetMarcFromKohaField("items.itemnumber"); #get itemnumber tag
1032
    $item1_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #and remove it
1031
    $item1_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #and remove it
1033
    $item2_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #because it won't match
1032
    $item2_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #because it won't match
1034
    is_deeply( $item1_marc, $item2_marc, "The Marc should match if the items are the same");
1033
    is_deeply( $item1_marc, $item2_marc, "The Marc should match if the items are the same");
1035
    $schema->storage->txn_rollback;
1034
    $schema->storage->txn_rollback;
1036
};
1035
};
1037
- 
1036
1037
subtest 'tests for GetMarcItemFields' => sub {
1038
    plan tests => 5;
1039
    $schema->storage->txn_begin;
1040
1041
    #Setup the information we need
1042
    my $builder  = t::lib::TestBuilder->new;
1043
    my $library  = $builder->build({ source => 'Branch', });
1044
    my $itemtype = $builder->build({ source => 'Itemtype', });
1045
    my $biblio   = $builder->build({
1046
        source => 'Biblio',
1047
        value=>{
1048
            frameworkcode => "",
1049
        }
1050
    });
1051
    my $biblioitem = $builder->build({
1052
        source => 'Biblioitem',
1053
        value => { biblionumber => $biblio->{biblionumber} },
1054
    });
1055
    my @items;
1056
    my $item1 = $builder->build_object({
1057
        class => 'Koha::Items',
1058
        value => {
1059
            biblionumber     => $biblio->{biblionumber},
1060
            biblioitemnumber => $biblioitem->{biblioitemnumber},
1061
            itype            => $itemtype->{itemtype},
1062
            homebranch       => $library->{branchcode},
1063
            barcode          => undef,
1064
            restricted       => 1,
1065
            itemcallnumber   => "",
1066
            cn_sort          => "",
1067
            withdrawn        => 0,
1068
        }
1069
    });
1070
    push @items, GetItem( $item1->itemnumber );
1071
    my $item2 = $builder->build_object({
1072
        class => 'Koha::Items',
1073
        value => {
1074
            biblionumber     => $biblio->{biblionumber},
1075
            biblioitemnumber => $biblioitem->{biblioitemnumber},
1076
            itype            => $itemtype->{itemtype},
1077
            homebranch       => $library->{branchcode},
1078
            barcode          => undef,
1079
            restricted       => 1,
1080
            itemcallnumber   => "",
1081
            cn_sort          => "",
1082
            withdrawn        => 0,
1083
        }
1084
    });
1085
    push @items, GetItem( $item2->itemnumber );
1086
    my $item3 = $builder->build_object({
1087
        class => 'Koha::Items',
1088
        value => {
1089
            biblionumber     => $biblio->{biblionumber},
1090
            biblioitemnumber => $biblioitem->{biblioitemnumber},
1091
            itype            => $itemtype->{itemtype},
1092
            homebranch       => $library->{branchcode},
1093
            barcode          => undef,
1094
            restricted       => 1,
1095
            itemcallnumber   => "",
1096
            cn_sort          => "",
1097
            withdrawn        => 1,
1098
        }
1099
    });
1100
    push @items, GetItem( $item3->itemnumber );
1101
1102
    #Get the marc for our items individually for comparison later
1103
    my $item1_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item1->itemnumber );
1104
    my $item2_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item2->itemnumber );
1105
    my $item3_marc = C4::Items::GetMarcItem( $biblio->{biblionumber}, $item3->itemnumber );
1106
    my ($itemtag, $item_num_subfield )=C4::Biblio::GetMarcFromKohaField("items.itemnumber"); #get itemnumber tag
1107
    $item1_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #and remove it
1108
    $item2_marc->field($itemtag)->delete_subfield(code => $item_num_subfield); #because it won't match
1109
1110
    #Testing with hidden items
1111
    my $opachiddenitems = "
1112
        withdrawn: [1]";
1113
    my $hidingrules = YAML::Load($opachiddenitems);
1114
    my $marc_items = C4::Items::GetMarcItemFields( $biblio->{biblionumber}, [], $hidingrules );
1115
    @$marc_items[0]->delete_subfield(code => $item_num_subfield);
1116
    @$marc_items[1]->delete_subfield(code => $item_num_subfield);
1117
    is(scalar @$marc_items, 2, "We should not get a hidden item");
1118
    is_deeply( $item1_marc->field($itemtag), @$marc_items[0], "We should get the first item");
1119
    is_deeply( $item2_marc->field($itemtag), @$marc_items[1], "We should also get the second item");
1120
1121
    #Testing with specified items
1122
    $marc_items = C4::Items::GetMarcItemFields( $biblio->{biblionumber}, [ $item3->itemnumber ], undef );
1123
    is(scalar @$marc_items,1,"We should only get the specifically requested item");
1124
    is_deeply( $item3_marc->field($itemtag), @$marc_items[0], "We should get the third item when explicitly requested");
1125
1126
    $schema->storage->txn_rollback;
1127
};

Return to bug 20664