From 4ca639a5f64347db02416c881d15ff0e53ee4cb7 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 29 May 2024 13:54:52 +0000 Subject: [PATCH] Bug 35989: (QA follow-up) Add test and limit variable scope Before this patch if a record had a 751 and a 781 you could have fields repeated. This patch reduces the scope of the fields to subdivision variable as it is only used in processing 7xx fields and should not be shared between fields. I also add unit tests Signed-off-by: Nick Clemens Signed-off-by: Aleisha Amohia Signed-off-by: Martin Renvoize (cherry picked from commit 95f2aecc1b57b7c4bb8326f9f2fc9366a042a9c1) Signed-off-by: Lucas Gass --- C4/AuthoritiesMarc.pm | 6 +++--- t/db_dependent/AuthoritiesMarc.t | 27 ++++++++++++++++++++------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index ecc8c53d42..4c61f8bedb 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -1015,8 +1015,7 @@ sub BuildSummary { use C4::Heading::MARC21; my $handler = C4::Heading::MARC21->new(); my $subfields_to_report; - my $subfields_to_subdivision = ""; - my $delimiter = C4::Context->preference('AuthoritySeparator'); + my $delimiter = C4::Context->preference('AuthoritySeparator'); foreach my $field ($record->field('1..')) { my $tag = $field->tag(); @@ -1095,7 +1094,8 @@ sub BuildSummary { push @notes, { note => $field->as_string(), field => $field->tag() }; } - foreach my $field ( $record->field('7..') ) { + foreach my $field ( $record->field('7..') ) { + my $subfields_to_subdivision; my $tag = $field->tag(); if ( $tag eq '700' ) { diff --git a/t/db_dependent/AuthoritiesMarc.t b/t/db_dependent/AuthoritiesMarc.t index 3823dd9d5c..e1b117fbc6 100755 --- a/t/db_dependent/AuthoritiesMarc.t +++ b/t/db_dependent/AuthoritiesMarc.t @@ -41,8 +41,10 @@ $module->mock('GetAuthority', sub { $record->add_fields( [ '001', '2' ], [ '151', ' ', ' ', a => 'New York (State)' ], - [ '551', ' ', ' ', a => 'United States', w => 'g', 9 => '1' ] - ); + [ '551', ' ', ' ', a => 'United States', w => 'g', 9 => '1' ], + [ '751', ' ', ' ', a => 'United States', w => 'g', 9 => '1' ], + [ '781', ' ', ' ', a => 'New York', x => 'General subdivision', 9 => '1' ] + ); } elsif ($authid eq '3') { $record->add_fields( [ '001', '3' ], @@ -151,14 +153,25 @@ my $expected_marc21_summary = { 'type' => 'broader' } ], - 'seefrom' => [], - 'label' => 'Geographic Name', - 'type' => 'Geographic Name', - 'equalterm' => [] + 'equalterm' => [ + { + 'field' => '751', + 'hemain' => 'United States', + 'heading' => 'United States' + }, + { + 'hemain' => undef, + 'field' => '781', + 'heading' => 'General subdivision' + } + ], + 'seefrom' => [], + 'label' => 'Geographic Name', + 'type' => 'Geographic Name', }; is_deeply( - BuildSummary(C4::AuthoritiesMarc::GetAuthority(2), 2, 'GEOGR_NAME'), + BuildSummary( C4::AuthoritiesMarc::GetAuthority(2), 2, 'GEOGR_NAME' ), $expected_marc21_summary, 'test BuildSummary for MARC21' ); -- 2.39.5