|
Lines 1-7
Link Here
|
| 1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
| 2 |
|
2 |
|
| 3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
| 4 |
use Test::More tests => 20; |
4 |
use Test::More tests => 22; |
| 5 |
use utf8; |
5 |
use utf8; |
| 6 |
use File::Basename; |
6 |
use File::Basename; |
| 7 |
use File::Temp qw/tempfile/; |
7 |
use File::Temp qw/tempfile/; |
|
Lines 18-24
BEGIN {
Link Here
|
| 18 |
t::lib::Mocks::mock_config( 'pluginsdir', $path ); |
18 |
t::lib::Mocks::mock_config( 'pluginsdir', $path ); |
| 19 |
|
19 |
|
| 20 |
use_ok('Koha::Plugins'); |
20 |
use_ok('Koha::Plugins'); |
| 21 |
use_ok('C4::ImportBatch', qw( AddImportBatch GetImportBatch AddBiblioToBatch AddItemsToImportBiblio SetMatchedBiblionumber GetImportBiblios GetItemNumbersFromImportBatch CleanBatch DeleteBatch RecordsFromMarcPlugin BatchCommitRecords )); |
21 |
use_ok('C4::ImportBatch', qw( GetBadBranchesImportItems AddImportBatch GetImportBatch AddBiblioToBatch AddItemsToImportBiblio SetMatchedBiblionumber GetImportBiblios GetItemNumbersFromImportBatch CleanBatch DeleteBatch RecordsFromMarcPlugin BatchCommitRecords )); |
| 22 |
} |
22 |
} |
| 23 |
|
23 |
|
| 24 |
# Start transaction |
24 |
# Start transaction |
|
Lines 188-193
$dbh->do( "DELETE FROM items WHERE itemnumber=?", undef, $itemno );
Link Here
|
| 188 |
is( @a, 0, 'No item numbers expected since we deleted the item' ); |
188 |
is( @a, 0, 'No item numbers expected since we deleted the item' ); |
| 189 |
$dbh->do( $sql, undef, undef, $import_record_id ); # remove link again |
189 |
$dbh->do( $sql, undef, undef, $import_record_id ); # remove link again |
| 190 |
|
190 |
|
|
|
191 |
# Test GetTitleImportRecord |
| 192 |
my $title_import_record = C4::ImportBatch::GetTitleImportRecord($import_record_id); |
| 193 |
is( $title_import_record, 'The art of computer programming', 'GetTitleImportRecord should return the correct title' ); |
| 194 |
|
| 191 |
# fresh data |
195 |
# fresh data |
| 192 |
my $sample_import_batch3 = { |
196 |
my $sample_import_batch3 = { |
| 193 |
matcher_id => 3, |
197 |
matcher_id => 3, |
|
Lines 388-393
subtest "BatchCommitRecords overlay into framework" => sub {
Link Here
|
| 388 |
is( $biblio->frameworkcode, "QQ", "Framework set on overlay" ); |
392 |
is( $biblio->frameworkcode, "QQ", "Framework set on overlay" ); |
| 389 |
}; |
393 |
}; |
| 390 |
|
394 |
|
|
|
395 |
subtest "GetBadBranchesImportItems" => sub { |
| 396 |
plan tests => 2; |
| 397 |
t::lib::Mocks::mock_config( 'enable_plugins', 0 ); |
| 398 |
my $mock_import = Test::MockModule->new("C4::ImportBatch"); |
| 399 |
my $biblio = $builder->build_sample_biblio; |
| 400 |
$mock_import->mock( _get_commit_action => sub { return ( 'replace', 'ignore', $biblio->biblionumber ); } ); |
| 401 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 402 |
|
| 403 |
my $import_batch = { |
| 404 |
matcher_id => 2, |
| 405 |
template_id => 2, |
| 406 |
branchcode => 'CTL', |
| 407 |
overlay_action => 'replace', |
| 408 |
nomatch_action => 'ignore', |
| 409 |
item_action => 'ignore', |
| 410 |
import_status => 'staged', |
| 411 |
batch_type => 'z3950', |
| 412 |
file_name => 'test.mrc', |
| 413 |
comments => 'test', |
| 414 |
record_type => 'auth', |
| 415 |
}; |
| 416 |
my $id_import_batch = C4::ImportBatch::AddImportBatch($import_batch); |
| 417 |
my $import_record_id = AddBiblioToBatch( $id_import_batch, 0, $biblio->metadata->record, 'utf8', 0 ); |
| 418 |
|
| 419 |
my $import_item1 = $builder->build_object( |
| 420 |
{ |
| 421 |
class => 'Koha::Import::Record::Items', |
| 422 |
value => { |
| 423 |
import_record_id => $import_record_id, |
| 424 |
marcxml => qq{<?xml version="1.0" encoding="UTF-8"?> |
| 425 |
<collection |
| 426 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 427 |
xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd" |
| 428 |
xmlns="http://www.loc.gov/MARC21/slim"> |
| 429 |
|
| 430 |
<record> |
| 431 |
<leader>00000 a </leader> |
| 432 |
<datafield tag="952" ind1=" " ind2=" "> |
| 433 |
<subfield code="a">${\($library->branchcode)}</subfield> |
| 434 |
<subfield code="b">${\($library->branchcode)}</subfield> |
| 435 |
<subfield code="c">GEN</subfield> |
| 436 |
<subfield code="p">test1234</subfield> |
| 437 |
<subfield code="y">BK</subfield> |
| 438 |
</datafield> |
| 439 |
</record> |
| 440 |
</collection> |
| 441 |
}, |
| 442 |
} |
| 443 |
} |
| 444 |
); |
| 445 |
|
| 446 |
my @items = GetBadBranchesImportItems($id_import_batch); |
| 447 |
is( scalar @items, 0, "No items with bad branchcode" ); |
| 448 |
|
| 449 |
my $import_item2 = $builder->build_object( |
| 450 |
{ |
| 451 |
class => 'Koha::Import::Record::Items', |
| 452 |
value => { |
| 453 |
import_record_id => $import_record_id, |
| 454 |
marcxml => qq{<?xml version="1.0" encoding="UTF-8"?> |
| 455 |
<collection |
| 456 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 457 |
xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd" |
| 458 |
xmlns="http://www.loc.gov/MARC21/slim"> |
| 459 |
|
| 460 |
<record> |
| 461 |
<leader>00000 a </leader> |
| 462 |
<datafield tag="952" ind1=" " ind2=" "> |
| 463 |
<subfield code="a">ABC</subfield> |
| 464 |
<subfield code="b">ABC</subfield> |
| 465 |
<subfield code="c">GEN</subfield> |
| 466 |
<subfield code="p">test1234</subfield> |
| 467 |
<subfield code="y">BK</subfield> |
| 468 |
</datafield> |
| 469 |
</record> |
| 470 |
</collection> |
| 471 |
}, |
| 472 |
} |
| 473 |
} |
| 474 |
); |
| 475 |
|
| 476 |
@items = GetBadBranchesImportItems($id_import_batch); |
| 477 |
is( scalar @items, 2, "Items with bad branchcode" ); |
| 478 |
}; |
| 479 |
|
| 391 |
subtest "Do not adjust biblionumber when replacing items during import" => sub { |
480 |
subtest "Do not adjust biblionumber when replacing items during import" => sub { |
| 392 |
plan tests => 7; |
481 |
plan tests => 7; |
| 393 |
|
482 |
|
| 394 |
- |
|
|