From 48fd8d1900f23d33c2e7aa5f3a9f10c21cafdb54 Mon Sep 17 00:00:00 2001 From: Arthur Suzuki Date: Sat, 25 Jan 2020 23:19:52 +0100 Subject: [PATCH] Bug 24480: Unit test This updates the SimpleMARC tests and MarcModificationTemplates tests to expect the new order of fields Signed-off-by: Kelly Signed-off-by: Phil Ringnalda Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- Koha/SimpleMARC.pm | 13 +++-- t/SimpleMARC.t | 32 +++++------ t/db_dependent/MarcModificationTemplates.t | 64 +++++++++++----------- 3 files changed, 55 insertions(+), 54 deletions(-) diff --git a/Koha/SimpleMARC.pm b/Koha/SimpleMARC.pm index 0c95ccf804..d3c05647ff 100644 --- a/Koha/SimpleMARC.pm +++ b/Koha/SimpleMARC.pm @@ -575,6 +575,13 @@ sub _copy_move_field { @from_fields = map { $_ <= @from_fields ? $from_fields[ $_ - 1 ] : () } @$field_numbers; } + if ( $action eq 'replace' ) { + my @to_fields = $record->field( $toFieldName ); + for my $to_field ( @to_fields ) { + $record->delete_field( $to_field ); + } + } + for my $from_field ( @from_fields ) { my $new_field = $from_field->clone; $new_field->{_tag} = $toFieldName; # Should be replaced by set_tag, introduced by MARC::Field 2.0.4 @@ -588,12 +595,6 @@ sub _copy_move_field { if ( $action eq 'move' ) { $record->delete_field( $from_field ) } - elsif ( $action eq 'replace' ) { - my @to_fields = $record->field( $toFieldName ); - if ( @to_fields ) { - $record->delete_field( $to_fields[0] ); - } - } $record->insert_grouped_field( $new_field ); } } diff --git a/t/SimpleMARC.t b/t/SimpleMARC.t index 56a92fb74e..f4e4d70e43 100755 --- a/t/SimpleMARC.t +++ b/t/SimpleMARC.t @@ -386,7 +386,7 @@ subtest 'copy_field' => sub { read_field( { record => $record, field => '651', subfield => 'a' } ); is_deeply( \@fields_651a, - [ 'Computer programming.', 'Computer algorithms.' ], + [ 'Computer algorithms.' , 'Computer programming.' ], 'Copy multivalued field' ); delete_field( { record => $record, field => '651' } ); @@ -447,7 +447,7 @@ subtest 'copy_field' => sub { read_field( { record => $record, field => '651', subfield => 'a' } ); is_deeply( \@fields_651a, - [ 'The art of programming.', 'The art of algorithms.' ], + [ 'The art of algorithms.', 'The art of programming.' ], 'Copy field using regex' ); delete_field( { record => $record, field => '651' } ); @@ -466,7 +466,7 @@ subtest 'copy_field' => sub { read_field( { record => $record, field => '651', subfield => 'a' } ); is_deeply( \@fields_651a, - [ 'The mistake of programming.', 'The mistake of algorithms.' ], + [ 'The mistake of algorithms.', 'The mistake of programming.' ], 'Copy fields using regex on existing fields' ); delete_field( { record => $record, field => '651' } ); @@ -485,7 +485,7 @@ subtest 'copy_field' => sub { read_field( { record => $record, field => '651', subfield => 'a' } ); is_deeply( \@fields_651a, - [ 'The art of programming.', 'The art of algorithms.', ], + [ 'The art of algorithms.', 'The art of programming.', ], 'Copy all fields using regex' ); delete_field( { record => $record, field => '651' } ); @@ -533,7 +533,7 @@ subtest 'copy_field' => sub { read_field( { record => $record, field => '652', subfield => 'a' } ); is_deeply( \@fields_652a, - [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ], + [ 'Cfoomputer algorithms.', 'Cfoomputer programming.' ], 'Copy field using regex' ); @@ -551,7 +551,7 @@ subtest 'copy_field' => sub { read_field( { record => $record, field => '653', subfield => 'a' } ); is_deeply( \@fields_653a, - [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ], + [ 'Cfoomputer algfoorithms.', 'Cfoomputer prfoogramming.' ], 'Copy field using regex' ); @@ -569,7 +569,7 @@ subtest 'copy_field' => sub { read_field( { record => $record, field => '654', subfield => 'a' } ); is_deeply( \@fields_654a, - [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ], + [ 'Cfoomputer algorithms.', 'Cfoomputer programming.' ], 'Copy field using regex' ); @@ -587,7 +587,7 @@ subtest 'copy_field' => sub { read_field( { record => $record, field => '655', subfield => 'a' } ); is_deeply( \@fields_655a, - [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ], + [ 'Cfoomputer algfoorithms.', 'Cfoomputer prfoogramming.' ], 'Copy field using regex' ); @@ -981,7 +981,7 @@ subtest 'copy_and_replace_field' => sub { read_field( { record => $record, field => '651', subfield => 'a' } ); is_deeply( \@fields_651a, - [ 'Computer programming.', 'Computer algorithms.' ], + [ 'Computer algorithms.', 'Computer programming.' ], 'Copy and replace multivalued field (same as copy)' ); delete_field( { record => $record, field => '651' } ); @@ -1041,7 +1041,7 @@ subtest 'copy_and_replace_field' => sub { read_field( { record => $record, field => '651', subfield => 'a' } ); is_deeply( \@fields_651a, - [ 'The art of programming.', 'The art of algorithms.' ], + [ 'The art of algorithms.', 'The art of programming.' ], 'Copy and replace field using regex (same as copy)' ); delete_field( { record => $record, field => '651' } ); @@ -1060,7 +1060,7 @@ subtest 'copy_and_replace_field' => sub { read_field( { record => $record, field => '651', subfield => 'a' } ); is_deeply( \@fields_651a, - [ 'The mistake of programming.', 'The mistake of algorithms.' ], + [ 'The mistake of algorithms.', 'The mistake of programming.' ], 'Copy and replace fields using regex on existing fields (same as copy)' ); delete_field( { record => $record, field => '651' } ); @@ -1079,7 +1079,7 @@ subtest 'copy_and_replace_field' => sub { read_field( { record => $record, field => '651', subfield => 'a' } ); is_deeply( \@fields_651a, - [ 'The art of programming.', 'The art of algorithms.', ], + [ 'The art of algorithms.', 'The art of programming.', ], 'Copy and replace all fields using regex (same as copy)' ); delete_field( { record => $record, field => '651' } ); @@ -1127,7 +1127,7 @@ subtest 'copy_and_replace_field' => sub { read_field( { record => $record, field => '652', subfield => 'a' } ); is_deeply( \@fields_652a, - [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ], + [ 'Cfoomputer algorithms.', 'Cfoomputer programming.' ], 'Copy and replace field using regex (same as copy)' ); @@ -1145,7 +1145,7 @@ subtest 'copy_and_replace_field' => sub { read_field( { record => $record, field => '653', subfield => 'a' } ); is_deeply( \@fields_653a, - [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ], + [ 'Cfoomputer algfoorithms.', 'Cfoomputer prfoogramming.' ], 'Copy and replace field using regex (same as copy)' ); @@ -1163,7 +1163,7 @@ subtest 'copy_and_replace_field' => sub { read_field( { record => $record, field => '654', subfield => 'a' } ); is_deeply( \@fields_654a, - [ 'Cfoomputer programming.', 'Cfoomputer algorithms.' ], + [ 'Cfoomputer algorithms.', 'Cfoomputer programming.' ], 'Copy and replace field using regex (same as copy)' ); @@ -1181,7 +1181,7 @@ subtest 'copy_and_replace_field' => sub { read_field( { record => $record, field => '655', subfield => 'a' } ); is_deeply( \@fields_655a, - [ 'Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.' ], + [ 'Cfoomputer algfoorithms.', 'Cfoomputer prfoogramming.' ], 'Copy and replace field using regex (same as copy)' ); diff --git a/t/db_dependent/MarcModificationTemplates.t b/t/db_dependent/MarcModificationTemplates.t index f448291d6c..c0ec258344 100755 --- a/t/db_dependent/MarcModificationTemplates.t +++ b/t/db_dependent/MarcModificationTemplates.t @@ -507,6 +507,9 @@ sub expected_record_1 { my $record = MARC::Record->new; $record->leader('03174nam a2200445 a 4500'); my @fields = ( + MARC::Field->new( + '007', 'vxcdq', + ), MARC::Field->new( 100, '1', ' ', a => 'Knuth, Donald Ervin', @@ -517,36 +520,33 @@ sub expected_record_1 { a => 'The art of computer programming', c => 'Donald E. Knuth.', ), - MARC::Field->new( - 650, ' ', '0', - 9 => '462', - ), - MARC::Field->new( - 952, ' ', ' ', - p => '3010023917_updated', - y => 'BK', - c => 'GEN', - e => '2001-06-25', - ), MARC::Field->new( 246, '', ' ', a => 'The art of computer programming', ), + MARC::Field->new( + 650, ' ', '0', + 9 => '462', + ), MARC::Field->new( 651, ' ', '0', a => 'Computer algorithms.', 9 => '499', ), MARC::Field->new( - 999, ' ', ' ', - a => 'existent - updated.', + 952, ' ', ' ', + p => '3010023917_updated', + y => 'BK', + c => 'GEN', + e => '2001-06-25', ), MARC::Field->new( 999, ' ', ' ', a => 'additional existent.', ), MARC::Field->new( - '007', 'vxcdq', + 999, ' ', ' ', + a => 'existent - updated.', ), ); $record->append_fields(@fields); @@ -577,18 +577,18 @@ sub expected_record_2 { a => 'Computer programming.', 9 => '499', ), + MARC::Field->new( + 651, ' ', '0', + a => 'Computer programming.', + 9 => '462', + ), MARC::Field->new( 952, ' ', ' ', p => '3010023917', y => 'BK', c => 'GEN', d => '2001-06-25', - ), - MARC::Field->new( - 651, ' ', '0', - a => 'Computer programming.', - 9 => '462', - ), + ) ); $record->append_fields(@fields); return $record; @@ -720,6 +720,14 @@ sub expected_record_0 { a => 'The art of computer programming', c => 'Donald E. Knuth.', ), + MARC::Field->new( + 600, ' ', ' ', + 0 => 'TestUpdated', + ), + MARC::Field->new( + 600, ' ', ' ', + 0 => 'TestUpdated', + ), MARC::Field->new( 650, ' ', '0', 0 => '42', @@ -731,18 +739,6 @@ sub expected_record_0 { 0 => 'Zeroth', a => 'Appolo', ), - MARC::Field->new( - 600, ' ', ' ', - 0 => 'TestUpdated', - ), - MARC::Field->new( - 600, ' ', ' ', - 0 => 'TestUpdated', - ), - MARC::Field->new( - 700, ' ', ' ', - 0 => '12345', - ), MARC::Field->new( 690, ' ', ' ', 0 => 'Zeroth', @@ -753,6 +749,10 @@ sub expected_record_0 { 0 => 'Zeroth', a => 'Appolo', ), + MARC::Field->new( + 700, ' ', ' ', + 0 => '12345', + ), ); $record->append_fields(@fields); return $record; -- 2.39.5