Bug 15869: Unit test
authorNick Clemens <nick@bywatersolutions.com>
Wed, 21 Sep 2022 21:13:17 +0000 (21:13 +0000)
committerJacob O'Mara <jacob.omara@ptfs-europe.com>
Wed, 8 Feb 2023 16:34:30 +0000 (16:34 +0000)
Signed-off-by: Andrew Fuerste-Henry <andrewfh@dubcolib.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit 3a3eff3fc45a25afe8b86ef3500fda2dc0875c62)
Signed-off-by: Jacob O'Mara <jacob.omara@ptfs-europe.com>
t/db_dependent/ImportBatch.t

index 0184a8f..a745861 100755 (executable)
@@ -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);