From da5074a5453bfb5c0ebbb20a0b3a02e3b9ca35f2 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Thu, 16 Oct 2025 20:15:48 +0300 Subject: [PATCH] Bug 41036: Add tests To test: 1. Apply only this patch, do not yet apply the next one 2. prove t/db_dependent/Koha/ImportBatch.t 3. Observe tests failing --- t/db_dependent/Koha/ImportBatch.t | 68 +++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 t/db_dependent/Koha/ImportBatch.t diff --git a/t/db_dependent/Koha/ImportBatch.t b/t/db_dependent/Koha/ImportBatch.t new file mode 100644 index 00000000000..5fb7d519ad4 --- /dev/null +++ b/t/db_dependent/Koha/ImportBatch.t @@ -0,0 +1,68 @@ +#!/usr/bin/perl + +# Copyright 2024 Koha Development team +# +# This file is part of Koha +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see + +use Modern::Perl; + +use Test::MockModule; +use Test::More tests => 2; + +use t::lib::Mocks::Logger; +use t::lib::TestBuilder; + +my $schema = Koha::Database->new->schema; +my $builder = t::lib::TestBuilder->new; +my $logger = t::lib::Mocks::Logger->new; + +use_ok('Koha::ImportBatch'); + +subtest 'Koha::ImportBatch->new_from_file tests' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + my $mocked_c4_importbatch = Test::MockModule->new('C4::ImportBatch'); + $mocked_c4_importbatch->mock( + 'RecordsFromMARCXMLFile', + sub { + return ( [ "marcxml error 1", "error 2" ], [] ); + } + ); + + Koha::ImportBatch->new_from_file( { record_type => 'biblio', format => 'MARCXML', filepath => 'none' } ); + $logger->warn_is( + "The following error(s) occurred during MARCXML record import:\nERROR: marcxml error 1\nERROR: error 2", + "Errors are being logged" + ); + + $mocked_c4_importbatch->mock( + 'RecordsFromISO2709File', + sub { + return ( [ "iso2709 error 1", "error 2" ], [] ); + } + ); + + Koha::ImportBatch->new_from_file( { record_type => 'biblio', format => 'ISO2709', filepath => 'none' } ); + $logger->warn_is( + "The following error(s) occurred during ISO2709 record import:\nERROR: iso2709 error 1\nERROR: error 2", + "Errors are being logged" + ); + + $schema->storage->txn_rollback; +}; -- 2.34.1