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 |
- |
|
|