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.',
92 read_field( { record => $record, field => '650', subfield => 'a' } );
93 is_deeply( $fields_650a[0], 'Computer programming.', 'first 650$a' );
94 is_deeply( $fields_650a[1], 'Computer algorithms.', 'second 650$a' );
106 ['Computer programming.'],
120 ['Computer algorithms.'],
135 'There is no 3 650$a'
152 subtest 'read field' => sub {
154 my $record = new_record;
155 $record->append_fields(
158 a => 'Computer algorithms.',
171 [ 'Computer programming.', '462', 'Computer algorithms.', '463' ],
172 'Get the all subfield values for field 650'
184 [ 'Computer programming.', '462' ],
185 'Get the all subfield values for the first field 650'
190 { record => $record, field => '650', field_numbers => [2] }
193 [ 'Computer algorithms.', '463' ],
194 'Get the all subfield values for the second field 650'
199 { record => $record, field => '650', field_numbers => [3] }
203 'Get the all subfield values for the third field 650 which does not exist'
209 subtest 'update_field' => sub {
211 subtest 'update subfield' => sub {
213 my $record = new_record;
220 values => ['3010023918']
226 { record => $record, field => '952', subfield => 'p' }
230 'update existing subfield 952$p'
232 delete_field( { record => $record, field => '952' } );
238 values => ['3010023918']
252 { record => $record, field => '952', subfield => 'p' }
256 'create subfield 952$p'
260 { record => $record, field => '952', subfield => 'y' }
263 'create subfield 952$k on existing 952 field'
266 $record->append_fields(
279 values => ['3010023919']
283 read_field( { record => $record, field => '952', subfield => 'p' } );
286 [ '3010023919', '3010023919' ],
287 'update all subfields 952$p with the same value'
295 values => [ '3010023917', '3010023918' ]
299 read_field( { record => $record, field => '952', subfield => 'p' } );
302 [ '3010023917', '3010023918' ],
303 'update all subfields 952$p with the different values'
311 values => [ '654321' ]
315 read_field( { record => $record, field => '952', subfield => '0' } );
318 [ '654321', '654321' ],
319 'update all subfields 952$0 with the same value'
325 # copy_field - subfield
326 subtest 'copy_field' => sub {
328 subtest 'copy subfield' => sub {
330 my $record = new_record;
331 $record->append_fields(
334 a => 'Computer algorithms.',
342 from_subfield => 'a',
350 { record => $record, field => '245', subfield => 'a' }
353 ['The art of computer programming'],
354 'After copy 245$a still exists'
359 { record => $record, field => '246', subfield => 'a' }
362 ['The art of computer programming'],
363 '246$a is a new field'
365 delete_field( { record => $record, field => '246' } );
368 { record => $record, field => '246', subfield => 'a' }
371 '246$a does not exist anymore'
378 from_subfield => 'a',
384 read_field( { record => $record, field => '651', subfield => 'a' } );
387 [ 'Computer programming.', 'Computer algorithms.' ],
388 'Copy multivalued field'
390 delete_field( { record => $record, field => '651' } );
396 from_subfield => 'a',
405 { record => $record, field => '651', subfield => 'a' }
408 ['Computer programming.'],
409 'Copy first field 650$a'
411 delete_field( { record => $record, field => '652' } );
417 from_subfield => 'a',
426 { record => $record, field => '651', subfield => 'a' }
429 ['Computer programming.', 'Computer algorithms.'],
430 'Copy second field 650$a'
432 delete_field( { record => $record, field => '651' } );
438 from_subfield => 'a',
441 regex => { search => 'Computer', replace => 'The art of' }
445 read_field( { record => $record, field => '651', subfield => 'a' } );
448 [ 'The art of programming.', 'The art of algorithms.' ],
449 'Copy field using regex'
451 delete_field( { record => $record, field => '651' } );
457 from_subfield => 'a',
460 regex => { search => 'Computer', replace => 'The mistake of' }
464 read_field( { record => $record, field => '651', subfield => 'a' } );
467 [ 'The mistake of programming.', 'The mistake of algorithms.' ],
468 'Copy fields using regex on existing fields'
470 delete_field( { record => $record, field => '651' } );
476 from_subfield => 'a',
479 regex => { search => 'Computer', replace => 'The art of' }
483 read_field( { record => $record, field => '651', subfield => 'a' } );
486 [ 'The art of programming.', 'The art of algorithms.', ],
487 'Copy all fields using regex'
489 delete_field( { record => $record, field => '651' } );
495 from_subfield => 'a',
498 regex => { search => 'Computer', replace => 'The art of' },
503 read_field( { record => $record, field => '651', subfield => 'a' } );
506 [ 'The art of programming.', ],
507 'Copy first field using regex'
509 delete_field( { record => $record, field => '651' } );
511 # Copy with regex modifiers
512 $record = new_record;
513 $record->append_fields(
516 a => 'Computer algorithms.',
524 from_subfield => 'a',
527 regex => { search => 'o', replace => 'foo' }
531 read_field( { record => $record, field => '652', subfield => 'a' } );
534 [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ],
535 'Copy field using regex'
542 from_subfield => 'a',
545 regex => { search => 'o', replace => 'foo', modifiers => 'g' }
549 read_field( { record => $record, field => '653', subfield => 'a' } );
552 [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ],
553 'Copy field using regex'
560 from_subfield => 'a',
563 regex => { search => 'O', replace => 'foo', modifiers => 'i' }
567 read_field( { record => $record, field => '654', subfield => 'a' } );
570 [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ],
571 'Copy field using regex'
578 from_subfield => 'a',
581 regex => { search => 'O', replace => 'foo', modifiers => 'gi' }
585 read_field( { record => $record, field => '655', subfield => 'a' } );
588 [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ],
589 'Copy field using regex'
592 $record = new_record;
593 $record->append_fields(
605 from_subfield => 'd',
611 read_field( { record => $record, field => '952', subfield => 'd' } );
612 # FIXME We need a new action "duplicate" if we don't want to modify the original field
615 [ '2001-06-25', '2001-06-25', '2001-06-25' ],
616 'copy 952$d into others 952 field'
623 from_subfield => '1',
629 read_field( { record => $record, field => '999', subfield => '9' } );
630 is_deeply( \@fields_9999, [],
631 'copy a nonexistent subfield does not create a new one' );
633 $record = new_record;
638 from_subfield => 'a',
641 regex => { search => '^', replace => 'BEGIN ' }
647 { record => $record, field => '245', subfield => 'a' }
650 ['The art of computer programming', 'BEGIN The art of computer programming'],
651 'Update a subfield: add a string at the beginning'
654 $record = new_record;
659 from_subfield => 'a',
662 regex => { search => '$', replace => ' END' }
668 { record => $record, field => '245', subfield => 'a' }
671 ['The art of computer programming', 'The art of computer programming END'],
672 'Update a subfield: add a string at the end'
675 $record = new_record;
680 from_subfield => 'c',
689 { record => $record, field => '650' }
692 [ 'Computer programming.', '462', 'Donald E. Knuth.' ],
693 'Copy a subfield to an existent field but inexistent subfield'
696 $record = new_record;
701 from_subfield => 'c',
710 { record => $record, field => '650' }
713 [ 'Computer programming.', '462', 'Donald E. Knuth.' ],
714 'Copy a subfield to an existent field / subfield'
718 subtest 'copy field' => sub {
720 my $record = new_record;
721 $record->append_fields(
731 { record => $record, from_field => '952', to_field => '953' } );
732 my @fields_952 = read_field( { record => $record, field => '952' } );
736 { record => $record, field => '952', field_numbers => [1] }
739 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
740 "copy all: original first field still exists"
745 { record => $record, field => '952', field_numbers => [2] }
748 [ '3010023918', 'CD' ],
749 "copy all: original second field still exists"
754 { record => $record, field => '953', field_numbers => [1] }
757 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
758 "copy all: first original fields has been copied"
763 { record => $record, field => '953', field_numbers => [2] }
766 [ '3010023918', 'CD' ],
767 "copy all: second original fields has been copied"
770 #- copy only the first field
782 { record => $record, field => '953', field_numbers => [1] }
785 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
786 "copy first: first original fields has been copied"
791 { record => $record, field => '953', field_numbers => [2] }
794 [ '3010023918', 'CD' ],
795 "copy first: second original fields has been copied"
798 [ read_field( { record => $record, field => '954' } ) ],
799 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
800 "copy first: only first, first 953 has been copied"
803 $record = new_record;
804 $record->append_fields(
812 #- copy all fields and modify values using a regex
818 regex => { search => '30100', replace => '42424' }
824 { record => $record, field => '952', field_numbers => [1] }
827 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
828 "copy all with regex: original first field still exists"
833 { record => $record, field => '952', field_numbers => [2] }
836 [ '3010023918', 'CD' ],
837 "copy all with regex: original second field still exists"
842 { record => $record, field => '953', field_numbers => [1] }
845 [ '4242423917', 'BK', 'GEN', '2001-06-25' ],
846 "copy all with regex: first original fields has been copied"
851 { record => $record, field => '953', field_numbers => [2] }
854 [ '4242423918', 'CD' ],
855 "copy all with regex: second original fields has been copied"
865 read_field( { record => $record, field => '999', subfield => '9' } );
866 is_deeply( \@fields_9999, [],
867 'copy a nonexistent field does not create a new one' );
869 $record = new_record;
881 { record => $record, field => '650', field_numbers => [2] }
884 [ 'The art of computer programming', 'Donald E. Knuth.' ],
885 'Copy a field to existent fields should create a new field'
890 { record => $record, field => '650', field_numbers => [1] }
893 [ 'Computer programming.', '462' ],
894 'Copy a field to existent fields should create a new field, the original one should not have been updated'
899 # copy_and_replace_field - subfield
900 subtest 'copy_and_replace_field' => sub {
902 subtest 'copy and replace subfield' => sub {
904 my $record = new_record;
905 $record->append_fields(
908 a => 'Computer algorithms.',
912 copy_and_replace_field(
916 from_subfield => 'a',
924 { record => $record, field => '245', subfield => 'a' }
927 ['The art of computer programming'],
928 'Copy and replace should not have modify original subfield 245$a (same as copy)'
933 { record => $record, field => '246', subfield => 'a' }
936 ['The art of computer programming'],
937 'Copy and replace should create a new 246$a (same as copy)'
940 $record = new_record;
941 $record->append_fields(
944 a => 'Computer algorithms.',
948 copy_and_replace_field(
952 from_subfield => 'a',
958 read_field( { record => $record, field => '651', subfield => 'a' } );
961 [ 'Computer programming.', 'Computer algorithms.' ],
962 'Copy and replace multivalued field (same as copy)'
964 delete_field( { record => $record, field => '651' } );
966 copy_and_replace_field(
970 from_subfield => 'a',
979 { record => $record, field => '651', subfield => 'a' }
982 ['Computer programming.'],
983 'Copy and replace first field 650$a should only copy the 1st (same as copy)'
986 copy_and_replace_field(
990 from_subfield => 'a',
999 { record => $record, field => '651', subfield => 'a' }
1002 ['Computer algorithms.'],
1003 'Copy and replace second field 650$a should erase 651$a'
1005 delete_field( { record => $record, field => '651' } );
1007 copy_and_replace_field(
1010 from_field => '650',
1011 from_subfield => 'a',
1014 regex => { search => 'Computer', replace => 'The art of' }
1018 read_field( { record => $record, field => '651', subfield => 'a' } );
1021 [ 'The art of programming.', 'The art of algorithms.' ],
1022 'Copy and replace field using regex (same as copy)'
1024 delete_field( { record => $record, field => '651' } );
1026 copy_and_replace_field(
1029 from_field => '650',
1030 from_subfield => 'a',
1033 regex => { search => 'Computer', replace => 'The mistake of' }
1037 read_field( { record => $record, field => '651', subfield => 'a' } );
1040 [ 'The mistake of programming.', 'The mistake of algorithms.' ],
1041 'Copy and replace fields using regex on existing fields (same as copy)'
1043 delete_field( { record => $record, field => '651' } );
1045 copy_and_replace_field(
1048 from_field => '650',
1049 from_subfield => 'a',
1052 regex => { search => 'Computer', replace => 'The art of' }
1056 read_field( { record => $record, field => '651', subfield => 'a' } );
1059 [ 'The art of programming.', 'The art of algorithms.', ],
1060 'Copy and replace all fields using regex (same as copy)'
1062 delete_field( { record => $record, field => '651' } );
1064 copy_and_replace_field(
1067 from_field => '650',
1068 from_subfield => 'a',
1071 regex => { search => 'Computer', replace => 'The art of' },
1072 field_numbers => [1]
1076 read_field( { record => $record, field => '651', subfield => 'a' } );
1079 [ 'The art of programming.', ],
1080 'Copy and replace first field using regex (same as copy)'
1082 delete_field( { record => $record, field => '651' } );
1084 # Copy and replace with regex modifiers
1085 $record = new_record;
1086 $record->append_fields(
1089 a => 'Computer algorithms.',
1093 copy_and_replace_field(
1096 from_field => '650',
1097 from_subfield => 'a',
1100 regex => { search => 'o', replace => 'foo' }
1104 read_field( { record => $record, field => '652', 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 => 'g' }
1122 read_field( { record => $record, field => '653', subfield => 'a' } );
1125 [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ],
1126 'Copy and replace field using regex (same as copy)'
1129 copy_and_replace_field(
1132 from_field => '650',
1133 from_subfield => 'a',
1136 regex => { search => 'O', replace => 'foo', modifiers => 'i' }
1140 read_field( { record => $record, field => '654', subfield => 'a' } );
1143 [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ],
1144 'Copy and replace field using regex (same as copy)'
1147 copy_and_replace_field(
1150 from_field => '650',
1151 from_subfield => 'a',
1154 regex => { search => 'O', replace => 'foo', modifiers => 'gi' }
1158 read_field( { record => $record, field => '655', subfield => 'a' } );
1161 [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ],
1162 'Copy and replace field using regex (same as copy)'
1165 $record = new_record;
1166 $record->append_fields(
1174 copy_and_replace_field(
1177 from_field => '952',
1178 from_subfield => 'd',
1184 read_field( { record => $record, field => '952', subfield => 'd' } );
1187 [ '2001-06-25', '2001-06-25' ],
1188 'copy and replace 952$d into others 952 field'
1191 copy_and_replace_field(
1194 from_field => '111',
1195 from_subfield => '1',
1201 read_field( { record => $record, field => '999', subfield => '9' } );
1202 is_deeply( \@fields_9999, [],
1203 'copy and replace a nonexistent subfield does not create a new one (same as copy)' );
1205 $record = new_record;
1206 copy_and_replace_field(
1210 from_subfield => 'a',
1213 regex => { search => '^', replace => 'BEGIN ' }
1216 # This is the same as update the subfield
1220 { record => $record, field => '245', subfield => 'a' }
1223 ['BEGIN The art of computer programming'],
1224 'Copy and replace - Update a subfield: add a string at the beginning'
1227 $record = new_record;
1228 copy_and_replace_field(
1232 from_subfield => 'a',
1235 regex => { search => '$', replace => ' END' }
1238 # This is the same as update the subfield
1242 { record => $record, field => '245', subfield => 'a' }
1245 ['The art of computer programming END'],
1246 'Copy and replace - Update a subfield: add a string at the end'
1249 $record = new_record;
1250 copy_and_replace_field(
1254 from_subfield => 'c',
1263 { record => $record, field => '650' }
1266 [ 'Computer programming.', '462', 'Donald E. Knuth.' ],
1267 'Copy and replace a subfield to an existent field but inexistent subfield (same as copy)'
1270 $record = new_record;
1271 copy_and_replace_field(
1275 from_subfield => 'c',
1284 { record => $record, field => '650' }
1287 [ 'Computer programming.', 'Donald E. Knuth.' ],
1288 'Copy and replace a subfield to an existent field / subfield, the origin subfield is replaced'
1292 subtest 'copy and replace field' => sub {
1294 my $record = new_record;
1295 $record->append_fields(
1304 copy_and_replace_field(
1305 { record => $record, from_field => '952', to_field => '953' } );
1306 my @fields_952 = read_field( { record => $record, field => '952' } );
1310 { record => $record, field => '952', field_numbers => [1] }
1313 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
1314 "copy all: original first field still exists (same as copy)"
1319 { record => $record, field => '952', field_numbers => [2] }
1322 [ '3010023918', 'CD' ],
1323 "copy all: original second field still exists (same as copy)"
1328 { record => $record, field => '953', field_numbers => [1] }
1331 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
1332 "copy all: first original fields has been copied (same as copy)"
1337 { record => $record, field => '953', field_numbers => [2] }
1340 [ '3010023918', 'CD' ],
1341 "copy all: second original fields has been copied (same as copy)"
1344 #- copy only the first field
1345 copy_and_replace_field(
1348 from_field => '953',
1350 field_numbers => [1]
1356 { record => $record, field => '953', field_numbers => [1] }
1359 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
1360 "copy and replace first: first original fields has been copied (same as copy)"
1365 { record => $record, field => '953', field_numbers => [2] }
1368 [ '3010023918', 'CD' ],
1369 "copy and replace first: second original fields has been copied (same as copy)"
1372 [ read_field( { record => $record, field => '954' } ) ],
1373 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
1374 "copy and replace first: only first, first 953 has been copied (same as copy)"
1377 $record = new_record;
1378 $record->append_fields(
1386 #- copy and replace all fields and modify values using a regex
1387 copy_and_replace_field(
1390 from_field => '952',
1392 regex => { search => '30100', replace => '42424' }
1398 { record => $record, field => '952', field_numbers => [1] }
1401 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
1402 "copy and replace all with regex: original first field still exists (same as copy)"
1407 { record => $record, field => '952', field_numbers => [2] }
1410 [ '3010023918', 'CD' ],
1411 "copy and replace all with regex: original second field still exists (same as copy)"
1416 { record => $record, field => '953', field_numbers => [1] }
1419 [ '4242423917', 'BK', 'GEN', '2001-06-25' ],
1420 "copy and replace all with regex: first original fields has been copied (same as copy)"
1425 { record => $record, field => '953', field_numbers => [2] }
1428 [ '4242423918', 'CD' ],
1429 "copy and replace all with regex: second original fields has been copied (same as copy)"
1431 copy_and_replace_field(
1434 from_field => '111',
1439 read_field( { record => $record, field => '999', subfield => '9' } );
1440 is_deeply( \@fields_9999, [],
1441 'copy and replace a nonexistent field does not create a new one (same as copy)' );
1443 $record = new_record;
1444 copy_and_replace_field(
1455 { record => $record, field => '650', field_numbers => [1] }
1458 [ 'The art of computer programming', 'Donald E. Knuth.' ],
1459 'Copy and replace to an existent field should erase the original field'
1464 { record => $record, field => '650', field_numbers => [2] }
1468 'Copy and replace to an existent field should not create a new field'
1473 # move_field - subfields
1474 subtest 'move_field' => sub {
1476 subtest 'move subfield' => sub {
1478 my $record = new_record;
1479 my ( @fields_952d, @fields_952c, @fields_954c, @fields_954p );
1480 $record->append_fields(
1490 from_field => '952',
1491 from_subfield => 'c',
1497 read_field( { record => $record, field => '952', subfield => 'c' } );
1499 read_field( { record => $record, field => '954', subfield => 'c' } );
1500 is_deeply( \@fields_952c, [], 'The 952$c has moved' );
1501 is_deeply( \@fields_954c, ['GEN'], 'Now 954$c exists' );
1506 from_field => '952',
1507 from_subfield => 'p',
1510 field_numbers => [1]
1512 ); # Move the first field
1514 read_field( { record => $record, field => '952', subfield => 'p' } );
1516 read_field( { record => $record, field => '954', subfield => 'p' } );
1517 is_deeply( \@fields_952p, ['3010023917'], 'One of 952$p has moved' );
1518 is_deeply( \@fields_954p, ['3010023917'], 'Now 954$p exists' );
1520 $record = new_record;
1521 $record->append_fields(
1532 from_field => '952',
1533 from_subfield => 'p',
1539 read_field( { record => $record, field => '952', subfield => 'p' } );
1541 read_field( { record => $record, field => '954', subfield => 'p' } );
1542 is_deeply( \@fields_952p, [], 'All 952$p have moved' );
1545 [ '3010023917', '3010023917' ],
1552 from_field => '111',
1553 from_subfield => '1',
1559 read_field( { record => $record, field => '999', subfield => '9' } );
1560 is_deeply( \@fields_9999, [],
1561 'move a nonexistent subfield does not create a new one' );
1564 subtest 'move field' => sub {
1567 # move_field - fields
1568 my $record = new_record;
1569 $record->append_fields(
1579 { record => $record, from_field => '952', to_field => '953' } );
1580 is_deeply( [ read_field( { record => $record, field => '952' } ) ],
1581 [], "original fields don't exist" );
1585 { record => $record, field => '953', field_numbers => [1] }
1588 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
1589 "first original fields has been copied"
1594 { record => $record, field => '953', field_numbers => [2] }
1597 [ '3010023917', 'BK' ],
1598 "second original fields has been copied"
1601 #- Move only the first field
1605 from_field => '953',
1607 field_numbers => [1]
1611 [ read_field( { record => $record, field => '953' } ) ],
1612 [ '3010023917', 'BK' ],
1613 "only first, the second 953 still exists"
1616 [ read_field( { record => $record, field => '954' } ) ],
1617 [ '3010023917', 'BK', 'GEN', '2001-06-25' ],
1618 "only first, first 953 has been copied"
1621 $record = new_record;
1622 $record->append_fields(
1630 #- Move all fields and modify values using a regex
1634 from_field => '952',
1636 regex => { search => 'BK', replace => 'DVD' }
1639 is_deeply( [ read_field( { record => $record, field => '952' } ) ],
1640 [], "use a regex, original fields don't exist" );
1644 { record => $record, field => '953', field_numbers => [1] }
1647 [ '3010023917', 'DVD', 'GEN', '2001-06-25' ],
1648 "use a regex, first original fields has been copied"
1653 { record => $record, field => '953', field_numbers => [2] }
1656 [ '3010023917', 'DVD' ],
1657 "use a regex, second original fields has been copied"
1663 from_field => '111',
1668 read_field( { record => $record, field => '999', subfield => '9' } );
1669 is_deeply( \@fields_9999, [],
1670 'move a nonexistent field does not create a new one' );
1676 subtest 'delete_field' => sub {
1678 subtest 'delete subfield' => sub {
1680 my $record = new_record;
1681 $record->append_fields(
1694 field_numbers => [1]
1698 read_field( { record => $record, field => '952', subfield => 'p' } );
1699 is_deeply( \@fields_952p, ['3010023917'], 'Delete first 952$p' );
1701 $record = new_record;
1702 $record->append_fields(
1709 delete_field( { record => $record, field => '952', subfield => 'p' } );
1711 read_field( { record => $record, field => '952', subfield => 'p' } );
1712 is_deeply( \@fields_952p, [], 'Delete all 952$p' );
1715 subtest 'delete field' => sub {
1717 my $record = new_record;
1718 delete_field( { record => $record, field => '952' } );
1719 my @fields_952 = read_field( { record => $record, field => '952' } );
1720 is_deeply( \@fields_952, [], 'Delete all 952, 1 deleted' );
1722 $record = new_record;
1723 $record->append_fields(
1730 delete_field( { record => $record, field => '952' } );
1731 @fields_952 = read_field( { record => $record, field => '952' } );
1732 is_deeply( \@fields_952, [], 'Delete all 952, 2 deleted' );
1736 subtest 'field_equals' => sub {
1738 my $record = new_record;
1739 subtest 'standard MARC fields' => sub {
1741 my $match = Koha::SimpleMARC::field_equals({
1747 is_deeply( $match, [], '100$a not equal to "Donald"' );
1749 $match = Koha::SimpleMARC::field_equals({
1756 is_deeply( $match, [1], 'first 100$a matches "Donald"');
1759 subtest 'control fields' => sub {
1761 my $match = Koha::SimpleMARC::field_equals({
1767 is_deeply( $match, [], '008 control field not equal to "eng"' );
1769 $match = Koha::SimpleMARC::field_equals({
1776 is_deeply( $match, [1], 'first 008 control field matches "eng"' );