3 use Test::More tests => 11;
6 use_ok("MARC::Record");
7 use_ok("Koha::SimpleMARC");
10 my $record = MARC::Record->new;
11 $record->leader('03174nam a2200445 a 4500');
14 '008', '120829t20132012nyu bk 001 0ceng',
18 a => 'Knuth, Donald Ervin',
23 a => 'The art of computer programming',
24 c => 'Donald E. Knuth.',
28 a => 'Computer programming.',
39 $record->append_fields(@fields);
44 subtest 'field_exists' => sub {
46 my $record = new_record;
48 field_exists( { record => $record, field => '650', subfield => 'a' } ),
53 field_exists( { record => $record, field => '650', subfield => 'b' } ),
55 '650$b does not exist'
58 $record->append_fields(
61 a => 'Computer algorithms.',
67 field_exists( { record => $record, field => '650', subfield => 'a' } ),
69 '650$a exists, field_exists returns the 2 field numbers'
74 subtest 'read_field' => sub {
76 subtest 'read subfield' => sub {
78 my $record = new_record;
79 $record->append_fields(
82 a => 'Computer algorithms.',
88 read_field( { record => $record, field => '650', subfield => 'a' } );
89 is_deeply( $fields_650a[0], 'Computer programming.', 'first 650$a' );
90 is_deeply( $fields_650a[1], 'Computer algorithms.', 'second 650$a' );
102 ['Computer programming.'],
116 ['Computer algorithms.'],
131 'There is no 3 650$a'
134 subtest 'read field' => sub {
136 my $record = new_record;
137 $record->append_fields(
140 a => 'Computer algorithms.',
153 [ 'Computer programming.', '462', 'Computer algorithms.', '463' ],
154 'Get the all subfield values for field 650'
166 [ 'Computer programming.', '462' ],
167 'Get the all subfield values for the first field 650'
172 { record => $record, field => '650', field_numbers => [2] }
175 [ 'Computer algorithms.', '463' ],
176 'Get the all subfield values for the second field 650'
181 { record => $record, field => '650', field_numbers => [3] }
185 'Get the all subfield values for the third field 650 which does not exist'
191 subtest 'update_field' => sub {
193 subtest 'update subfield' => sub {
195 my $record = new_record;
202 values => ['3010023918']
208 { record => $record, field => '952', subfield => 'p' }
212 'update existing subfield 952$p'
214 delete_field( { record => $record, field => '952' } );
220 values => ['3010023918']
234 { record => $record, field => '952', subfield => 'p' }
238 'create subfield 952$p'
242 { record => $record, field => '952', subfield => 'y' }
245 'create subfield 952$k on existing 952 field'
248 $record->append_fields(
260 values => ['3010023919']
264 read_field( { record => $record, field => '952', subfield => 'p' } );
267 [ '3010023919', '3010023919' ],
268 'update all subfields 952$p with the same value'
276 values => [ '3010023917', '3010023918' ]
280 read_field( { record => $record, field => '952', subfield => 'p' } );
283 [ '3010023917', '3010023918' ],
284 'update all subfields 952$p with the different values'
289 # copy_field - subfield
290 subtest 'copy_field' => sub {
292 subtest 'copy subfield' => sub {
294 my $record = new_record;
295 $record->append_fields(
298 a => 'Computer algorithms.',
306 from_subfield => 'a',
314 { record => $record, field => '245', subfield => 'a' }
317 ['The art of computer programming'],
318 'After copy 245$a still exists'
323 { record => $record, field => '246', subfield => 'a' }
326 ['The art of computer programming'],
327 '246$a is a new field'
329 delete_field( { record => $record, field => '246' } );
332 { record => $record, field => '246', subfield => 'a' }
335 '246$a does not exist anymore'
342 from_subfield => 'a',
348 read_field( { record => $record, field => '651', subfield => 'a' } );
351 [ 'Computer programming.', 'Computer algorithms.' ],
352 'Copy multivalued field'
354 delete_field( { record => $record, field => '651' } );
360 from_subfield => 'a',
369 { record => $record, field => '651', subfield => 'a' }
372 ['Computer programming.'],
373 'Copy first field 650$a'
375 delete_field( { record => $record, field => '652' } );
381 from_subfield => 'a',
390 { record => $record, field => '651', subfield => 'a' }
393 ['Computer programming.', 'Computer algorithms.'],
394 'Copy second field 650$a'
396 delete_field( { record => $record, field => '651' } );
402 from_subfield => 'a',
405 regex => { search => 'Computer', replace => 'The art of' }
409 read_field( { record => $record, field => '651', subfield => 'a' } );
412 [ 'The art of programming.', 'The art of algorithms.' ],
413 'Copy field using regex'
415 delete_field( { record => $record, field => '651' } );
421 from_subfield => 'a',
424 regex => { search => 'Computer', replace => 'The mistake of' }
428 read_field( { record => $record, field => '651', subfield => 'a' } );
431 [ 'The mistake of programming.', 'The mistake of algorithms.' ],
432 'Copy fields using regex on existing fields'
434 delete_field( { record => $record, field => '651' } );
440 from_subfield => 'a',
443 regex => { search => 'Computer', replace => 'The art of' }
447 read_field( { record => $record, field => '651', subfield => 'a' } );
450 [ 'The art of programming.', 'The art of algorithms.', ],
451 'Copy all fields using regex'
453 delete_field( { record => $record, field => '651' } );
459 from_subfield => 'a',
462 regex => { search => 'Computer', replace => 'The art of' },
467 read_field( { record => $record, field => '651', subfield => 'a' } );
470 [ 'The art of programming.', ],
471 'Copy first field using regex'
473 delete_field( { record => $record, field => '651' } );
475 # Copy with regex modifiers
476 $record = new_record;
477 $record->append_fields(
480 a => 'Computer algorithms.',
488 from_subfield => 'a',
491 regex => { search => 'o', replace => 'foo' }
495 read_field( { record => $record, field => '652', subfield => 'a' } );
498 [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ],
499 'Copy field using regex'
506 from_subfield => 'a',
509 regex => { search => 'o', replace => 'foo', modifiers => 'g' }
513 read_field( { record => $record, field => '653', subfield => 'a' } );
516 [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ],
517 'Copy field using regex'
524 from_subfield => 'a',
527 regex => { search => 'O', replace => 'foo', modifiers => 'i' }
531 read_field( { record => $record, field => '654', subfield => 'a' } );
534 [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ],
535 'Copy field using regex'
542 from_subfield => 'a',
545 regex => { search => 'O', replace => 'foo', modifiers => 'gi' }
549 read_field( { record => $record, field => '655', subfield => 'a' } );
552 [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ],
553 'Copy field using regex'
556 $record = new_record;
557 $record->append_fields(
569 from_subfield => 'd',
575 read_field( { record => $record, field => '952', subfield => 'd' } );
576 # FIXME We need a new action "duplicate" if we don't want to modify the original field
579 [ '2001-06-25', '2001-06-25', '2001-06-25' ],
580 'copy 952$d into others 952 field'
587 from_subfield => '1',
593 read_field( { record => $record, field => '999', subfield => '9' } );
594 is_deeply( \@fields_9999, [],
595 'copy a nonexistent subfield does not create a new one' );
597 $record = new_record;
602 from_subfield => 'a',
605 regex => { search => '^', replace => 'BEGIN ' }
611 { record => $record, field => '245', subfield => 'a' }
614 ['The art of computer programming', 'BEGIN The art of computer programming'],
615 'Update a subfield: add a string at the beginning'
618 $record = new_record;
623 from_subfield => 'a',
626 regex => { search => '$', replace => ' END' }
632 { record => $record, field => '245', subfield => 'a' }
635 ['The art of computer programming', 'The art of computer programming END'],
636 'Update a subfield: add a string at the end'
639 $record = new_record;
644 from_subfield => 'c',
653 { record => $record, field => '650' }
656 [ 'Computer programming.', '462', 'Donald E. Knuth.' ],
657 'Copy a subfield to an existent field but inexistent subfield'
660 $record = new_record;
665 from_subfield => 'c',
674 { record => $record, field => '650' }
677 [ 'Computer programming.', '462', 'Donald E. Knuth.' ],
678 'Copy a subfield to an existent field / subfield'
682 subtest 'copy field' => sub {
684 my $record = new_record;
685 $record->append_fields(
695 { record => $record, from_field => '952', to_field => '953' } );
696 my @fields_952 = read_field( { record => $record, field => '952' } );
700 { record => $record, field => '952', field_numbers => [1] }
703 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
704 "copy all: original first field still exists"
709 { record => $record, field => '952', field_numbers => [2] }
712 [ '3010023918', 'CD' ],
713 "copy all: original second field still exists"
718 { record => $record, field => '953', field_numbers => [1] }
721 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
722 "copy all: first original fields has been copied"
727 { record => $record, field => '953', field_numbers => [2] }
730 [ '3010023918', 'CD' ],
731 "copy all: second original fields has been copied"
734 #- copy only the first field
746 { record => $record, field => '953', field_numbers => [1] }
749 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
750 "copy first: first original fields has been copied"
755 { record => $record, field => '953', field_numbers => [2] }
758 [ '3010023918', 'CD' ],
759 "copy first: second original fields has been copied"
762 [ read_field( { record => $record, field => '954' } ) ],
763 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
764 "copy first: only first, first 953 has been copied"
767 $record = new_record;
768 $record->append_fields(
776 #- copy all fields and modify values using a regex
782 regex => { search => '30100', replace => '42424' }
788 { record => $record, field => '952', field_numbers => [1] }
791 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
792 "copy all with regex: original first field still exists"
797 { record => $record, field => '952', field_numbers => [2] }
800 [ '3010023918', 'CD' ],
801 "copy all with regex: original second field still exists"
806 { record => $record, field => '953', field_numbers => [1] }
809 [ '4242423917', 'BK', 'GEN', '2001-06-25' ],
810 "copy all with regex: first original fields has been copied"
815 { record => $record, field => '953', field_numbers => [2] }
818 [ '4242423918', 'CD' ],
819 "copy all with regex: second original fields has been copied"
829 read_field( { record => $record, field => '999', subfield => '9' } );
830 is_deeply( \@fields_9999, [],
831 'copy a nonexistent field does not create a new one' );
833 $record = new_record;
845 { record => $record, field => '650', field_numbers => [2] }
848 [ 'The art of computer programming', 'Donald E. Knuth.' ],
849 'Copy a field to existent fields should create a new field'
854 { record => $record, field => '650', field_numbers => [1] }
857 [ 'Computer programming.', '462' ],
858 'Copy a field to existent fields should create a new field, the original one should not have been updated'
863 # copy_and_replace_field - subfield
864 subtest 'copy_and_replace_field' => sub {
866 subtest 'copy and replace subfield' => sub {
868 my $record = new_record;
869 $record->append_fields(
872 a => 'Computer algorithms.',
876 copy_and_replace_field(
880 from_subfield => 'a',
888 { record => $record, field => '245', subfield => 'a' }
891 ['The art of computer programming'],
892 'Copy and replace should not have modify original subfield 245$a (same as copy)'
897 { record => $record, field => '246', subfield => 'a' }
900 ['The art of computer programming'],
901 'Copy and replace should create a new 246$a (same as copy)'
904 $record = new_record;
905 $record->append_fields(
908 a => 'Computer algorithms.',
912 copy_and_replace_field(
916 from_subfield => 'a',
922 read_field( { record => $record, field => '651', subfield => 'a' } );
925 [ 'Computer programming.', 'Computer algorithms.' ],
926 'Copy and replace multivalued field (same as copy)'
928 delete_field( { record => $record, field => '651' } );
930 copy_and_replace_field(
934 from_subfield => 'a',
943 { record => $record, field => '651', subfield => 'a' }
946 ['Computer programming.'],
947 'Copy and replace first field 650$a should only copy the 1st (same as copy)'
950 copy_and_replace_field(
954 from_subfield => 'a',
963 { record => $record, field => '651', subfield => 'a' }
966 ['Computer algorithms.'],
967 'Copy and replace second field 650$a should erase 651$a'
969 delete_field( { record => $record, field => '651' } );
971 copy_and_replace_field(
975 from_subfield => 'a',
978 regex => { search => 'Computer', replace => 'The art of' }
982 read_field( { record => $record, field => '651', subfield => 'a' } );
985 [ 'The art of programming.', 'The art of algorithms.' ],
986 'Copy and replace field using regex (same as copy)'
988 delete_field( { record => $record, field => '651' } );
990 copy_and_replace_field(
994 from_subfield => 'a',
997 regex => { search => 'Computer', replace => 'The mistake of' }
1001 read_field( { record => $record, field => '651', subfield => 'a' } );
1004 [ 'The mistake of programming.', 'The mistake of algorithms.' ],
1005 'Copy and replace fields using regex on existing fields (same as copy)'
1007 delete_field( { record => $record, field => '651' } );
1009 copy_and_replace_field(
1012 from_field => '650',
1013 from_subfield => 'a',
1016 regex => { search => 'Computer', replace => 'The art of' }
1020 read_field( { record => $record, field => '651', subfield => 'a' } );
1023 [ 'The art of programming.', 'The art of algorithms.', ],
1024 'Copy and replace all fields using regex (same as copy)'
1026 delete_field( { record => $record, field => '651' } );
1028 copy_and_replace_field(
1031 from_field => '650',
1032 from_subfield => 'a',
1035 regex => { search => 'Computer', replace => 'The art of' },
1036 field_numbers => [1]
1040 read_field( { record => $record, field => '651', subfield => 'a' } );
1043 [ 'The art of programming.', ],
1044 'Copy and replace first field using regex (same as copy)'
1046 delete_field( { record => $record, field => '651' } );
1048 # Copy and replace with regex modifiers
1049 $record = new_record;
1050 $record->append_fields(
1053 a => 'Computer algorithms.',
1057 copy_and_replace_field(
1060 from_field => '650',
1061 from_subfield => 'a',
1064 regex => { search => 'o', replace => 'foo' }
1068 read_field( { record => $record, field => '652', subfield => 'a' } );
1071 [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ],
1072 'Copy and replace field using regex (same as copy)'
1075 copy_and_replace_field(
1078 from_field => '650',
1079 from_subfield => 'a',
1082 regex => { search => 'o', replace => 'foo', modifiers => 'g' }
1086 read_field( { record => $record, field => '653', subfield => 'a' } );
1089 [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ],
1090 'Copy and replace field using regex (same as copy)'
1093 copy_and_replace_field(
1096 from_field => '650',
1097 from_subfield => 'a',
1100 regex => { search => 'O', replace => 'foo', modifiers => 'i' }
1104 read_field( { record => $record, field => '654', subfield => 'a' } );
1107 [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ],
1108 'Copy and replace field using regex (same as copy)'
1111 copy_and_replace_field(
1114 from_field => '650',
1115 from_subfield => 'a',
1118 regex => { search => 'O', replace => 'foo', modifiers => 'gi' }
1122 read_field( { record => $record, field => '655', subfield => 'a' } );
1125 [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ],
1126 'Copy and replace field using regex (same as copy)'
1129 $record = new_record;
1130 $record->append_fields(
1138 copy_and_replace_field(
1141 from_field => '952',
1142 from_subfield => 'd',
1148 read_field( { record => $record, field => '952', subfield => 'd' } );
1151 [ '2001-06-25', '2001-06-25' ],
1152 'copy and replace 952$d into others 952 field'
1155 copy_and_replace_field(
1158 from_field => '111',
1159 from_subfield => '1',
1165 read_field( { record => $record, field => '999', subfield => '9' } );
1166 is_deeply( \@fields_9999, [],
1167 'copy and replace a nonexistent subfield does not create a new one (same as copy)' );
1169 $record = new_record;
1170 copy_and_replace_field(
1174 from_subfield => 'a',
1177 regex => { search => '^', replace => 'BEGIN ' }
1180 # This is the same as update the subfield
1184 { record => $record, field => '245', subfield => 'a' }
1187 ['BEGIN The art of computer programming'],
1188 'Copy and replace - Update a subfield: add a string at the beginning'
1191 $record = new_record;
1192 copy_and_replace_field(
1196 from_subfield => 'a',
1199 regex => { search => '$', replace => ' END' }
1202 # This is the same as update the subfield
1206 { record => $record, field => '245', subfield => 'a' }
1209 ['The art of computer programming END'],
1210 'Copy and replace - Update a subfield: add a string at the end'
1213 $record = new_record;
1214 copy_and_replace_field(
1218 from_subfield => 'c',
1227 { record => $record, field => '650' }
1230 [ 'Computer programming.', '462', 'Donald E. Knuth.' ],
1231 'Copy and replace a subfield to an existent field but inexistent subfield (same as copy)'
1234 $record = new_record;
1235 copy_and_replace_field(
1239 from_subfield => 'c',
1248 { record => $record, field => '650' }
1251 [ 'Computer programming.', 'Donald E. Knuth.' ],
1252 'Copy and replace a subfield to an existent field / subfield, the origin subfield is replaced'
1256 subtest 'copy and replace field' => sub {
1258 my $record = new_record;
1259 $record->append_fields(
1268 copy_and_replace_field(
1269 { record => $record, from_field => '952', to_field => '953' } );
1270 my @fields_952 = read_field( { record => $record, field => '952' } );
1274 { record => $record, field => '952', field_numbers => [1] }
1277 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
1278 "copy all: original first field still exists (same as copy)"
1283 { record => $record, field => '952', field_numbers => [2] }
1286 [ '3010023918', 'CD' ],
1287 "copy all: original second field still exists (same as copy)"
1292 { record => $record, field => '953', field_numbers => [1] }
1295 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
1296 "copy all: first original fields has been copied (same as copy)"
1301 { record => $record, field => '953', field_numbers => [2] }
1304 [ '3010023918', 'CD' ],
1305 "copy all: second original fields has been copied (same as copy)"
1308 #- copy only the first field
1309 copy_and_replace_field(
1312 from_field => '953',
1314 field_numbers => [1]
1320 { record => $record, field => '953', field_numbers => [1] }
1323 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
1324 "copy and replace first: first original fields has been copied (same as copy)"
1329 { record => $record, field => '953', field_numbers => [2] }
1332 [ '3010023918', 'CD' ],
1333 "copy and replace first: second original fields has been copied (same as copy)"
1336 [ read_field( { record => $record, field => '954' } ) ],
1337 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
1338 "copy and replace first: only first, first 953 has been copied (same as copy)"
1341 $record = new_record;
1342 $record->append_fields(
1350 #- copy and replace all fields and modify values using a regex
1351 copy_and_replace_field(
1354 from_field => '952',
1356 regex => { search => '30100', replace => '42424' }
1362 { record => $record, field => '952', field_numbers => [1] }
1365 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
1366 "copy and replace all with regex: original first field still exists (same as copy)"
1371 { record => $record, field => '952', field_numbers => [2] }
1374 [ '3010023918', 'CD' ],
1375 "copy and replace all with regex: original second field still exists (same as copy)"
1380 { record => $record, field => '953', field_numbers => [1] }
1383 [ '4242423917', 'BK', 'GEN', '2001-06-25' ],
1384 "copy and replace all with regex: first original fields has been copied (same as copy)"
1389 { record => $record, field => '953', field_numbers => [2] }
1392 [ '4242423918', 'CD' ],
1393 "copy and replace all with regex: second original fields has been copied (same as copy)"
1395 copy_and_replace_field(
1398 from_field => '111',
1403 read_field( { record => $record, field => '999', subfield => '9' } );
1404 is_deeply( \@fields_9999, [],
1405 'copy and replace a nonexistent field does not create a new one (same as copy)' );
1407 $record = new_record;
1408 copy_and_replace_field(
1419 { record => $record, field => '650', field_numbers => [1] }
1422 [ 'The art of computer programming', 'Donald E. Knuth.' ],
1423 'Copy and replace to an existent field should erase the original field'
1428 { record => $record, field => '650', field_numbers => [2] }
1432 'Copy and replace to an existent field should not create a new field'
1437 # move_field - subfields
1438 subtest 'move_field' => sub {
1440 subtest 'move subfield' => sub {
1442 my $record = new_record;
1443 my ( @fields_952d, @fields_952c, @fields_954c, @fields_954p );
1444 $record->append_fields(
1454 from_field => '952',
1455 from_subfield => 'c',
1461 read_field( { record => $record, field => '952', subfield => 'c' } );
1463 read_field( { record => $record, field => '954', subfield => 'c' } );
1464 is_deeply( \@fields_952c, [], 'The 952$c has moved' );
1465 is_deeply( \@fields_954c, ['GEN'], 'Now 954$c exists' );
1470 from_field => '952',
1471 from_subfield => 'p',
1474 field_numbers => [1]
1476 ); # Move the first field
1478 read_field( { record => $record, field => '952', subfield => 'p' } );
1480 read_field( { record => $record, field => '954', subfield => 'p' } );
1481 is_deeply( \@fields_952p, ['3010023917'], 'One of 952$p has moved' );
1482 is_deeply( \@fields_954p, ['3010023917'], 'Now 954$p exists' );
1484 $record = new_record;
1485 $record->append_fields(
1496 from_field => '952',
1497 from_subfield => 'p',
1503 read_field( { record => $record, field => '952', subfield => 'p' } );
1505 read_field( { record => $record, field => '954', subfield => 'p' } );
1506 is_deeply( \@fields_952p, [], 'All 952$p have moved' );
1509 [ '3010023917', '3010023917' ],
1516 from_field => '111',
1517 from_subfield => '1',
1523 read_field( { record => $record, field => '999', subfield => '9' } );
1524 is_deeply( \@fields_9999, [],
1525 'move a nonexistent subfield does not create a new one' );
1528 subtest 'move field' => sub {
1531 # move_field - fields
1532 my $record = new_record;
1533 $record->append_fields(
1543 { record => $record, from_field => '952', to_field => '953' } );
1544 is_deeply( [ read_field( { record => $record, field => '952' } ) ],
1545 [], "original fields don't exist" );
1549 { record => $record, field => '953', field_numbers => [1] }
1552 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
1553 "first original fields has been copied"
1558 { record => $record, field => '953', field_numbers => [2] }
1561 [ '3010023917', 'BK' ],
1562 "second original fields has been copied"
1565 #- Move only the first field
1569 from_field => '953',
1571 field_numbers => [1]
1575 [ read_field( { record => $record, field => '953' } ) ],
1576 [ '3010023917', 'BK' ],
1577 "only first, the second 953 still exists"
1580 [ read_field( { record => $record, field => '954' } ) ],
1581 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
1582 "only first, first 953 has been copied"
1585 $record = new_record;
1586 $record->append_fields(
1594 #- Move all fields and modify values using a regex
1598 from_field => '952',
1600 regex => { search => 'BK', replace => 'DVD' }
1603 is_deeply( [ read_field( { record => $record, field => '952' } ) ],
1604 [], "use a regex, original fields don't exist" );
1608 { record => $record, field => '953', field_numbers => [1] }
1611 [ '3010023917', 'DVD', 'GEN', '2001-06-25' ],
1612 "use a regex, first original fields has been copied"
1617 { record => $record, field => '953', field_numbers => [2] }
1620 [ '3010023917', 'DVD' ],
1621 "use a regex, second original fields has been copied"
1627 from_field => '111',
1632 read_field( { record => $record, field => '999', subfield => '9' } );
1633 is_deeply( \@fields_9999, [],
1634 'move a nonexistent field does not create a new one' );
1640 subtest 'delete_field' => sub {
1642 subtest 'delete subfield' => sub {
1644 my $record = new_record;
1645 $record->append_fields(
1658 field_numbers => [1]
1662 read_field( { record => $record, field => '952', subfield => 'p' } );
1663 is_deeply( \@fields_952p, ['3010023917'], 'Delete first 952$p' );
1665 $record = new_record;
1666 $record->append_fields(
1673 delete_field( { record => $record, field => '952', subfield => 'p' } );
1675 read_field( { record => $record, field => '952', subfield => 'p' } );
1676 is_deeply( \@fields_952p, [], 'Delete all 952$p' );
1679 subtest 'delete field' => sub {
1681 my $record = new_record;
1682 delete_field( { record => $record, field => '952' } );
1683 my @fields_952 = read_field( { record => $record, field => '952' } );
1684 is_deeply( \@fields_952, [], 'Delete all 952, 1 deleted' );
1686 $record = new_record;
1687 $record->append_fields(
1694 delete_field( { record => $record, field => '952' } );
1695 @fields_952 = read_field( { record => $record, field => '952' } );
1696 is_deeply( \@fields_952, [], 'Delete all 952, 2 deleted' );
1700 subtest 'field_equals' => sub {
1702 my $record = new_record;
1703 subtest 'standard MARC fields' => sub {
1705 my $match = Koha::SimpleMARC::field_equals({
1711 is_deeply( $match, [], '100$a not equal to "Donald"' );
1713 $match = Koha::SimpleMARC::field_equals({
1720 is_deeply( $match, [1], 'first 100$a matches "Donald"');
1723 subtest 'control fields' => sub {
1725 my $match = Koha::SimpleMARC::field_equals({
1731 is_deeply( $match, [], '008 control field not equal to "eng"' );
1733 $match = Koha::SimpleMARC::field_equals({
1740 is_deeply( $match, [1], 'first 008 control field matches "eng"' );