From 45b9fc60e8e8c35ab651714072513fd99d715450 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 26 Feb 2026 13:43:21 +0000 Subject: [PATCH] Bug 35104: Update Biblio.t to reflect graceful non-XML stripping behaviour The ModBiblio subtest was written for the old exception-throwing behaviour where invalid MARC would emit a Perl warn() and the error would appear in the action log. With the graceful stripping introduced by this bug: - StripNonXmlChars recovers the record silently (no Perl warn()) - The stripping event is reported via the warnings arrayref in $options - nonxml_stripped is persisted on biblio_metadata - ModBiblio still succeeds and logs the modification to action logs Update the three assertions accordingly. Sponsored-by: OpenFifth --- misc/migration_tools/bulkmarcimport.pl | 8 ++++--- t/db_dependent/Biblio.t | 31 ++++++++++++++++---------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/misc/migration_tools/bulkmarcimport.pl b/misc/migration_tools/bulkmarcimport.pl index 76505928174..56a3b8887f4 100755 --- a/misc/migration_tools/bulkmarcimport.pl +++ b/misc/migration_tools/bulkmarcimport.pl @@ -564,7 +564,7 @@ RECORD: while () { # Create biblio, unless we already have it (either match or ISBN) my @import_warnings; $mod_biblio_options->{warnings} = \@import_warnings; - $add_biblio_options->{warnings} = \@import_warnings; + $add_biblio_options->{warnings} = \@import_warnings; if ($matched_record_id) { eval { $biblioitemnumber = Koha::Biblios->find($matched_record_id)->biblioitem->biblioitemnumber; }; if ($update) { @@ -626,8 +626,10 @@ RECORD: while () { next RECORD; } for my $w ( grep { $_->{type} eq 'nonxml_stripped' } @import_warnings ) { - warn sprintf( "WARNING: Non-XML characters stripped from biblio %s: %s\n", - $record_id // $originalid, $w->{message} ); + warn sprintf( + "WARNING: Non-XML characters stripped from biblio %s: %s\n", + $record_id // $originalid, $w->{message} + ); printlog( { id => $record_id // $originalid, diff --git a/t/db_dependent/Biblio.t b/t/db_dependent/Biblio.t index bca89014a23..2107fba2d02 100755 --- a/t/db_dependent/Biblio.t +++ b/t/db_dependent/Biblio.t @@ -1204,29 +1204,36 @@ subtest 'GetFrameworkCode' => sub { }; -subtest 'ModBiblio on invalid record' => sub { +subtest 'ModBiblio on record with strippable non-XML characters' => sub { plan tests => 3; t::lib::Mocks::mock_preference( "CataloguingLog", 1 ); - # We create a record with an onvalid control character in the MARC + # We create a record with an invalid control character (chr(31)) in the MARC my $record = MARC::Record->new(); - my $field = MARC::Field->new( '650', '', '', 'a' => '00aD000015937' ); + my $field = MARC::Field->new( '650', '', '', 'a' => '00' . chr(31) . 'aD000015937' ); $record->append_fields($field); my ($biblionumber) = C4::Biblio::AddBiblio( $record, '' ); - warning_like { C4::Biblio::ModBiblio( $record, $biblionumber, '' ); } - qr/parser error : PCDATA invalid Char value 31/, - 'Modding the biblio warns about the encoding issues'; - my $action_logs = - Koha::ActionLogs->search( { object => $biblionumber, module => 'Cataloguing', action => 'MODIFY' } ); - is( $action_logs->count, 1, "Modification of biblio was successful and recorded" ); - my $action_log = $action_logs->next; + # New behaviour: strippable non-XML characters are silently fixed; the + # stripping event is reported via the warnings arrayref, not Perl warn() + my @warnings; + C4::Biblio::ModBiblio( $record, $biblionumber, '', { warnings => \@warnings } ); + like( + $warnings[0]{message}, qr/parser error : PCDATA invalid Char value 31/, + 'Non-XML character stripping reported via warnings arrayref' + ); + + my $metadata = Koha::Biblios->find($biblionumber)->metadata; like( - $action_log->info, qr/parser error : PCDATA invalid Char value 31/, - "Metadata issue successfully logged in action logs" + $metadata->nonxml_stripped, qr/parser error : PCDATA invalid Char value 31/, + 'nonxml_stripped persisted on biblio_metadata after ModBiblio' ); + + my $action_logs = + Koha::ActionLogs->search( { object => $biblionumber, module => 'Cataloguing', action => 'MODIFY' } ); + is( $action_logs->count, 1, "Modification of biblio was successfully recorded in action logs" ); }; subtest 'UpdateTotalIssues on Invalid record' => sub { -- 2.53.0