From 654588fcb7d0d3f33a9a87955a2ea7719984b127 Mon Sep 17 00:00:00 2001 From: Kyle Hall Date: Mon, 6 Feb 2023 11:55:48 -0500 Subject: [PATCH] Bug 32804: Add unit tests --- t/db_dependent/ImportBatch.t | 47 +++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/ImportBatch.t b/t/db_dependent/ImportBatch.t index 0184a8f5c5..f1d951cb2c 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/; @@ -328,6 +328,51 @@ subtest "_get_commit_action" => sub { }; +subtest "Do not adjust biblionumber when replacing items during import" => sub { + plan tests => 6; + + my $item1 = $builder->build_sample_item; + my $item2 = $builder->build_sample_item; + + my $library = $builder->build_object({ class => 'Koha::Libraries' }); + + my $import_item = $builder->build_object({ class => 'Koha::Import::Record::Items', value => { + marcxml => qq{ + + + + 00000 a + + ${\($library->branchcode)} + ${\($library->branchcode)} + GEN + ${\($item1->barcode)} + BK + + + + }, + }}); + + isnt( $item1->homebranch, $library->branchcode, "Item's homebranch is currently not the same as our created branch's branchcode" ); + + my ( $num_items_added, $num_items_replaced, $num_items_errored ) = + C4::ImportBatch::_batchCommitItems( $import_item->import_record_id, $item2->biblionumber, 'replace' ); + + $item1->discard_changes(); + + is( $num_items_errored, 0, 'Item was replaced' ); + $import_item->discard_changes(); + is( $import_item->status, 'imported', 'Import was successful'); + is( $import_item->import_error, undef, 'No error was reported' ); + + is( $item1->biblionumber, $item1->biblioitemnumber, "Item's biblionumber and biblioitemnumber match" ); + is( $item1->homebranch, $library->branchcode, "Item was overlayed succesfully" ); +}; + 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