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

(-)a/Koha/Biblio.pm (-89 / +104 lines)
Lines 1921-2069 sub generate_marc_host_field { Link Here
1921
1921
1922
    my $marcflavour = C4::Context->preference('marcflavour');
1922
    my $marcflavour = C4::Context->preference('marcflavour');
1923
    my $marc_host   = $self->metadata->record;
1923
    my $marc_host   = $self->metadata->record;
1924
    my %sfd;
1924
1925
    my @sfd;    # array of subfields to preserve order
1925
    my $host_field;
1926
    my $host_field;
1926
    my $link_field;
1927
    my $link_field;
1927
1928
1928
    if ( $marcflavour eq 'MARC21' ) {
1929
    if ( $marcflavour eq 'MARC21' ) {
1929
1930
1930
        # Author
1931
        # Attempt to clone the main entry (100, 110, or 111)
1931
        if ( $host_field = $marc_host->field('100') || $marc_host->field('110') || $marc_host->field('111') ) {
1932
        my $main_entry = $marc_host->field('100') || $marc_host->field('110') || $marc_host->field('111');
1932
            my $s = $host_field->as_string('ab');
1933
        $main_entry = $main_entry ? $main_entry->clone : undef;
1933
            if ($s) {
1934
1934
                $sfd{a} = $s;
1935
        # Clean unwanted subfields based on tag type
1936
        if ($main_entry) {
1937
            if ( $main_entry->tag eq '111' ) {
1938
                $main_entry->delete_subfield( code => qr/[94j]/ );
1939
            } else {
1940
                $main_entry->delete_subfield( code => qr/[94e]/ );
1935
            }
1941
            }
1936
        }
1942
        }
1937
1943
1938
        # Edition
1944
        # Construct subfield 7 from leader and main entry tag
1939
        if ( $host_field = $marc_host->field('250') ) {
1945
        my $s7 = "nn" . substr( $marc_host->leader, 6, 2 );
1940
            my $s = $host_field->as_string('ab');
1946
        if ($main_entry) {
1941
            if ($s) {
1947
            my $c1 = 'n';
1942
                $sfd{b} = $s;
1948
            if ( $main_entry->tag =~ /^1[01]/ ) {
1949
                $c1 = $main_entry->indicator('1');
1950
                $c1 = $main_entry->tag eq '100' ? 1 : 2 unless $c1 =~ /\d/;
1943
            }
1951
            }
1952
            my $c0 =
1953
                  ( $main_entry->tag eq '100' ) ? 'p'
1954
                : ( $main_entry->tag eq '110' ) ? 'c'
1955
                : ( $main_entry->tag eq '111' ) ? 'm'
1956
                :                                 'u';
1957
            substr( $s7, 0, 2, $c0 . $c1 );
1944
        }
1958
        }
1959
        push @sfd, '7' => $s7;
1945
1960
1946
        # Publication
1961
        # Subfield a - cleaned main entry string
1947
        if ( $host_field = $marc_host->field('260') ) {
1962
        if ($main_entry) {
1948
            my $s = $host_field->as_string('abc');
1963
            my $a = $main_entry->as_string;
1949
            if ($s) {
1964
            $a =~ s/\.$// unless $a =~ /\b[a-z]{1,2}\.$/i;
1950
                $sfd{d} = $s;
1965
            push @sfd, 'a' => $a;
1951
            }
1952
        }
1966
        }
1953
1967
1954
        # Uniform title
1968
        # Subfield t - title from 245, cleaned
1955
        if ( $host_field = $marc_host->field('240') ) {
1969
        if ( my $f245 = $marc_host->field('245') ) {
1956
            my $s = $host_field->as_string('a');
1970
            my $f245c = $f245->clone;
1957
            if ($s) {
1971
            $f245c->delete_subfield( code => 'c' );
1958
                $sfd{s} = $s;
1972
            my $t = $f245c->as_string;
1959
            }
1973
            $t =~ s/[\s\/\\.]+$//;
1974
            my $nonfiling = $f245c->indicator('2') // 0;
1975
            $t = ucfirst substr( $t, $nonfiling );
1976
            push @sfd, 't' => $t;
1960
        }
1977
        }
1961
1978
1962
        # Title
1979
        # Subfield b - edition from 250
1963
        if ( $host_field = $marc_host->field('245') ) {
1980
        if ( my $f250 = $marc_host->field('250') ) {
1964
            my $s = $host_field->as_string('ab');
1981
            my $b = $f250->as_string;
1965
            if ($s) {
1982
            $b =~ s/\.$//;
1966
                $sfd{t} = $s;
1983
            push @sfd, 'b' => $b;
1967
            }
1968
        }
1984
        }
1969
1985
1970
        # ISSN
1986
        # Subfield d - publication info from 260
1971
        if ( $host_field = $marc_host->field('022') ) {
1987
        if ( my $f260 = $marc_host->field('260') ) {
1972
            my $s = $host_field->as_string('a');
1988
            my $d = $f260->as_string('abc');
1973
            if ($s) {
1989
            $d =~ s/\.$//;
1974
                $sfd{x} = $s;
1990
            push @sfd, 'd' => $d;
1975
            }
1976
        }
1991
        }
1977
1992
1978
        # ISBN
1993
        # Subfield k - host info from 800-830 fields
1979
        if ( $host_field = $marc_host->field('020') ) {
1994
        for my $f ( $marc_host->field('8[013][01]') ) {
1980
            my $s = $host_field->as_string('a');
1995
            my $k = $f->as_string('abcdnjltnp');
1981
            if ($s) {
1996
            $k .= ', ISSN ' . $f->subfield('x') if $f->subfield('x');
1982
                $sfd{z} = $s;
1997
            $k .= ' ; ' . $f->subfield('v')     if $f->subfield('v');
1983
            }
1998
            push @sfd, 'k' => $k;
1984
        }
1999
        }
1985
        if ( C4::Context->preference('UseControlNumber') ) {
1986
2000
1987
            # Control number
2001
        # Subfield x - ISSN from 022
1988
            if ( $host_field = $marc_host->field('001') ) {
2002
        for my $f ( $marc_host->field('022') ) {
1989
                $sfd{w} = $host_field->data();
2003
            push @sfd, 'x' => $f->subfield('a') if $f->subfield('a');
1990
            }
2004
        }
2005
2006
        # Subfield z - ISBN from 020
2007
        for my $f ( $marc_host->field('020') ) {
2008
            push @sfd, 'z' => $f->subfield('a') if $f->subfield('a');
2009
        }
1991
2010
1992
            # Control number identifier
2011
        # Subfield w - control number (001 and optionally 003)
1993
            if ( $host_field = $marc_host->field('003') ) {
2012
        if ( C4::Context->preference('UseControlNumber') ) {
1994
                $sfd{w} = '(' . $host_field->data() . ')' . $sfd{w};
2013
            if ( my $f001 = $marc_host->field('001') ) {
2014
                my $w = $f001->data;
2015
                if ( my $f003 = $marc_host->field('003') ) {
2016
                    $w = '(' . $f003->data . ')' . $w;
2017
                }
2018
                push @sfd, 'w' => $w;
1995
            }
2019
            }
1996
        }
2020
        }
1997
        $link_field = MARC::Field->new( 773, '0', ' ', %sfd );
2021
2022
        # Construct 773 link field
2023
        $link_field = MARC::Field->new( 773, '0', ' ', @sfd );
2024
1998
    } elsif ( $marcflavour eq 'UNIMARC' ) {
2025
    } elsif ( $marcflavour eq 'UNIMARC' ) {
1999
2026
2000
        # Author
2027
        # Author (700/710/720)
2001
        if ( $host_field = $marc_host->field('700') || $marc_host->field('710') || $marc_host->field('720') ) {
2028
        if ( $host_field = $marc_host->field('700') || $marc_host->field('710') || $marc_host->field('720') ) {
2002
            my $s = $host_field->as_string('ab');
2029
            my $s = $host_field->as_string('ab');
2003
            if ($s) {
2030
            push @sfd, 'a' => $s if $s;
2004
                $sfd{a} = $s;
2031
        }
2005
            }
2032
2033
        # Title (200)
2034
        if ( $host_field = $marc_host->field('200') ) {
2035
            my $s = $host_field->as_string('a');
2036
            push @sfd, 't' => $s if $s;
2006
        }
2037
        }
2007
2038
2008
        # Place of publication
2039
        # Place of publication (210$a)
2009
        if ( $host_field = $marc_host->field('210') ) {
2040
        if ( $host_field = $marc_host->field('210') ) {
2010
            my $s = $host_field->as_string('a');
2041
            my $s = $host_field->as_string('a');
2011
            if ($s) {
2042
            push @sfd, 'c' => $s if $s;
2012
                $sfd{c} = $s;
2013
            }
2014
        }
2043
        }
2015
2044
2016
        # Date of publication
2045
        # Date of publication (210$d)
2017
        if ( $host_field = $marc_host->field('210') ) {
2046
        if ( $host_field = $marc_host->field('210') ) {
2018
            my $s = $host_field->as_string('d');
2047
            my $s = $host_field->as_string('d');
2019
            if ($s) {
2048
            push @sfd, 'd' => $s if $s;
2020
                $sfd{d} = $s;
2021
            }
2022
        }
2049
        }
2023
2050
2024
        # Edition statement
2051
        # Edition statement (205)
2025
        if ( $host_field = $marc_host->field('205') ) {
2052
        if ( $host_field = $marc_host->field('205') ) {
2026
            my $s = $host_field->as_string();
2053
            my $s = $host_field->as_string;
2027
            if ($s) {
2054
            push @sfd, 'e' => $s if $s;
2028
                $sfd{e} = $s;
2029
            }
2030
        }
2055
        }
2031
2056
2032
        # Title
2057
        # URL (856$u)
2033
        if ( $host_field = $marc_host->field('200') ) {
2034
            my $s = $host_field->as_string('a');
2035
            if ($s) {
2036
                $sfd{t} = $s;
2037
            }
2038
        }
2039
2040
        #URL
2041
        if ( $host_field = $marc_host->field('856') ) {
2058
        if ( $host_field = $marc_host->field('856') ) {
2042
            my $s = $host_field->as_string('u');
2059
            my $s = $host_field->as_string('u');
2043
            if ($s) {
2060
            push @sfd, 'u' => $s if $s;
2044
                $sfd{u} = $s;
2045
            }
2046
        }
2061
        }
2047
2062
2048
        # ISSN
2063
        # ISSN (011$a)
2049
        if ( $host_field = $marc_host->field('011') ) {
2064
        if ( $host_field = $marc_host->field('011') ) {
2050
            my $s = $host_field->as_string('a');
2065
            my $s = $host_field->as_string('a');
2051
            if ($s) {
2066
            push @sfd, 'x' => $s if $s;
2052
                $sfd{x} = $s;
2053
            }
2054
        }
2067
        }
2055
2068
2056
        # ISBN
2069
        # ISBN (010$a)
2057
        if ( $host_field = $marc_host->field('010') ) {
2070
        if ( $host_field = $marc_host->field('010') ) {
2058
            my $s = $host_field->as_string('a');
2071
            my $s = $host_field->as_string('a');
2059
            if ($s) {
2072
            push @sfd, 'y' => $s if $s;
2060
                $sfd{y} = $s;
2061
            }
2062
        }
2073
        }
2074
2075
        # Control number (001)
2063
        if ( $host_field = $marc_host->field('001') ) {
2076
        if ( $host_field = $marc_host->field('001') ) {
2064
            $sfd{0} = $host_field->data();
2077
            push @sfd, '0' => $host_field->data();
2065
        }
2078
        }
2066
        $link_field = MARC::Field->new( 461, '0', ' ', %sfd );
2079
2080
        # Construct 461 link field
2081
        $link_field = MARC::Field->new( 461, '0', ' ', @sfd );
2067
    }
2082
    }
2068
2083
2069
    return $link_field;
2084
    return $link_field;
(-)a/t/db_dependent/Koha/Biblio.t (-49 / +153 lines)
Lines 999-1074 subtest 'get_volumes_query' => sub { Link Here
999
};
999
};
1000
1000
1001
subtest 'generate_marc_host_field' => sub {
1001
subtest 'generate_marc_host_field' => sub {
1002
    plan tests => 22;
1002
    plan tests => 33;
1003
1003
1004
    $schema->storage->txn_begin;
1004
    $schema->storage->txn_begin;
1005
1005
1006
    # Set up MARC21 tests
1006
    t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' );
1007
    t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' );
1007
1008
1008
    my $biblio = $builder->build_sample_biblio();
1009
    # 1. Complete MARC21 record test
1009
    my $record = $biblio->metadata->record;
1010
    my $record = MARC::Record->new();
1011
    $record->leader('00000nam a22000007a 4500');
1010
    $record->append_fields(
1012
    $record->append_fields(
1011
        MARC::Field->new( '001', '1234' ),
1013
        MARC::Field->new( '001', '12345' ),
1012
        MARC::Field->new( '003', 'FIRST' ),
1014
        MARC::Field->new( '003', 'NB' ),
1013
        MARC::Field->new( '240', '', '', a => 'A uniform title' ),
1015
        MARC::Field->new( '020', '',  '',  'a' => '978-3-16-148410-0' ),
1014
        MARC::Field->new( '260', '', '', a => 'Publication' ),
1016
        MARC::Field->new( '022', '',  '',  'a' => '1234-5678' ),
1015
        MARC::Field->new( '250', '', '', a => 'Edition a', b => 'Edition b' ),
1017
        MARC::Field->new( '100', '1', '',  'a' => 'Smith, John',  'e' => 'author',   '9' => 'xyz', '4' => 'aut' ),
1016
        MARC::Field->new( '022', '', '', a => '0317-8471' ),
1018
        MARC::Field->new( '245', '1', '0', 'a' => 'The Title',    'b' => 'Subtitle', 'c' => 'John Smith' ),
1019
        MARC::Field->new( '250', '',  '',  'a' => '2nd edition',  'b' => 'revised' ),
1020
        MARC::Field->new( '260', '',  '',  'a' => 'New York',     'b' => 'Publisher', 'c' => '2023' ),
1021
        MARC::Field->new( '830', '',  '',  'a' => 'Series Title', 'v' => 'vol. 2',    'x' => '2345-6789' )
1017
    );
1022
    );
1018
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
1023
    my ($biblio_id) = AddBiblio( $record, qw{} );
1019
    $biblio = Koha::Biblios->find( $biblio->biblionumber );
1024
    my $biblio = Koha::Biblios->find($biblio_id);
1020
1025
1021
    t::lib::Mocks::mock_preference( 'UseControlNumber', '0' );
1026
    # Test MARC21 with UseControlNumber off
1027
    t::lib::Mocks::mock_preference( 'UseControlNumber', 0 );
1022
    my $link = $biblio->generate_marc_host_field();
1028
    my $link = $biblio->generate_marc_host_field();
1023
1029
1024
    is( ref($link),           'MARC::Field',         "->generate_marc_host_field returns a MARC::Field object" );
1030
    # Test standard MARC21 field
1025
    is( $link->tag,           '773',                 "MARC::Field->tag returns '773' when marcflavour is 'MARC21" );
1031
    is( ref($link),          'MARC::Field', 'Returns a MARC::Field object' );
1026
    is( $link->subfield('a'), 'Some boring author',  'MARC::Field->subfield(a) returns content from 100ab' );
1032
    is( $link->tag(),        '773',         'Field tag is 773 for MARC21' );
1027
    is( $link->subfield('b'), 'Edition a Edition b', 'MARC::Field->subfield(b) returns content from 250ab' );
1033
    is( $link->indicator(1), '0',           'First indicator is 0' );
1028
    is( $link->subfield('d'), 'Publication',         'MARC::Field->subfield(c) returns content from 260abc' );
1034
    is( $link->indicator(2), ' ',           'Second indicator is blank' );
1029
    is( $link->subfield('s'), 'A uniform title',     'MARC::Field->subfield(s) returns content from 240a' );
1035
1030
    is( $link->subfield('t'), 'Some boring read',    'MARC::Field->subfield(s) returns content from 245ab' );
1036
    # Check all subfields
1031
    is( $link->subfield('x'), '0317-8471',           'MARC::Field->subfield(s) returns content from 022a' );
1037
    is( $link->subfield('7'), 'p1am',        'Subfield 7 correctly formed' );
1032
    is( $link->subfield('z'), undef,                 'MARC::Field->subfield(s) returns undef when 020a is empty' );
1038
    is( $link->subfield('a'), 'Smith, John', 'Subfield a contains author from 100a' );
1033
    is( $link->subfield('w'), undef, 'MARC::Field->subfield(w) returns undef when "UseControlNumber" is disabled' );
1039
    is(
1040
        $link->subfield('t'), 'The Title Subtitle',
1041
        'Subfield t contains title without trailing punctuation from 245ab'
1042
    );
1043
    is( $link->subfield('b'), '2nd edition revised',     'Subfield b contains edition info from 250ab' );
1044
    is( $link->subfield('d'), 'New York Publisher 2023', 'Subfield d contains publication info from 260abc' );
1045
    is( $link->subfield('k'), 'Series Title, ISSN 2345-6789 ; vol. 2', 'Subfield k contains series info from 830' );
1046
    is( $link->subfield('x'), '1234-5678',                             'Subfield x contains ISSN from 022a' );
1047
    is( $link->subfield('z'), '978-3-16-148410-0',                     'Subfield z contains ISBN from 020a' );
1048
    is( $link->subfield('w'), undef, 'Subfield w is undefined when UseControlNumber is disabled' );
1034
1049
1050
    # Test with UseControlNumber enabled
1035
    t::lib::Mocks::mock_preference( 'UseControlNumber', '1' );
1051
    t::lib::Mocks::mock_preference( 'UseControlNumber', '1' );
1036
    $link = $biblio->generate_marc_host_field();
1052
    $link = $biblio->generate_marc_host_field();
1037
    is(
1053
    is(
1038
        $link->subfield('w'), '(FIRST)1234',
1054
        $link->subfield('w'), '(NB)12345',
1039
        'MARC::Field->subfield(w) returns content from 003 and 001 when "UseControlNumber" is enabled'
1055
        'Subfield w contains control number with source when UseControlNumber is enabled'
1040
    );
1056
    );
1041
1057
1042
    # UNIMARC tests
1058
    # 245 punctuation handling tests
1043
    t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' );
1059
    # Trailing slash
1060
    $record->field('245')->update( a => 'A title /', b => '', c => '', 'ind2' => '0' );
1061
    ($biblio_id) = AddBiblio( $record, qw{} );
1062
    $biblio = Koha::Biblios->find($biblio_id);
1063
    $link   = $biblio->generate_marc_host_field();
1064
    is( $link->subfield('t'), 'A title', "Trailing slash is removed from 245a" );
1044
1065
1045
    $biblio = $builder->build_sample_biblio();
1066
    # Trailing period
1046
    $record = $biblio->metadata->record;
1067
    $record->field('245')->update( a => 'Another title.', 'ind2' => '0' );
1047
    $record->append_fields(
1068
    ($biblio_id) = AddBiblio( $record, qw{} );
1048
        MARC::Field->new( '001', '1234' ),
1069
    $biblio = Koha::Biblios->find($biblio_id);
1049
        MARC::Field->new( '700', '', '', a => 'A nice author' ),
1070
    $link   = $biblio->generate_marc_host_field();
1050
        MARC::Field->new( '210', '', '', a => 'A publication', d => 'A date' ),
1071
    is( $link->subfield('t'), 'Another title', "Trailing period is removed from 245a" );
1051
        MARC::Field->new( '205', '', '', a => "Fun things" ),
1072
1052
        MARC::Field->new( '856', '', '', u => 'http://myurl.com/' ),
1073
    # Offset from indicator 2 = 4
1053
        MARC::Field->new( '011', '', '', a => '0317-8471' ),
1074
    $record->field('245')->update( a => 'The offset title', 'ind2' => '4' );
1054
        MARC::Field->new( '545', '', '', a => 'Invisible on OPAC' ),
1075
    ($biblio_id) = AddBiblio( $record, qw{} );
1076
    $biblio = Koha::Biblios->find($biblio_id);
1077
    $link   = $biblio->generate_marc_host_field();
1078
    is( $link->subfield('t'), 'Offset title', "Title offset applied from indicator 2" );
1079
1080
    # Capitalization after offset
1081
    $record->field('245')->update( a => 'the capital test', 'ind2' => '0' );
1082
    ($biblio_id) = AddBiblio( $record, qw{} );
1083
    $biblio = Koha::Biblios->find($biblio_id);
1084
    $link   = $biblio->generate_marc_host_field();
1085
    is( $link->subfield('t'), 'The capital test', "Title is capitalized after indicator offset" );
1086
1087
    # 2. Test MARC21 with corporate author (110)
1088
    my $record_corporate = MARC::Record->new();
1089
    $record_corporate->leader('00000nam a22000007a 4500');
1090
    $record_corporate->append_fields(
1091
        MARC::Field->new( '110', '2', '',  'a' => 'Corporate Author', 'e' => 'sponsor', '9' => 'xyz', '4' => 'spn' ),
1092
        MARC::Field->new( '245', '1', '0', 'a' => 'The Title' )
1055
    );
1093
    );
1056
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
1094
    ($biblio_id) = AddBiblio( $record_corporate, qw{} );
1095
    $biblio = Koha::Biblios->find($biblio_id);
1096
1097
    $link = $biblio->generate_marc_host_field();
1098
    is( $link->subfield('7'), 'c2am',             'Subfield 7 correctly formed for corporate author' );
1099
    is( $link->subfield('a'), 'Corporate Author', 'Subfield a contains corporate author' );
1100
1101
    # 3. Test MARC21 with meeting name (111)
1102
    my $record_meeting = MARC::Record->new();
1103
    $record_meeting->leader('00000nam a22000007a 4500');
1104
    $record_meeting->append_fields(
1105
        MARC::Field->new( '111', '2', '',  'a' => 'Conference Name', 'j' => 'relator', '9' => 'xyz', '4' => 'spn' ),
1106
        MARC::Field->new( '245', '1', '0', 'a' => 'The Title' )
1107
    );
1108
    ($biblio_id) = AddBiblio( $record_meeting, qw{} );
1109
    $biblio = Koha::Biblios->find($biblio_id);
1110
1111
    $link = $biblio->generate_marc_host_field();
1112
    is( $link->subfield('7'), 'm2am', 'Subfield 7 correctly formed for meeting name' );
1113
1114
    # 4. Test MARC21 with minimal record
1115
    my $record_minimal = MARC::Record->new();
1116
    $record_minimal->leader('00000nam a22000007a 4500');
1117
    $record_minimal->append_fields( MARC::Field->new( '245', '0', '0', 'a' => 'Title Only' ) );
1118
    ($biblio_id) = AddBiblio( $record_minimal, qw{} );
1119
    $biblio = Koha::Biblios->find($biblio_id);
1120
1121
    $link = $biblio->generate_marc_host_field();
1122
    is( $link->subfield('7'), 'nnam', 'Subfield 7 correctly formed with no main entry' );
1123
1124
    # 5. Test UNIMARC
1125
    t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' );
1126
    $biblio = $builder->build_sample_biblio();
1127
    my $record_unimarc = MARC::Record->new();
1128
    $record_unimarc->append_fields(
1129
        MARC::Field->new( '001', '54321' ),
1130
        MARC::Field->new( '010', '', '', 'a' => '978-0-12-345678-9' ),
1131
        MARC::Field->new( '011', '', '', 'a' => '2345-6789' ),
1132
        MARC::Field->new( '200', '', '', 'a' => 'UNIMARC Title' ),
1133
        MARC::Field->new( '205', '', '', 'a' => 'Third edition' ),
1134
        MARC::Field->new( '210', '', '', 'a' => 'Paris', 'd' => '2023' ),
1135
        MARC::Field->new( '700', '', '', 'a' => 'Doe',   'b' => 'Jane' ),
1136
        MARC::Field->new( '856', '', '', 'u' => 'http://example.com' )
1137
    );
1138
    ($biblio_id) = AddBiblio( $record_unimarc, qw{} );
1139
    $biblio = Koha::Biblios->find($biblio_id);
1140
1141
    $link = $biblio->generate_marc_host_field();
1142
1143
    is( ref($link),          'MARC::Field', 'Returns a MARC::Field object for UNIMARC' );
1144
    is( $link->tag(),        '461',         'Field tag is 461 for UNIMARC' );
1145
    is( $link->indicator(1), '0',           'First indicator is 0 for UNIMARC' );
1146
    is( $link->indicator(2), ' ',           'Second indicator is blank for UNIMARC' );
1147
1148
    # Check UNIMARC subfields
1149
    is( $link->subfield('a'), 'Doe Jane',      'Subfield a contains author for UNIMARC' );
1150
    is( $link->subfield('t'), 'UNIMARC Title', 'Subfield t contains title for UNIMARC' );
1151
    is( $link->subfield('c'), 'Paris',         'Subfield c contains place of publication for UNIMARC' );
1152
    is( $link->subfield('d'), '2023',          'Subfield d contains date of publication for UNIMARC' );
1153
    is( $link->subfield('0'), '54321',         'Subfield 0 contains control number for UNIMARC' );
1154
1155
    # 6. Test UNIMARC with different author types
1156
    my $record_unimarc_corporate = MARC::Record->new();
1157
    $record_unimarc_corporate->append_fields(
1158
        MARC::Field->new( '710', '', '', 'a' => 'Corporate', 'b' => 'Department' ),
1159
        MARC::Field->new( '200', '', '', 'a' => 'Title' )
1160
    );
1161
    C4::Biblio::ModBiblio( $record_unimarc_corporate, $biblio->biblionumber );
1057
    $biblio = Koha::Biblios->find( $biblio->biblionumber );
1162
    $biblio = Koha::Biblios->find( $biblio->biblionumber );
1058
1163
1059
    $link = $biblio->generate_marc_host_field();
1164
    $link = $biblio->generate_marc_host_field();
1165
    is( $link->subfield('a'), 'Corporate Department', 'Subfield a contains corporate author for UNIMARC' );
1166
1167
    my $record_unimarc_family = MARC::Record->new();
1168
    $record_unimarc_family->append_fields(
1169
        MARC::Field->new( '720', '', '', 'a' => 'Family', 'b' => 'Name' ),
1170
        MARC::Field->new( '200', '', '', 'a' => 'Title' )
1171
    );
1172
    C4::Biblio::ModBiblio( $record_unimarc_family, $biblio->biblionumber );
1173
    $biblio = Koha::Biblios->find( $biblio->biblionumber );
1060
1174
1061
    is( ref($link),           'MARC::Field',       "->generate_marc_host_field returns a MARC::Field object" );
1175
    $link = $biblio->generate_marc_host_field();
1062
    is( $link->tag,           '461',               "MARC::Field->tag returns '461' when marcflavour is 'UNIMARC" );
1176
    is( $link->subfield('a'), 'Family Name', 'Subfield a contains family name for UNIMARC' );
1063
    is( $link->subfield('a'), 'A nice author',     'MARC::Field->subfield(a) returns content from 700ab' );
1064
    is( $link->subfield('c'), 'A publication',     'MARC::Field->subfield(b) returns content from 210a' );
1065
    is( $link->subfield('d'), 'A date',            'MARC::Field->subfield(c) returns content from 210d' );
1066
    is( $link->subfield('e'), 'Fun things',        'MARC::Field->subfield(s) returns content from 205' );
1067
    is( $link->subfield('t'), 'Some boring read',  'MARC::Field->subfield(s) returns content from 200a' );
1068
    is( $link->subfield('u'), 'http://myurl.com/', 'MARC::Field->subfield(s) returns content from 856u' );
1069
    is( $link->subfield('x'), '0317-8471',         'MARC::Field->subfield(s) returns content from 011a' );
1070
    is( $link->subfield('y'), undef,               'MARC::Field->subfield(w) returns undef if 010a is empty' );
1071
    is( $link->subfield('0'), '1234',              'MARC::Field->subfield(0) returns content from 001' );
1072
1177
1073
    $schema->storage->txn_rollback;
1178
    $schema->storage->txn_rollback;
1074
    t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' );
1179
    t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' );
1075
- 

Return to bug 39545