@@ -, +, @@
and GetTitleImportRecord
---
t/db_dependent/ImportBatch.t | 93 +++++++++++++++++++++++++++++++++++-
1 file changed, 91 insertions(+), 2 deletions(-)
--- a/t/db_dependent/ImportBatch.t
+++ a/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;
--