From 121e3dc94a926cc2d7155c651f40778b97462eb5 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 21 Sep 2022 21:13:17 +0000 Subject: [PATCH] Bug 15869: Unit test Signed-off-by: Andrew Fuerste-Henry --- t/db_dependent/ImportBatch.t | 39 ++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/ImportBatch.t b/t/db_dependent/ImportBatch.t index 0184a8f5c5..a745861bd6 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 => 18; +use Test::More tests => 19; 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 )); + use_ok('C4::ImportBatch', qw( AddImportBatch GetImportBatch AddBiblioToBatch AddItemsToImportBiblio SetMatchedBiblionumber GetImportBiblios GetItemNumbersFromImportBatch CleanBatch DeleteBatch RecordsFromMarcPlugin BatchCommitRecords )); } # Start transaction @@ -328,6 +328,41 @@ subtest "_get_commit_action" => sub { }; +subtest "BatchCommitRecords overlay into framework" => sub { + plan tests => 1; + 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',undef,$biblio->biblionumber); } ); + + my $import_batch = { + matcher_id => 2, + template_id => 2, + branchcode => 'QRZ', + 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 ); + + BatchCommitRecords({ + batch_id => $id_import_batch, + framework => "", + overlay_framework => "QQ", + }); + $biblio->discard_changes; + is( $biblio->frameworkcode, "QQ", "Framework set on overlay" ); +}; + + + + sub get_import_record { my $id_import_batch = shift; return $dbh->do('SELECT * FROM import_records WHERE import_batch_id = ?', undef, $id_import_batch); -- 2.30.2