5 use Test::More tests => 129;
12 use_ok("MARC::Field");
13 use_ok("MARC::Record");
14 use_ok('C4::MarcModificationTemplates', qw( AddModificationTemplate AddModificationTemplateAction GetModificationTemplateAction GetModificationTemplateActions ModModificationTemplateAction MoveModificationTemplateAction DelModificationTemplate DelModificationTemplateAction ModifyRecordWithTemplate GetModificationTemplates ));
16 my $schema = Koha::Database->new->schema;
17 $schema->storage->txn_begin;
18 my $dbh = C4::Context->dbh;
20 $dbh->do(q|DELETE FROM marc_modification_templates|);
23 my $template_id = AddModificationTemplate("template_name");
24 like( $template_id, qr|^\d+$|, "new template returns an id" );
26 is( AddModificationTemplateAction(
27 $template_id, 'move_field', 1,
28 '464', 'u', '', '464', '3',
30 '', '', '', '', '', '',
31 'move first 464$u to 464$3'
32 ), 1, "Add first action");
34 is( AddModificationTemplateAction(
35 $template_id, 'update_field', 0,
36 '099', 't', 'LIV', '', '',
38 'if', '200', 'b', 'equals', 'Text', '',
39 'Update field 099$t with value LIV if 200$b matches "Text"'
40 ), 1, "Add second action");
42 is( AddModificationTemplateAction(
43 $template_id, 'copy_field', 0,
44 '606', 'a', '', '607', 'a',
46 'unless', '606', 'a', 'not_equals', '^AJAX', '1',
47 'Copy field 606$a to 607$a unless 606$a matches RegEx m^AJAX'
48 ), 1, "Add third action");
50 is( AddModificationTemplateAction(
51 $template_id, 'add_field', 0,
52 '650', 'a', 'Additional', '', '',
54 'unless', '650', 'a', 'exists', '', '',
55 'Add field 650$aAdditional unless 650$a exists'
56 ), 1, "Add fourth action");
59 my @actions = GetModificationTemplateActions( $template_id );
60 is( @actions, 4, "4 actions are inserted");
62 for my $action ( @actions ) {
63 isnt( GetModificationTemplateAction( $action->{mmta_id} ), undef, "action with id $action->{mmta_id} exists" );
66 my $first_action = $actions[0];
67 is( $first_action->{ordering}, 1, "test ordering for first action" );
68 is( $first_action->{action}, 'move_field', "test action for first action" );
69 is( $first_action->{from_field}, '464', "test from_field for first action" );
70 is( $first_action->{from_subfield}, 'u', "test from_subfield for first action" );
71 is( $first_action->{to_field}, '464', "test to_field for first action" );
72 is( $first_action->{to_subfield}, '3', "test to_subfield for first action" );
74 my $second_action = $actions[1];
75 is( $second_action->{ordering}, 2, "test ordering for second action" );
76 is( $second_action->{action}, 'update_field', "test action for second action" );
77 is( $second_action->{from_field}, '099',"test from_field for second action" );
78 is( $second_action->{from_subfield}, 't', "test from_subfield for second action" );
79 is( $second_action->{field_value}, 'LIV', "test firld_value for second action" );
80 is( $second_action->{to_field}, '', "test to_field for second action" );
81 is( $second_action->{to_subfield}, '', "test to_subfield for second action" );
82 is( $second_action->{conditional}, 'if', "test conditional for second action" );
83 is( $second_action->{conditional_field}, '200', "test conditional_field for second action" );
84 is( $second_action->{conditional_subfield}, 'b', "test conditional_subfield for second action" );
85 is( $second_action->{conditional_comparison}, 'equals', "test conditional_comparison for second action" );
87 my $third_action = $actions[2];
88 is( $third_action->{ordering}, 3, "test ordering for third action" );
89 is( $third_action->{action}, 'copy_field', "test action for third action" );
90 is( $third_action->{from_field}, '606', "test from_field for third action" );
91 is( $third_action->{from_subfield}, 'a', "test from_subfield for third action" );
92 is( $third_action->{to_field}, '607', "test to_field for third action" );
93 is( $third_action->{to_subfield}, 'a', "test to_subfield for third action" );
94 is( $third_action->{conditional}, 'unless', "test conditional for third action" );
95 is( $third_action->{conditional_field}, '606', "test conditional_field for third action" );
96 is( $third_action->{conditional_subfield}, 'a', "test conditional_subfield for third action" );
97 is( $third_action->{conditional_comparison}, 'not_equals', "test conditional_comparison for third action" );
98 is( $third_action->{conditional_value}, '^AJAX', "test conditional_value for third action" );
100 my $fourth_action = $actions[3];
101 is( $fourth_action->{ordering}, 4, "test ordering for fourth action" );
102 is( $fourth_action->{action}, 'add_field', "test action for fourth action" );
103 is( $fourth_action->{from_field}, '650', "test from_field for fourth action" );
104 is( $fourth_action->{from_subfield}, 'a', "test from_subfield for fourth action" );
105 is( $fourth_action->{to_field}, '', "test to_field for fourth action" );
106 is( $fourth_action->{to_subfield}, '', "test to_subfield for fourth action" );
107 is( $fourth_action->{conditional}, 'unless', "test conditional for fourth action" );
108 is( $fourth_action->{conditional_field}, '650', "test conditional_field for fourth action" );
109 is( $fourth_action->{conditional_subfield}, 'a', "test conditional_subfield for fourth action" );
110 is( $fourth_action->{conditional_comparison}, 'exists', "test conditional_comparison for fourth action" );
111 is( $fourth_action->{conditional_value}, '', "test conditional_value for fourth action" );
114 is( ModModificationTemplateAction(
115 $actions[1]->{mmta_id}, 'update_field', 0,
116 '100', 'u', 'LIV', '', '',
118 'if', '200', 'c', 'equals', 'Text', '',
119 'Update field 099$t with value LIV if 200$b matches "Text"'
120 ), 1, "Modify second action");
122 $second_action = GetModificationTemplateAction( $actions[1]->{mmta_id} );
123 is( $second_action->{ordering}, 2, "test ordering for second action modified" );
124 is( $second_action->{action}, 'update_field', "test action for second action modified" );
125 is( $second_action->{from_field}, '100',"test from_field for second action modified" );
126 is( $second_action->{from_subfield}, 'u', "test from_subfield for second action modified" );
127 is( $second_action->{field_value}, 'LIV', "test firld_value for second action modified" );
128 is( $second_action->{to_field}, '', "test to_field for second action modified" );
129 is( $second_action->{to_subfield}, '', "test to_subfield for second action modified" );
130 is( $second_action->{conditional}, 'if', "test conditional for second action modified" );
131 is( $second_action->{conditional_field}, '200', "test conditional_field for second action modified" );
132 is( $second_action->{conditional_subfield}, 'c', "test conditional_subfield for second action modified" );
133 is( $second_action->{conditional_comparison}, 'equals', "test conditional_comparison for second action modified" );
136 is( MoveModificationTemplateAction( $actions[2]->{mmta_id}, 'top' ), '1', 'Move the third action on top' );
137 is( MoveModificationTemplateAction( $actions[0]->{mmta_id}, 'bottom' ), '1', 'Move the first action on bottom' );
139 is( GetModificationTemplateAction( $actions[0]->{mmta_id} )->{ordering}, '4', 'First becomes fourth' );
140 is( GetModificationTemplateAction( $actions[1]->{mmta_id} )->{ordering}, '2', 'Second stays second' );
141 is( GetModificationTemplateAction( $actions[2]->{mmta_id} )->{ordering}, '1', 'Third becomes first' );
142 is( GetModificationTemplateAction( $actions[3]->{mmta_id} )->{ordering}, '3', 'Fourth becomes third' );
144 is( MoveModificationTemplateAction( $actions[0]->{mmta_id}, 'up' ), '1', 'Move up the first action (was fourth)' );
145 is( MoveModificationTemplateAction( $actions[0]->{mmta_id}, 'up' ), '1', 'Move up the first action (was third)' );
146 is( MoveModificationTemplateAction( $actions[2]->{mmta_id}, 'down' ), '1', 'Move down the third action (was first)' );
148 is( GetModificationTemplateAction( $actions[0]->{mmta_id} )->{ordering}, '1', 'First becomes again first' );
149 is( GetModificationTemplateAction( $actions[1]->{mmta_id} )->{ordering}, '3', 'Second becomes third' );
150 is( GetModificationTemplateAction( $actions[2]->{mmta_id} )->{ordering}, '2', 'Third becomes second' );
151 is( GetModificationTemplateAction( $actions[3]->{mmta_id} )->{ordering}, '4', 'Fourth becomes again fourth' );
154 is( DelModificationTemplateAction( $actions[0]->{mmta_id} ), 3, "Delete the first action, 2 others are reordered" );
155 is( GetModificationTemplateAction( $actions[0]->{mmta_id} ), undef, "first action does not exist anymore" );
157 is( DelModificationTemplate( $template_id ), 1, "The template has been deleted" );
159 is( GetModificationTemplateAction( $actions[1]->{mmta_id} ), undef, "second action does not exist anymore" );
160 is( GetModificationTemplateAction( $actions[2]->{mmta_id} ), undef, "third action does not exist anymore" );
161 is( GetModificationTemplateAction( $actions[3]->{mmta_id} ), undef, "fourth action does not exist anymore" );
163 is( GetModificationTemplateActions( $template_id ), 0, "There is no action for deleted template" );
165 # ModifyRecordWithTemplate
166 t::lib::Mocks::mock_userenv();
168 $template_id = AddModificationTemplate("new_template_test");
169 like( $template_id, qr|^\d+$|, "new template returns an id" );
171 is( AddModificationTemplateAction(
172 $template_id, 'delete_field', 0,
173 '245', '', '', '', '',
175 'if', '245', 'a', 'equals', 'Bad title', '',
176 'Delete field 245 if 245$a eq "Bad title"'
177 ), 1, 'Add first action: delete field 245 if 245$a eq "Bad title"');
179 is( AddModificationTemplateAction(
180 $template_id, 'copy_field', 0,
181 '245', 'a', '', '246', 'a',
183 '', '', '', '', '', '',
184 'copy field 245$a to 246$a'
185 ), 1, 'Add second action: copy 245$a to 246$a');
187 is( AddModificationTemplateAction(
188 $template_id, 'delete_field', 0,
189 '650', 'a', '', '', '',
191 'if', '650', '9', 'equals', '462', '',
192 'Delete field 650$a if 650$9=462'
193 ), 1, 'Add third action: delete field 650$a if 650$9=462');
195 is( AddModificationTemplateAction(
196 $template_id, 'update_field', 0,
197 '952', 'p', '3010023917_updated', '', '',
199 'unless', '650', '9', 'equals', '42', '',
200 'Update field 952$p with "3010023917_updated" if 650$9 != 42'
201 ), 1, 'Add fourth action: update field 952$p with "3010023917_updated" if 650$9 != 42');
203 is( AddModificationTemplateAction(
204 $template_id, 'move_field', 0,
205 '952', 'd', '', '952', 'e',
207 'if', '952', 'c', 'equals', '^GEN', '1',
208 'Move field 952$d to 952$e if 952$c =~ /^GEN/'
209 ), 1, 'Add fifth action: move field 952$d to 952$e if 952$c =~ /^GEN/');
211 is( AddModificationTemplateAction(
212 $template_id, 'update_field', 0,
213 '650', 'a', 'Computer algorithms.', '', '',
215 'if', '650', '9', 'equals', '499', '',
216 'Update field 650$a with "Computer algorithms." to 651 if 650$9 == 499'
217 ), 1, 'Add sixth action: update field 650$a with "Computer algorithms." if 650$9 == 499');
219 is( AddModificationTemplateAction(
220 $template_id, 'move_field', 0,
221 '650', '', '', '651', '',
223 'if', '650', '9', 'equals', '499', '',
224 'Move field 650 to 651 if 650$9 == 499'
225 ), 1, 'Add seventh action: move field 650 to 651 if 650$9 == 499');
227 is( AddModificationTemplateAction(
228 $template_id, 'update_field', 0,
229 '999', 'a', 'non existent.', '', '',
231 '', '', '', '', '', '',
232 'Update non existent field 999$a with "non existent"'
233 ), 1, 'Add eighth action: update field non existent 999$a with "non existent."');
235 is( AddModificationTemplateAction(
236 $template_id, 'update_field', 0,
237 '999', 'a', 'existent - updated.', '', '',
239 '', '', '', '', '', '',
240 'Update existent field 999$a with "existent - updated."'
241 ), 1, 'Add ninth action: update field non existent 999$a with "existent - updated."');
243 is( AddModificationTemplateAction(
244 $template_id, 'add_field', 0,
245 '999', 'a', 'additional existent.', '', '',
247 '', '', '', '', '', '',
248 'Add new existent field 999$a with "additional existent"'
249 ), 1, 'Add tenth action: add additional field existent 999$a with "additional existent."');
251 is( AddModificationTemplateAction(
252 $template_id, 'add_field', 0,
253 '007', '', 'vxcdq', '', '',
255 '', '', '', '', '', '',
256 'Add new existent field 999$a with "additional existent"'
257 ), 1, 'Add eleventh action: add additional field existent 007');
259 my $record = new_record();
260 is( ModifyRecordWithTemplate( $template_id, $record ), undef, "The ModifyRecordWithTemplate returns undef" );
262 my $expected_record = expected_record_1();
263 is_deeply( $record, $expected_record, "Record modification as expected");
265 $template_id = AddModificationTemplate("another_template_test");
267 # Duplicate 245 => 3x245
268 is( AddModificationTemplateAction(
269 $template_id, 'copy_field', 0,
270 '245', '', '', '245', '',
272 'if', '245', 'a', 'equals', 'Bad title', '',
273 'Copy field 245 if 245$a eq "Bad title"'
274 ), 1, 'Add action: copy field 245 if 245$a eq "Bad title"');
276 $record = new_record();
277 is( ModifyRecordWithTemplate( $template_id, $record ), undef, "The ModifyRecordWithTemplate returns undef" );
279 my @fields_245a = Koha::SimpleMARC::read_field({
284 is_deeply( \@fields_245a, [
286 'The art of computer programming',
288 ], 'Copy field has copied the "Bad title"' );
290 # Update first "Bad title"
291 is( AddModificationTemplateAction(
292 $template_id, 'update_field', 1,
293 '245', 'a', 'Bad title updated', '', '',
295 'if', '245', 'a', 'equals', 'Bad title', '',
296 'Update first 245$a matching "Bad title" with "Bad title updated"'
297 ), 1, 'Add action: update field 245$a matching "Bad title" with "Bad title updated');
299 $record = new_record();
300 is( ModifyRecordWithTemplate( $template_id, $record ), undef, "The ModifyRecordWithTemplate returns undef" );
302 @fields_245a = Koha::SimpleMARC::read_field({
307 is_deeply( \@fields_245a, [
309 'The art of computer programming',
311 ], 'update_field has update first the "Bad title"' );
313 # Duplicate first 245 => 3x245
314 is( AddModificationTemplateAction(
315 $template_id, 'copy_field', 1,
316 '245', '', '', '245', '',
318 'if', '245', 'a', 'equals', '^Bad title', '1',
319 'Copy field 245 if 245$a =~ "^Bad title"'
320 ), 1, 'Add action: copy field 245 if 245$a =~ "^Bad title"');
322 $record = new_record();
323 is( ModifyRecordWithTemplate( $template_id, $record ), undef, "The ModifyRecordWithTemplate returns undef" );
325 @fields_245a = Koha::SimpleMARC::read_field({
330 is_deeply( \@fields_245a, [
333 'The art of computer programming',
335 ], 'Copy field has copied first "^Bad title"' );
337 # Delete first ^Bad title
338 is( AddModificationTemplateAction(
339 $template_id, 'delete_field', 1,
340 '245', '', '', '', '',
342 'if', '245', 'a', 'equals', '^Bad title', '1',
343 'Delete first 245$a mathing ^Bad title'
344 ), 1, 'Delete first 245$a mathing ^Bad title');
346 $record = new_record();
347 is( ModifyRecordWithTemplate( $template_id, $record ), undef, "The ModifyRecordWithTemplate returns undef" );
348 @fields_245a = Koha::SimpleMARC::read_field({
353 is_deeply( \@fields_245a, [
355 'The art of computer programming',
357 ], 'delete field has been deleted the right field"' );
359 is( AddModificationTemplateAction(
360 $template_id, 'delete_field', 0,
361 '245', '', '', '', '',
363 'if', '245', 'a', 'equals', 'updated$', '1',
364 'Delete first 245$a mathing updated$'
365 ), 1, 'Delete first 245$a mathing updated$');
367 $record = new_record();
368 is( ModifyRecordWithTemplate( $template_id, $record ), undef, "The ModifyRecordWithTemplate returns undef" );
369 @fields_245a = Koha::SimpleMARC::read_field({
374 is_deeply( \@fields_245a, [
375 'The art of computer programming',
377 ], 'delete field has been deleted the right field"' );
379 subtest 'GetModificationTemplates' => sub {
381 $dbh->do(q|DELETE FROM marc_modification_templates|);
382 AddModificationTemplate("zzz");
383 AddModificationTemplate("aaa");
384 AddModificationTemplate("mmm");
385 my @templates = GetModificationTemplates();
386 is_deeply( [map{$_->{name}} @templates], ['aaa', 'mmm', 'zzz'] );
389 subtest "not_equals" => sub {
391 $dbh->do(q|DELETE FROM marc_modification_templates|);
392 my $template_id = AddModificationTemplate("template_name");
393 AddModificationTemplateAction(
394 $template_id, 'move_field', 0,
395 '650', '', '', '651', '',
397 'if', '650', '9', 'not_equals', '499', '',
398 'Move field 650 to 651 if 650$9 != 499'
400 my $record = new_record();
401 ModifyRecordWithTemplate( $template_id, $record );
402 my $expected_record = expected_record_2();
403 is_deeply( $record, $expected_record, '650 has been moved to 651 when 650$9 != 499' );
405 $dbh->do(q|DELETE FROM marc_modification_templates|);
406 $template_id = AddModificationTemplate("template_name");
407 AddModificationTemplateAction(
408 $template_id, 'move_field', 0,
409 '650', '', '', '651', '',
411 'if', '650', 'b', 'not_equals', '499', '',
412 'Move field 650 to 651 if 650$b != 499'
414 $record = new_record();
415 ModifyRecordWithTemplate( $template_id, $record );
416 $expected_record = new_record();
417 is_deeply( $record, $expected_record, 'None 650 have been moved, no $650$b exists' );
420 subtest "when conditional field doesn't match the from field" => sub {
422 $dbh->do(q|DELETE FROM marc_modification_templates|);
423 my $template_id = AddModificationTemplate("template_name");
424 AddModificationTemplateAction(
425 $template_id, 'delete_field', 0,
426 '650', '9', '', '', '',
428 'if', '245', 'a', 'equals', 'Bad title', '',
429 'Delete fields 650$9 if 245$a == "Bad title"'
431 my $record = new_record();
432 ModifyRecordWithTemplate( $template_id, $record );
433 my $expected_record = expected_record_3();
434 is_deeply( $record, $expected_record, '650$9 fields have been deleted when 245$a == "Bad title"' );
436 $dbh->do(q|DELETE FROM marc_modification_templates|);
437 $template_id = AddModificationTemplate("template_name");
438 AddModificationTemplateAction(
439 $template_id, 'delete_field', 0,
440 '650', '9', '', '', '',
442 'if', '245', 'a', 'exists', '', '',
443 'Delete fields 650$9 if 245$a exists'
445 $record = new_record();
446 ModifyRecordWithTemplate( $template_id, $record );
447 $expected_record = expected_record_3();
448 is_deeply( $record, $expected_record, '650$9 fields have been deleted because 245$a exists' );
450 $dbh->do(q|DELETE FROM marc_modification_templates|);
451 $template_id = AddModificationTemplate("template_name");
452 AddModificationTemplateAction(
453 $template_id, 'delete_field', 1,
454 '650', '', '', '', '',
456 'if', '245', 'a', 'exists', '', '',
457 'Delete 1st field 650 if 245$a exists'
459 $record = new_record();
460 ModifyRecordWithTemplate( $template_id, $record );
461 $expected_record = expected_record_4();
462 is_deeply( $record, $expected_record, '1st 650 field has been deleted because 245$a exists' );
466 my $record = MARC::Record->new;
467 $record->leader('03174nam a2200445 a 4500');
471 a => 'Knuth, Donald Ervin',
476 a => 'The art of computer programming',
477 c => 'Donald E. Knuth.',
482 c => 'Donald E. Knuth.',
486 a => 'Computer programming.',
491 a => 'Computer programming.',
502 $record->append_fields(@fields);
506 sub expected_record_1 {
507 my $record = MARC::Record->new;
508 $record->leader('03174nam a2200445 a 4500');
515 a => 'Knuth, Donald Ervin',
520 a => 'The art of computer programming',
521 c => 'Donald E. Knuth.',
525 a => 'The art of computer programming',
533 a => 'Computer algorithms.',
538 p => '3010023917_updated',
545 a => 'additional existent.',
549 a => 'existent - updated.',
552 $record->append_fields(@fields);
556 sub expected_record_2 {
557 my $record = MARC::Record->new;
558 $record->leader('03174nam a2200445 a 4500');
562 a => 'Knuth, Donald Ervin',
567 a => 'The art of computer programming',
568 c => 'Donald E. Knuth.',
573 c => 'Donald E. Knuth.',
577 a => 'Computer programming.',
582 a => 'Computer programming.',
593 $record->append_fields(@fields);
597 sub expected_record_3 {
598 my $record = MARC::Record->new;
599 $record->leader('03174nam a2200445 a 4500');
603 a => 'Knuth, Donald Ervin',
608 a => 'The art of computer programming',
609 c => 'Donald E. Knuth.',
614 c => 'Donald E. Knuth.',
618 a => 'Computer programming.',
622 a => 'Computer programming.',
632 $record->append_fields(@fields);
636 sub expected_record_4 {
637 my $record = MARC::Record->new;
638 $record->leader('03174nam a2200445 a 4500');
642 a => 'Knuth, Donald Ervin',
647 a => 'The art of computer programming',
648 c => 'Donald E. Knuth.',
653 c => 'Donald E. Knuth.',
657 a => 'Computer programming.',
668 $record->append_fields(@fields);
672 # Tests related to use of subfield 0 ($0)
675 my $record = MARC::Record->new;
676 $record->leader('03174nam a2200445 a 4500');
681 a => 'Knuth, Donald Ervin',
687 a => 'The art of computer programming',
688 c => 'Donald E. Knuth.',
693 a => 'Computer programming.',
702 $record->append_fields(@fields);
706 sub expected_record_0 {
707 my $record = MARC::Record->new;
708 $record->leader('03174nam a2200445 a 4500');
712 a => 'Knuth, Donald Ervin',
720 a => 'The art of computer programming',
721 c => 'Donald E. Knuth.',
734 a => 'Computer programming.',
757 $record->append_fields(@fields);
761 $record = new_record_0();
762 is( ModifyRecordWithTemplate( $template_id, $record ), undef, "The ModifyRecordWithTemplate returns undef" );
764 $template_id = AddModificationTemplate("template_test_subfield_0");
765 like( $template_id, qr|^\d+$|, "new template returns an id" );
767 # Delete subfield 100$0
768 is( AddModificationTemplateAction(
769 $template_id, 'delete_field', 0,
770 '100', '0', '', '', '',
772 '', '', '', '', '', '',
773 'Action 1: Delete subfield 100$0'
774 ), 1, 'Action 1: Delete subfield 100$0');
776 # Add new subfield 100$0 with value "Test"
777 # This adds a new 100 field to the record
778 is( AddModificationTemplateAction(
779 $template_id, 'add_field', 0,
780 '100', '0', 'Test', '', '',
782 '', '', '', '', '', '',
783 'Action 2: Add new subfield 100$0 with value "Test"'
784 ), 1, 'Action 2: Add new subfield 100$0');
786 # Update existing or add new subfield 100$0 with value "TestUpdated"
787 # This updates the new 100 create above, and adds a new 100$0 to the original 100 field
788 is( AddModificationTemplateAction(
789 $template_id, 'update_field', 0,
790 '100', '0', 'TestUpdated', '', '',
792 '', '', '', '', '', '',
793 'Action 3: Update existing or add new subfield 100$0 with value "TestUpdated"'
794 ), 1, 'Action 3: Update existing or add new subfield 100$0 with value "TestUpdated"');
796 # Move subfield 100$0 to 600$0
797 # This removes the newly created 100, and removes the 100$0 from the original 100 field
798 # Two 600 fields with a single 0 subfield are created
799 is( AddModificationTemplateAction(
800 $template_id, 'move_field', 0,
801 '100', '0', '', '600', '0',
803 '', '', '', '', '', '',
804 'Action 4: Move subfield 100$0 to 600$0'
805 ), 1, 'Action 4: Move subfield 100$0 to 600$0');
807 # Copy subfield 600$0 to 100$0
808 # Copy subfield adds to existing fields if found, so we get two 100$0 on the original field
809 is( AddModificationTemplateAction(
810 $template_id, 'copy_field', 0,
811 '600', '0', '', '100', '0',
813 '', '', '', '', '', '',
814 'Action 5: Copy subfield 600$0 to 100$0'
815 ), 1, 'Action 5: Copy subfield 600$0 to 100$0');
817 # Copy and replace subfield 245$0 to 700$0
818 # Copy and replace in this case makes a new 700$0 as it wasn't there
819 is( AddModificationTemplateAction(
820 $template_id, 'copy_and_replace_field', 0,
821 '245', '0', '', '700', '0',
823 '', '', '', '', '', '',
824 'Action 6: Copy and replace subfield 245$0 to 700$0'
825 ), 1, 'Action 6: Copy and replace subfield 245$0 to 700$0');
827 # Copy subfield 590$0 to 690$0
828 # Copies the single subfield from 590 to a new 690
829 is( AddModificationTemplateAction(
830 $template_id, 'copy_field', 0,
831 '590', '0', '', '690', '0',
833 '', '', '', '', '', '',
834 'Action 7: Copy subfield 590$0 to 690$0'
835 ), 1, 'Action 7: Copy subfield 590$0 to 690$0');
837 # Copy subfield 590$a to 690$a
838 # Copy subfield adds to existing 690 a new subfield a
839 is( AddModificationTemplateAction(
840 $template_id, 'copy_field', 0,
841 '590', 'a', '', '690', 'a',
843 '', '', '', '', '', '',
844 'Action 8: Copy subfield 690$a to 690$a'
845 ), 1, 'Action 8: Copy subfield 690$a to 690$a');
848 # Copy field 590 to 690
849 # Copy field copies existing to a new 690, does not add to existing
850 is( AddModificationTemplateAction(
851 $template_id, 'copy_field', 0,
852 '590', '', '', '690', '',
854 '', '', '', '', '', '',
855 'Action 9: Copy subfield 590 to 690'
856 ), 1, 'Action 9: Copy subfield 590 to 690');
858 my @actions_0 = GetModificationTemplateActions( $template_id );
859 is( @actions_0, 9, "9 actions are inserted");
861 ModifyRecordWithTemplate( $template_id, $record );
862 my $expected_record_0 = expected_record_0();
863 is_deeply( $record, $expected_record_0, '100$0 has been deleted, added back, updated, moved to 600$0, and copied back to 100$0; finally, 245$0 has been copied and replaced to 700$0' );