From 99fd20d2d7bb04e13cb0bc1c6c79b0d3aaf23e56 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 21 Oct 2021 15:51:50 +0200 Subject: [PATCH] Bug 14957: Add tests for subfield order Signed-off-by: Martin Renvoize --- t/db_dependent/Biblio/MarcOverlayRules.t | 49 +++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Biblio/MarcOverlayRules.t b/t/db_dependent/Biblio/MarcOverlayRules.t index a0c672f2ec..29aeeafa06 100755 --- a/t/db_dependent/Biblio/MarcOverlayRules.t +++ b/t/db_dependent/Biblio/MarcOverlayRules.t @@ -25,7 +25,7 @@ use C4::Context; use C4::Biblio qw( AddBiblio ModBiblio DelBiblio GetMarcBiblio ); use Koha::Database; -use Test::More tests => 23; +use Test::More tests => 24; use Test::MockModule; use Koha::MarcOverlayRules; @@ -570,6 +570,53 @@ subtest 'Record fields has been overwritten when add = 1, append = 1, remove = 1 }; +subtest 'subfields order' => sub { + plan tests => 2; + + $rule->set( + { + 'add' => 0, + 'append' => 0, + 'remove' => 0, + 'delete' => 0, + } + )->store(); + + my $incoming_record = build_record( + [ + [ '250', 'a', '256 bottles of beer on the wall' ], + [ '250', 'a', '250 bottles of beer on the wall' ], + [ '500', 'a', 'One bottle of beer in the fridge' ], + ] + ); + + my $merged_record = Koha::MarcOverlayRules->merge_records($orig_record, $incoming_record, { 'source' => 'test' }); + + is( + $merged_record->as_formatted, + $orig_record->as_formatted, + 'Original record not modified - order of subfields not modified' + ); + + $rule->set( + { + 'add' => 1, + 'append' => 1, + 'remove' => 1, + 'delete' => 1, + } + )->store(); + + $merged_record = Koha::MarcOverlayRules->merge_records($orig_record, $incoming_record, { 'source' => 'test' }); + + is( + $merged_record->as_formatted, + $incoming_record->as_formatted, + 'Original record modified - order of subfields has been modified' + ); + +}; + # Test rule tag specificity # Protect field 500 with more specific tag value -- 2.20.1