From d742f2bb694c8b2a8c72b43f96f8349999e69efc 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 | 44 +++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/ImportBatch.t b/t/db_dependent/ImportBatch.t index 1ff0eddd33..8a0e25bfc9 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 => 19; +use Test::More tests => 20; use utf8; use File::Basename; use File::Temp qw/tempfile/; @@ -360,8 +360,50 @@ subtest "BatchCommitRecords overlay into framework" => sub { is( $biblio->frameworkcode, "QQ", "Framework set on overlay" ); }; +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; -- 2.30.2