Lines 1016-1061
subtest 'get_volumes_query' => sub {
Link Here
|
1016 |
}; |
1016 |
}; |
1017 |
|
1017 |
|
1018 |
subtest 'generate_marc_host_field' => sub { |
1018 |
subtest 'generate_marc_host_field' => sub { |
1019 |
plan tests => 24; |
1019 |
plan tests => 35; |
1020 |
|
1020 |
|
1021 |
$schema->storage->txn_begin; |
1021 |
$schema->storage->txn_begin; |
1022 |
|
1022 |
|
|
|
1023 |
# Set up MARC21 tests |
1023 |
t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); |
1024 |
t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); |
1024 |
|
1025 |
|
1025 |
my $biblio = $builder->build_sample_biblio(); |
1026 |
# 1. Complete MARC21 record test |
1026 |
my $record = $biblio->metadata->record; |
1027 |
my $record = MARC::Record->new(); |
|
|
1028 |
$record->leader('00000nam a22000007a 4500'); |
1027 |
$record->append_fields( |
1029 |
$record->append_fields( |
1028 |
MARC::Field->new( '001', '1234' ), |
1030 |
MARC::Field->new( '001', '12345' ), |
1029 |
MARC::Field->new( '003', 'FIRST' ), |
1031 |
MARC::Field->new( '003', 'NB' ), |
1030 |
MARC::Field->new( '240', '', '', a => 'A uniform title' ), |
1032 |
MARC::Field->new( '020', '', '', 'a' => '978-3-16-148410-0' ), |
1031 |
MARC::Field->new( '260', '', '', a => 'Publication 260' ), |
1033 |
MARC::Field->new( '022', '', '', 'a' => '1234-5678' ), |
1032 |
MARC::Field->new( '250', '', '', a => 'Edition a', b => 'Edition b' ), |
1034 |
MARC::Field->new( '100', '1', '', 'a' => 'Smith, John', 'e' => 'author', '9' => 'xyz', '4' => 'aut' ), |
1033 |
MARC::Field->new( '022', '', '', a => '0317-8471' ), |
1035 |
MARC::Field->new( '245', '1', '0', 'a' => 'The Title', 'b' => 'Subtitle', 'c' => 'John Smith' ), |
|
|
1036 |
MARC::Field->new( '250', '', '', 'a' => '2nd edition', 'b' => 'revised' ), |
1037 |
MARC::Field->new( '260', '', '', 'a' => 'New York', 'b' => 'Publisher', 'c' => '2023' ), |
1038 |
MARC::Field->new( '830', '', '', 'a' => 'Series Title', 'v' => 'vol. 2', 'x' => '2345-6789' ) |
1034 |
); |
1039 |
); |
1035 |
C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); |
1040 |
my ($biblio_id) = AddBiblio( $record, qw{} ); |
1036 |
$biblio = Koha::Biblios->find( $biblio->biblionumber ); |
1041 |
my $biblio = Koha::Biblios->find($biblio_id); |
1037 |
|
1042 |
|
1038 |
t::lib::Mocks::mock_preference( 'UseControlNumber', '0' ); |
1043 |
# Test MARC21 with UseControlNumber off |
|
|
1044 |
t::lib::Mocks::mock_preference( 'UseControlNumber', 0 ); |
1039 |
my $link = $biblio->generate_marc_host_field(); |
1045 |
my $link = $biblio->generate_marc_host_field(); |
1040 |
|
1046 |
|
1041 |
is( ref($link), 'MARC::Field', "->generate_marc_host_field returns a MARC::Field object" ); |
1047 |
# Test standard MARC21 field |
1042 |
is( $link->tag, '773', "MARC::Field->tag returns '773' when marcflavour is 'MARC21" ); |
1048 |
is( ref($link), 'MARC::Field', 'Returns a MARC::Field object' ); |
1043 |
is( $link->subfield('a'), 'Some boring author', 'MARC::Field->subfield(a) returns content from 100ab' ); |
1049 |
is( $link->tag(), '773', 'Field tag is 773 for MARC21' ); |
1044 |
is( $link->subfield('b'), 'Edition a Edition b', 'MARC::Field->subfield(b) returns content from 250ab' ); |
1050 |
is( $link->indicator(1), '0', 'First indicator is 0' ); |
1045 |
is( $link->subfield('d'), 'Publication 260', 'MARC::Field->subfield(c) returns content from 260abc' ); |
1051 |
is( $link->indicator(2), ' ', 'Second indicator is blank' ); |
1046 |
is( $link->subfield('s'), 'A uniform title', 'MARC::Field->subfield(s) returns content from 240a' ); |
1052 |
|
1047 |
is( $link->subfield('t'), 'Some boring read', 'MARC::Field->subfield(s) returns content from 245ab' ); |
1053 |
# Check all subfields |
1048 |
is( $link->subfield('x'), '0317-8471', 'MARC::Field->subfield(s) returns content from 022a' ); |
1054 |
is( $link->subfield('7'), 'p1am', 'Subfield 7 correctly formed' ); |
1049 |
is( $link->subfield('z'), undef, 'MARC::Field->subfield(s) returns undef when 020a is empty' ); |
1055 |
is( $link->subfield('a'), 'Smith, John', 'Subfield a contains author from 100a' ); |
1050 |
is( $link->subfield('w'), undef, 'MARC::Field->subfield(w) returns undef when "UseControlNumber" is disabled' ); |
1056 |
is( |
|
|
1057 |
$link->subfield('t'), 'The Title Subtitle', |
1058 |
'Subfield t contains title without trailing punctuation from 245ab' |
1059 |
); |
1060 |
is( $link->subfield('b'), '2nd edition revised', 'Subfield b contains edition info from 250ab' ); |
1061 |
is( $link->subfield('d'), 'New York Publisher 2023', 'Subfield d contains publication info from 260abc' ); |
1062 |
is( $link->subfield('k'), 'Series Title, ISSN 2345-6789 ; vol. 2', 'Subfield k contains series info from 830' ); |
1063 |
is( $link->subfield('x'), '1234-5678', 'Subfield x contains ISSN from 022a' ); |
1064 |
is( $link->subfield('z'), '978-3-16-148410-0', 'Subfield z contains ISBN from 020a' ); |
1065 |
is( $link->subfield('w'), undef, 'Subfield w is undefined when UseControlNumber is disabled' ); |
1051 |
|
1066 |
|
|
|
1067 |
# Test with UseControlNumber enabled |
1052 |
t::lib::Mocks::mock_preference( 'UseControlNumber', '1' ); |
1068 |
t::lib::Mocks::mock_preference( 'UseControlNumber', '1' ); |
1053 |
$link = $biblio->generate_marc_host_field(); |
1069 |
$link = $biblio->generate_marc_host_field(); |
1054 |
is( |
1070 |
is( |
1055 |
$link->subfield('w'), '(FIRST)1234', |
1071 |
$link->subfield('w'), '(NB)12345', |
1056 |
'MARC::Field->subfield(w) returns content from 003 and 001 when "UseControlNumber" is enabled' |
1072 |
'Subfield w contains control number with source when UseControlNumber is enabled' |
1057 |
); |
1073 |
); |
1058 |
|
1074 |
|
|
|
1075 |
# 245 punctuation handling tests |
1076 |
# Trailing slash |
1077 |
$record->field('245')->update( a => 'A title /', b => '', c => '', 'ind2' => '0' ); |
1078 |
($biblio_id) = AddBiblio( $record, qw{} ); |
1079 |
$biblio = Koha::Biblios->find($biblio_id); |
1080 |
$link = $biblio->generate_marc_host_field(); |
1081 |
is( $link->subfield('t'), 'A title', "Trailing slash is removed from 245a" ); |
1082 |
|
1083 |
# Trailing period |
1084 |
$record->field('245')->update( a => 'Another title.', 'ind2' => '0' ); |
1085 |
($biblio_id) = AddBiblio( $record, qw{} ); |
1086 |
$biblio = Koha::Biblios->find($biblio_id); |
1087 |
$link = $biblio->generate_marc_host_field(); |
1088 |
is( $link->subfield('t'), 'Another title', "Trailing period is removed from 245a" ); |
1089 |
|
1090 |
# Offset from indicator 2 = 4 |
1091 |
$record->field('245')->update( a => 'The offset title', 'ind2' => '4' ); |
1092 |
($biblio_id) = AddBiblio( $record, qw{} ); |
1093 |
$biblio = Koha::Biblios->find($biblio_id); |
1094 |
$link = $biblio->generate_marc_host_field(); |
1095 |
is( $link->subfield('t'), 'Offset title', "Title offset applied from indicator 2" ); |
1096 |
|
1097 |
# Capitalization after offset |
1098 |
$record->field('245')->update( a => 'the capital test', 'ind2' => '0' ); |
1099 |
($biblio_id) = AddBiblio( $record, qw{} ); |
1100 |
$biblio = Koha::Biblios->find($biblio_id); |
1101 |
$link = $biblio->generate_marc_host_field(); |
1102 |
is( $link->subfield('t'), 'The capital test', "Title is capitalized after indicator offset" ); |
1103 |
|
1104 |
# 260/264 handling tests |
1059 |
$record->append_fields( |
1105 |
$record->append_fields( |
1060 |
MARC::Field->new( '264', '', '', a => 'Publication 264' ), |
1106 |
MARC::Field->new( '264', '', '', a => 'Publication 264' ), |
1061 |
); |
1107 |
); |
Lines 1080-1115
subtest 'generate_marc_host_field' => sub {
Link Here
|
1080 |
'MARC::Field->subfield(d) returns content from 264 with indicator 1 = 3 in preference to 264 without' |
1126 |
'MARC::Field->subfield(d) returns content from 264 with indicator 1 = 3 in preference to 264 without' |
1081 |
); |
1127 |
); |
1082 |
|
1128 |
|
1083 |
# UNIMARC tests |
1129 |
# 2. Test MARC21 with corporate author (110) |
1084 |
t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' ); |
1130 |
my $record_corporate = MARC::Record->new(); |
|
|
1131 |
$record_corporate->leader('00000nam a22000007a 4500'); |
1132 |
$record_corporate->append_fields( |
1133 |
MARC::Field->new( '110', '2', '', 'a' => 'Corporate Author', 'e' => 'sponsor', '9' => 'xyz', '4' => 'spn' ), |
1134 |
MARC::Field->new( '245', '1', '0', 'a' => 'The Title' ) |
1135 |
); |
1136 |
($biblio_id) = AddBiblio( $record_corporate, qw{} ); |
1137 |
$biblio = Koha::Biblios->find($biblio_id); |
1085 |
|
1138 |
|
1086 |
$biblio = $builder->build_sample_biblio(); |
1139 |
$link = $biblio->generate_marc_host_field(); |
1087 |
$record = $biblio->metadata->record; |
1140 |
is( $link->subfield('7'), 'c2am', 'Subfield 7 correctly formed for corporate author' ); |
1088 |
$record->append_fields( |
1141 |
is( $link->subfield('a'), 'Corporate Author', 'Subfield a contains corporate author' ); |
1089 |
MARC::Field->new( '001', '1234' ), |
1142 |
|
1090 |
MARC::Field->new( '700', '', '', a => 'A nice author' ), |
1143 |
# 3. Test MARC21 with meeting name (111) |
1091 |
MARC::Field->new( '210', '', '', a => 'A publication', d => 'A date' ), |
1144 |
my $record_meeting = MARC::Record->new(); |
1092 |
MARC::Field->new( '205', '', '', a => "Fun things" ), |
1145 |
$record_meeting->leader('00000nam a22000007a 4500'); |
1093 |
MARC::Field->new( '856', '', '', u => 'http://myurl.com/' ), |
1146 |
$record_meeting->append_fields( |
1094 |
MARC::Field->new( '011', '', '', a => '0317-8471' ), |
1147 |
MARC::Field->new( '111', '2', '', 'a' => 'Conference Name', 'j' => 'relator', '9' => 'xyz', '4' => 'spn' ), |
1095 |
MARC::Field->new( '545', '', '', a => 'Invisible on OPAC' ), |
1148 |
MARC::Field->new( '245', '1', '0', 'a' => 'The Title' ) |
1096 |
); |
1149 |
); |
1097 |
C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); |
1150 |
($biblio_id) = AddBiblio( $record_meeting, qw{} ); |
|
|
1151 |
$biblio = Koha::Biblios->find($biblio_id); |
1152 |
|
1153 |
$link = $biblio->generate_marc_host_field(); |
1154 |
is( $link->subfield('7'), 'm2am', 'Subfield 7 correctly formed for meeting name' ); |
1155 |
|
1156 |
# 4. Test MARC21 with minimal record |
1157 |
my $record_minimal = MARC::Record->new(); |
1158 |
$record_minimal->leader('00000nam a22000007a 4500'); |
1159 |
$record_minimal->append_fields( MARC::Field->new( '245', '0', '0', 'a' => 'Title Only' ) ); |
1160 |
($biblio_id) = AddBiblio( $record_minimal, qw{} ); |
1161 |
$biblio = Koha::Biblios->find($biblio_id); |
1162 |
|
1163 |
$link = $biblio->generate_marc_host_field(); |
1164 |
is( $link->subfield('7'), 'nnam', 'Subfield 7 correctly formed with no main entry' ); |
1165 |
|
1166 |
# 5. Test UNIMARC |
1167 |
t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' ); |
1168 |
$biblio = $builder->build_sample_biblio(); |
1169 |
my $record_unimarc = MARC::Record->new(); |
1170 |
$record_unimarc->append_fields( |
1171 |
MARC::Field->new( '001', '54321' ), |
1172 |
MARC::Field->new( '010', '', '', 'a' => '978-0-12-345678-9' ), |
1173 |
MARC::Field->new( '011', '', '', 'a' => '2345-6789' ), |
1174 |
MARC::Field->new( '200', '', '', 'a' => 'UNIMARC Title' ), |
1175 |
MARC::Field->new( '205', '', '', 'a' => 'Third edition' ), |
1176 |
MARC::Field->new( '210', '', '', 'a' => 'Paris', 'd' => '2023' ), |
1177 |
MARC::Field->new( '700', '', '', 'a' => 'Doe', 'b' => 'Jane' ), |
1178 |
MARC::Field->new( '856', '', '', 'u' => 'http://example.com' ) |
1179 |
); |
1180 |
($biblio_id) = AddBiblio( $record_unimarc, qw{} ); |
1181 |
$biblio = Koha::Biblios->find($biblio_id); |
1182 |
|
1183 |
$link = $biblio->generate_marc_host_field(); |
1184 |
|
1185 |
is( ref($link), 'MARC::Field', 'Returns a MARC::Field object for UNIMARC' ); |
1186 |
is( $link->tag(), '461', 'Field tag is 461 for UNIMARC' ); |
1187 |
is( $link->indicator(1), '0', 'First indicator is 0 for UNIMARC' ); |
1188 |
is( $link->indicator(2), ' ', 'Second indicator is blank for UNIMARC' ); |
1189 |
|
1190 |
# Check UNIMARC subfields |
1191 |
is( $link->subfield('a'), 'Doe Jane', 'Subfield a contains author for UNIMARC' ); |
1192 |
is( $link->subfield('t'), 'UNIMARC Title', 'Subfield t contains title for UNIMARC' ); |
1193 |
is( $link->subfield('c'), 'Paris', 'Subfield c contains place of publication for UNIMARC' ); |
1194 |
is( $link->subfield('d'), '2023', 'Subfield d contains date of publication for UNIMARC' ); |
1195 |
is( $link->subfield('0'), '54321', 'Subfield 0 contains control number for UNIMARC' ); |
1196 |
|
1197 |
# 6. Test UNIMARC with different author types |
1198 |
my $record_unimarc_corporate = MARC::Record->new(); |
1199 |
$record_unimarc_corporate->append_fields( |
1200 |
MARC::Field->new( '710', '', '', 'a' => 'Corporate', 'b' => 'Department' ), |
1201 |
MARC::Field->new( '200', '', '', 'a' => 'Title' ) |
1202 |
); |
1203 |
C4::Biblio::ModBiblio( $record_unimarc_corporate, $biblio->biblionumber ); |
1098 |
$biblio = Koha::Biblios->find( $biblio->biblionumber ); |
1204 |
$biblio = Koha::Biblios->find( $biblio->biblionumber ); |
1099 |
|
1205 |
|
1100 |
$link = $biblio->generate_marc_host_field(); |
1206 |
$link = $biblio->generate_marc_host_field(); |
|
|
1207 |
is( $link->subfield('a'), 'Corporate Department', 'Subfield a contains corporate author for UNIMARC' ); |
1208 |
|
1209 |
my $record_unimarc_family = MARC::Record->new(); |
1210 |
$record_unimarc_family->append_fields( |
1211 |
MARC::Field->new( '720', '', '', 'a' => 'Family', 'b' => 'Name' ), |
1212 |
MARC::Field->new( '200', '', '', 'a' => 'Title' ) |
1213 |
); |
1214 |
C4::Biblio::ModBiblio( $record_unimarc_family, $biblio->biblionumber ); |
1215 |
$biblio = Koha::Biblios->find( $biblio->biblionumber ); |
1101 |
|
1216 |
|
1102 |
is( ref($link), 'MARC::Field', "->generate_marc_host_field returns a MARC::Field object" ); |
1217 |
$link = $biblio->generate_marc_host_field(); |
1103 |
is( $link->tag, '461', "MARC::Field->tag returns '461' when marcflavour is 'UNIMARC" ); |
1218 |
is( $link->subfield('a'), 'Family Name', 'Subfield a contains family name for UNIMARC' ); |
1104 |
is( $link->subfield('a'), 'A nice author', 'MARC::Field->subfield(a) returns content from 700ab' ); |
|
|
1105 |
is( $link->subfield('c'), 'A publication', 'MARC::Field->subfield(b) returns content from 210a' ); |
1106 |
is( $link->subfield('d'), 'A date', 'MARC::Field->subfield(c) returns content from 210d' ); |
1107 |
is( $link->subfield('e'), 'Fun things', 'MARC::Field->subfield(s) returns content from 205' ); |
1108 |
is( $link->subfield('t'), 'Some boring read', 'MARC::Field->subfield(s) returns content from 200a' ); |
1109 |
is( $link->subfield('u'), 'http://myurl.com/', 'MARC::Field->subfield(s) returns content from 856u' ); |
1110 |
is( $link->subfield('x'), '0317-8471', 'MARC::Field->subfield(s) returns content from 011a' ); |
1111 |
is( $link->subfield('y'), undef, 'MARC::Field->subfield(w) returns undef if 010a is empty' ); |
1112 |
is( $link->subfield('0'), '1234', 'MARC::Field->subfield(0) returns content from 001' ); |
1113 |
|
1219 |
|
1114 |
$schema->storage->txn_rollback; |
1220 |
$schema->storage->txn_rollback; |
1115 |
t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); |
1221 |
t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); |
1116 |
- |
|
|