From de94383b9dab31797db9855cd6e6180b8df03e93 Mon Sep 17 00:00:00 2001 From: Matthias Le Gac Date: Fri, 29 Mar 2024 15:20:42 -0400 Subject: [PATCH] Bug 21272: Unit test for methods GetBadBranchesImportItems and GetTitleImportRecord --- t/db_dependent/ImportBatch.t | 93 +++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/ImportBatch.t b/t/db_dependent/ImportBatch.t index 9e57c9c81e..6dfafedf52 100755 --- a/t/db_dependent/ImportBatch.t +++ b/t/db_dependent/ImportBatch.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use Modern::Perl; -use Test::More tests => 20; +use Test::More tests => 22; use utf8; use File::Basename; use File::Temp qw/tempfile/; @@ -18,7 +18,7 @@ BEGIN { t::lib::Mocks::mock_config( 'pluginsdir', $path ); use_ok('Koha::Plugins'); - use_ok('C4::ImportBatch', qw( AddImportBatch GetImportBatch AddBiblioToBatch AddItemsToImportBiblio SetMatchedBiblionumber GetImportBiblios GetItemNumbersFromImportBatch CleanBatch DeleteBatch RecordsFromMarcPlugin BatchCommitRecords )); + use_ok('C4::ImportBatch', qw( GetBadBranchesImportItems AddImportBatch GetImportBatch AddBiblioToBatch AddItemsToImportBiblio SetMatchedBiblionumber GetImportBiblios GetItemNumbersFromImportBatch CleanBatch DeleteBatch RecordsFromMarcPlugin BatchCommitRecords )); } # Start transaction @@ -188,6 +188,10 @@ $dbh->do( "DELETE FROM items WHERE itemnumber=?", undef, $itemno ); is( @a, 0, 'No item numbers expected since we deleted the item' ); $dbh->do( $sql, undef, undef, $import_record_id ); # remove link again +# Test GetTitleImportRecord +my $title_import_record = C4::ImportBatch::GetTitleImportRecord($import_record_id); +is( $title_import_record, 'The art of computer programming', 'GetTitleImportRecord should return the correct title' ); + # fresh data my $sample_import_batch3 = { matcher_id => 3, @@ -388,6 +392,91 @@ subtest "BatchCommitRecords overlay into framework" => sub { is( $biblio->frameworkcode, "QQ", "Framework set on overlay" ); }; +subtest "GetBadBranchesImportItems" => sub { + plan tests => 2; + t::lib::Mocks::mock_config( 'enable_plugins', 0 ); + my $mock_import = Test::MockModule->new("C4::ImportBatch"); + my $biblio = $builder->build_sample_biblio; + $mock_import->mock( _get_commit_action => sub { return ( 'replace', 'ignore', $biblio->biblionumber ); } ); + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + + my $import_batch = { + matcher_id => 2, + template_id => 2, + branchcode => 'CTL', + overlay_action => 'replace', + nomatch_action => 'ignore', + item_action => 'ignore', + import_status => 'staged', + batch_type => 'z3950', + file_name => 'test.mrc', + comments => 'test', + record_type => 'auth', + }; + my $id_import_batch = C4::ImportBatch::AddImportBatch($import_batch); + my $import_record_id = AddBiblioToBatch( $id_import_batch, 0, $biblio->metadata->record, 'utf8', 0 ); + + my $import_item1 = $builder->build_object( + { + class => 'Koha::Import::Record::Items', + value => { + import_record_id => $import_record_id, + marcxml => qq{ + + + + 00000 a + + ${\($library->branchcode)} + ${\($library->branchcode)} + GEN + test1234 + BK + + + + }, + } + } + ); + + my @items = GetBadBranchesImportItems($id_import_batch); + is( scalar @items, 0, "No items with bad branchcode" ); + + my $import_item2 = $builder->build_object( + { + class => 'Koha::Import::Record::Items', + value => { + import_record_id => $import_record_id, + marcxml => qq{ + + + + 00000 a + + ABC + ABC + GEN + test1234 + BK + + + + }, + } + } + ); + + @items = GetBadBranchesImportItems($id_import_batch); + is( scalar @items, 2, "Items with bad branchcode" ); +}; + subtest "Do not adjust biblionumber when replacing items during import" => sub { plan tests => 7; -- 2.34.1