From 63719e25ab63416cd5294b228bcee107a2504a5b Mon Sep 17 00:00:00 2001 From: Hammat Wele Date: Fri, 12 Sep 2025 21:19:07 +0000 Subject: [PATCH] Bug 21272: (QA follow-up) Fix tidiness and unit test Signed-off-by: Hammat Wele --- C4/ImportBatch.pm | 8 +++--- .../en/modules/tools/manage-marc-import.tt | 11 ++++---- t/db_dependent/ImportBatch.t | 26 ++++++++++++++----- tools/manage-marc-import.pl | 4 +-- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm index bfcae76643b..199377f4cc1 100644 --- a/C4/ImportBatch.pm +++ b/C4/ImportBatch.pm @@ -42,7 +42,7 @@ use Koha::SearchEngine::Indexer; use Koha::Plugins::Handler; use Koha::Logger; use List::MoreUtils qw( uniq any ); -use Array::Utils qw( array_minus ); +use Array::Utils qw( array_minus ); our ( @ISA, @EXPORT_OK ); @@ -1287,7 +1287,7 @@ Returns an array of imported item branches. =cut sub GetImportItemsBranches { - my ( $batch_id ) = @_; + my ($batch_id) = @_; my $dbh = C4::Context->dbh; my $query = "SELECT import_items_id, import_items.marcxml, encoding @@ -1303,8 +1303,10 @@ sub GetImportItemsBranches { my @branch; my ( $homebranchfield, $homebranchsubfield ) = GetMarcFromKohaField('items.homebranch'); my ( $holdingbranchfield, $holdingbranchsubfield ) = GetMarcFromKohaField('items.holdingbranch'); + foreach my $row (@$results) { - my $item_marc = MARC::Record->new_from_xml( StripNonXmlChars( $row->{'marcxml'} ), 'UTF-8', $row->{'encoding'} ); + my $item_marc = + MARC::Record->new_from_xml( StripNonXmlChars( $row->{'marcxml'} ), 'UTF-8', $row->{'encoding'} ); push @branch, $item_marc->subfield( $homebranchfield, $homebranchsubfield ); push @branch, $item_marc->subfield( $holdingbranchfield, $holdingbranchsubfield ); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt index c558b956dfa..49c423eb53c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tt @@ -258,11 +258,12 @@ [% IF ( missing_branches ) %] -
One and more records contains incorrect library codes which are not part of your installation: +
One and more records contains incorrect library codes which are not part of your installation: - [% FOREACH branche IN branches %] - [% branche | html %] - [% END %] + [% FOREACH branche IN branches %] + [% branche | html %] + [% END %]
[% END %] @@ -272,7 +273,7 @@ [% FOREACH title IN titles %] [% title | html %] - | + | [% END %]
diff --git a/t/db_dependent/ImportBatch.t b/t/db_dependent/ImportBatch.t index 55894c42b54..69d43f009ba 100755 --- a/t/db_dependent/ImportBatch.t +++ b/t/db_dependent/ImportBatch.t @@ -1,6 +1,7 @@ #!/usr/bin/perl use Modern::Perl; +use Test::NoWarnings; use Test::More tests => 23; use utf8; use File::Basename; @@ -274,8 +275,11 @@ subtest "_batchCommitItems" => sub { 'Error correctly set when import item has duplicate barcode and action always_add' ); - $import_item = $builder->build_object({ class => 'Koha::Import::Record::Items', value => { - marcxml => q{ + $import_item = $builder->build_object( + { + class => 'Koha::Import::Record::Items', + value => { + marcxml => q{ sub { }, - }}); + } + } + ); ( $num_items_added, $num_items_replaced, $num_items_errored ) = - C4::ImportBatch::_batchCommitItems( $import_item->import_record_id, 32, 'always_add',64 ); + C4::ImportBatch::_batchCommitItems( $import_item->import_record_id, 32, 'always_add', 64 ); is( $num_items_errored, 1, "Item with wrong branchcode fails when action always_add" ); $import_item->discard_changes(); - is( $import_item->status, 'error', "Import item marked as error when wrong branchcode detected and action always_add"); - is( $import_item->import_error, 'Branch code WBRC missing', 'Error correctly set when import item has a wrong branchcode detected and action always_add' ); + is( + $import_item->status, 'error', + "Import item marked as error when wrong branchcode detected and action always_add" + ); + is( + $import_item->import_error, 'Branch code WBRC missing', + 'Error correctly set when import item has a wrong branchcode detected and action always_add' + ); }; subtest "RecordsFromMarcPlugin" => sub { @@ -311,7 +323,7 @@ subtest "RecordsFromMarcPlugin" => sub { if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) { print $fh q{ 003 = NLAmRIJ -100,a = 20220520d u||y0frey50 ba +100,a = 20220520d u||y0frey50 by 700,a = Author 200,ind2 = 0 200,a = Silence in the library diff --git a/tools/manage-marc-import.pl b/tools/manage-marc-import.pl index 110e5bfb331..3cc0e40139f 100755 --- a/tools/manage-marc-import.pl +++ b/tools/manage-marc-import.pl @@ -37,7 +37,7 @@ use C4::Labels::Batch; use Koha::BiblioFrameworks; use Koha::BackgroundJob::MARCImportCommitBatch; use Koha::BackgroundJob::MARCImportRevertBatch; -use Array::Utils qw( array_minus ); +use Array::Utils qw( array_minus ); use List::MoreUtils qw( uniq any ); use Koha::Logger; @@ -96,7 +96,7 @@ if ( $op eq "" ) { import_batches_list( $template, $offset, $results_per_page ); } else { my @import_items_branches = GetImportItemsBranches($import_batch_id); - my @import_items = GetBadBranchesImportItems($import_batch_id); + my @import_items = GetBadBranchesImportItems($import_batch_id); my @bad_item_titles; my @missing_branches; foreach my $item (@import_items) { -- 2.34.1