|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# Copyright 2024 Koha Development team |
| 4 |
# |
| 5 |
# This file is part of Koha |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <https://www.gnu.org/licenses> |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
|
| 22 |
use Test::MockModule; |
| 23 |
use Test::More tests => 2; |
| 24 |
|
| 25 |
use t::lib::Mocks::Logger; |
| 26 |
use t::lib::TestBuilder; |
| 27 |
|
| 28 |
my $schema = Koha::Database->new->schema; |
| 29 |
my $builder = t::lib::TestBuilder->new; |
| 30 |
my $logger = t::lib::Mocks::Logger->new; |
| 31 |
|
| 32 |
use_ok('Koha::ImportBatch'); |
| 33 |
|
| 34 |
subtest 'Koha::ImportBatch->new_from_file tests' => sub { |
| 35 |
|
| 36 |
plan tests => 2; |
| 37 |
|
| 38 |
$schema->storage->txn_begin; |
| 39 |
|
| 40 |
my $mocked_c4_importbatch = Test::MockModule->new('C4::ImportBatch'); |
| 41 |
$mocked_c4_importbatch->mock( |
| 42 |
'RecordsFromMARCXMLFile', |
| 43 |
sub { |
| 44 |
return ( [ "marcxml error 1", "error 2" ], [] ); |
| 45 |
} |
| 46 |
); |
| 47 |
|
| 48 |
Koha::ImportBatch->new_from_file( { record_type => 'biblio', format => 'MARCXML', filepath => 'none' } ); |
| 49 |
$logger->warn_is( |
| 50 |
"The following error(s) occurred during MARCXML record import:\nERROR: marcxml error 1\nERROR: error 2", |
| 51 |
"Errors are being logged" |
| 52 |
); |
| 53 |
|
| 54 |
$mocked_c4_importbatch->mock( |
| 55 |
'RecordsFromISO2709File', |
| 56 |
sub { |
| 57 |
return ( [ "iso2709 error 1", "error 2" ], [] ); |
| 58 |
} |
| 59 |
); |
| 60 |
|
| 61 |
Koha::ImportBatch->new_from_file( { record_type => 'biblio', format => 'ISO2709', filepath => 'none' } ); |
| 62 |
$logger->warn_is( |
| 63 |
"The following error(s) occurred during ISO2709 record import:\nERROR: iso2709 error 1\nERROR: error 2", |
| 64 |
"Errors are being logged" |
| 65 |
); |
| 66 |
|
| 67 |
$schema->storage->txn_rollback; |
| 68 |
}; |