|
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 20-26
BEGIN {
Link Here
|
| 20 |
use_ok('Koha::Plugins'); |
20 |
use_ok('Koha::Plugins'); |
| 21 |
use_ok( |
21 |
use_ok( |
| 22 |
'C4::ImportBatch', |
22 |
'C4::ImportBatch', |
| 23 |
qw( AddImportBatch GetImportBatch AddBiblioToBatch AddItemsToImportBiblio SetMatchedBiblionumber GetImportBiblios GetItemNumbersFromImportBatch CleanBatch DeleteBatch RecordsFromMarcPlugin BatchCommitRecords ) |
23 |
qw( AddImportBatch GetImportBatch AddBiblioToBatch AddItemsToImportBiblio SetMatchedBiblionumber GetImportBiblios GetItemNumbersFromImportBatch CleanBatch DeleteBatch RecordsFromMarcPlugin BatchCommitRecords GetBadBranchesImportItems ) |
| 24 |
); |
24 |
); |
| 25 |
} |
25 |
} |
| 26 |
|
26 |
|
|
Lines 203-208
$dbh->do( "DELETE FROM items WHERE itemnumber=?", undef, $itemno );
Link Here
|
| 203 |
is( @a, 0, 'No item numbers expected since we deleted the item' ); |
203 |
is( @a, 0, 'No item numbers expected since we deleted the item' ); |
| 204 |
$dbh->do( $sql, undef, undef, $import_record_id ); # remove link again |
204 |
$dbh->do( $sql, undef, undef, $import_record_id ); # remove link again |
| 205 |
|
205 |
|
|
|
206 |
# Test GetTitleImportRecord |
| 207 |
my $title_import_record = C4::ImportBatch::GetTitleImportRecord($import_record_id); |
| 208 |
is( $title_import_record, 'The art of computer programming', 'GetTitleImportRecord should return the correct title' ); |
| 209 |
|
| 206 |
# fresh data |
210 |
# fresh data |
| 207 |
my $sample_import_batch3 = { |
211 |
my $sample_import_batch3 = { |
| 208 |
matcher_id => 3, |
212 |
matcher_id => 3, |
|
Lines 431-436
subtest "BatchCommitRecords overlay into framework" => sub {
Link Here
|
| 431 |
is( $biblio->frameworkcode, "QQ", "Framework set on overlay" ); |
435 |
is( $biblio->frameworkcode, "QQ", "Framework set on overlay" ); |
| 432 |
}; |
436 |
}; |
| 433 |
|
437 |
|
|
|
438 |
subtest "GetBadBranchesImportItems" => sub { |
| 439 |
plan tests => 2; |
| 440 |
t::lib::Mocks::mock_config( 'enable_plugins', 0 ); |
| 441 |
my $mock_import = Test::MockModule->new("C4::ImportBatch"); |
| 442 |
my $biblio = $builder->build_sample_biblio; |
| 443 |
$mock_import->mock( _get_commit_action => sub { return ( 'replace', 'ignore', $biblio->biblionumber ); } ); |
| 444 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 445 |
|
| 446 |
my $import_batch = { |
| 447 |
matcher_id => 2, |
| 448 |
template_id => 2, |
| 449 |
branchcode => 'CTL', |
| 450 |
overlay_action => 'replace', |
| 451 |
nomatch_action => 'ignore', |
| 452 |
item_action => 'ignore', |
| 453 |
import_status => 'staged', |
| 454 |
batch_type => 'z3950', |
| 455 |
file_name => 'test.mrc', |
| 456 |
comments => 'test', |
| 457 |
record_type => 'auth', |
| 458 |
}; |
| 459 |
my $id_import_batch = C4::ImportBatch::AddImportBatch($import_batch); |
| 460 |
my $import_record_id = AddBiblioToBatch( $id_import_batch, 0, $biblio->metadata->record, 'utf8', 0 ); |
| 461 |
|
| 462 |
my $import_item1 = $builder->build_object( |
| 463 |
{ |
| 464 |
class => 'Koha::Import::Record::Items', |
| 465 |
value => { |
| 466 |
import_record_id => $import_record_id, |
| 467 |
marcxml => qq{<?xml version="1.0" encoding="UTF-8"?> |
| 468 |
<collection |
| 469 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 470 |
xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd" |
| 471 |
xmlns="http://www.loc.gov/MARC21/slim"> |
| 472 |
|
| 473 |
<record> |
| 474 |
<leader>00000 a </leader> |
| 475 |
<datafield tag="952" ind1=" " ind2=" "> |
| 476 |
<subfield code="a">${\($library->branchcode)}</subfield> |
| 477 |
<subfield code="b">${\($library->branchcode)}</subfield> |
| 478 |
<subfield code="c">GEN</subfield> |
| 479 |
<subfield code="p">test1234</subfield> |
| 480 |
<subfield code="y">BK</subfield> |
| 481 |
</datafield> |
| 482 |
</record> |
| 483 |
</collection> |
| 484 |
}, |
| 485 |
} |
| 486 |
} |
| 487 |
); |
| 488 |
|
| 489 |
my @items = GetBadBranchesImportItems($id_import_batch); |
| 490 |
is( scalar @items, 0, "No items with bad branchcode" ); |
| 491 |
|
| 492 |
my $import_item2 = $builder->build_object( |
| 493 |
{ |
| 494 |
class => 'Koha::Import::Record::Items', |
| 495 |
value => { |
| 496 |
import_record_id => $import_record_id, |
| 497 |
marcxml => qq{<?xml version="1.0" encoding="UTF-8"?> |
| 498 |
<collection |
| 499 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 500 |
xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd" |
| 501 |
xmlns="http://www.loc.gov/MARC21/slim"> |
| 502 |
|
| 503 |
<record> |
| 504 |
<leader>00000 a </leader> |
| 505 |
<datafield tag="952" ind1=" " ind2=" "> |
| 506 |
<subfield code="a">ABC</subfield> |
| 507 |
<subfield code="b">ABC</subfield> |
| 508 |
<subfield code="c">GEN</subfield> |
| 509 |
<subfield code="p">test1234</subfield> |
| 510 |
<subfield code="y">BK</subfield> |
| 511 |
</datafield> |
| 512 |
</record> |
| 513 |
</collection> |
| 514 |
}, |
| 515 |
} |
| 516 |
} |
| 517 |
); |
| 518 |
|
| 519 |
@items = GetBadBranchesImportItems($id_import_batch); |
| 520 |
is( scalar @items, 2, "Items with bad branchcode" ); |
| 521 |
}; |
| 522 |
|
| 434 |
subtest "Do not adjust biblionumber when replacing items during import" => sub { |
523 |
subtest "Do not adjust biblionumber when replacing items during import" => sub { |
| 435 |
plan tests => 7; |
524 |
plan tests => 7; |
| 436 |
|
525 |
|
| 437 |
- |
|
|