Lines 18-24
Link Here
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::NoWarnings; |
20 |
use Test::NoWarnings; |
21 |
use Test::More tests => 7; |
21 |
use Test::More tests => 10; |
22 |
use Test::Warn; |
22 |
use Test::Warn; |
23 |
use t::lib::TestBuilder; |
23 |
use t::lib::TestBuilder; |
24 |
|
24 |
|
Lines 436-439
subtest '_get_record_for_export MARC field conditions' => sub {
Link Here
|
436 |
is( $record, undef, "Record condition \"not_exists(035a)\" should not match" ); |
436 |
is( $record, undef, "Record condition \"not_exists(035a)\" should not match" ); |
437 |
}; |
437 |
}; |
438 |
|
438 |
|
|
|
439 |
subtest 'export csv with marc modification template' => sub { |
440 |
plan tests => 1; |
441 |
my $csv_content = qq{Title=$title_field\$$title_subfield|Test=999\$9}; |
442 |
$dbh->do(q|INSERT INTO export_format(profile, description, content, csv_separator, field_separator, subfield_separator, encoding, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?)|, {}, "TEST_PROFILE_Records.t", "my useless desc", $csv_content, '|', ';', ',', 'utf8', 'marc'); |
443 |
my $csv_profile_id = $dbh->last_insert_id( undef, undef, 'export_format', undef ); |
444 |
|
445 |
my $template_id = C4::MarcModificationTemplates::AddModificationTemplate('test exporter'); |
446 |
C4::MarcModificationTemplates::AddModificationTemplateAction($template_id, 'add_field', 0, '999', '9', 'Foobar'); |
447 |
|
448 |
my $generated_csv_file = '/tmp/test_export_1.csv'; |
449 |
Koha::Exporter::Record::export({ |
450 |
record_type => 'bibs', |
451 |
record_ids => [ $biblionumber_1 ], |
452 |
format => 'csv', |
453 |
csv_profile_id => $csv_profile_id, |
454 |
marc_modification_template_id => $template_id, |
455 |
output_filepath => $generated_csv_file, |
456 |
}); |
457 |
|
458 |
my $expected_csv = <<EOF; |
459 |
Title|Test |
460 |
"$biblio_1_title"|Foobar |
461 |
EOF |
462 |
my $generated_csv_content = read_file( $generated_csv_file ); |
463 |
is( $generated_csv_content, $expected_csv, "Export CSV: Modification template should have been applied" ); |
464 |
}; |
465 |
|
466 |
subtest 'export xml with marc modification template' => sub { |
467 |
plan tests => 2; |
468 |
|
469 |
my $template_id = C4::MarcModificationTemplates::AddModificationTemplate('test exporter'); |
470 |
C4::MarcModificationTemplates::AddModificationTemplateAction($template_id, 'add_field', 0, '999', '9', 'Foobar'); |
471 |
|
472 |
my $generated_xml_file = '/tmp/test_export.xml'; |
473 |
Koha::Exporter::Record::export({ |
474 |
record_type => 'bibs', |
475 |
record_ids => [ $biblionumber_1 ], |
476 |
format => 'xml', |
477 |
marc_modification_template_id => $template_id, |
478 |
output_filepath => $generated_xml_file, |
479 |
}); |
480 |
|
481 |
my $generated_xml_content = read_file( $generated_xml_file ); |
482 |
$MARC::File::XML::_load_args{BinaryEncoding} = 'utf-8'; |
483 |
open my $fh, '<', $generated_xml_file; |
484 |
my $records = MARC::Batch->new( 'XML', $fh ); |
485 |
my @records; |
486 |
while ( my $record = $records->next ) { |
487 |
push @records, $record; |
488 |
} |
489 |
is( scalar( @records ), 1, 'Export XML: 1 record should have been exported' ); |
490 |
my $record = $records[0]; |
491 |
is( $record->subfield('999', '9'), 'Foobar', 'Export XML: marc modification template should have added 999$9' ); |
492 |
}; |
493 |
|
494 |
subtest 'export iso2709 with marc modification template' => sub { |
495 |
plan tests => 2; |
496 |
|
497 |
my $template_id = C4::MarcModificationTemplates::AddModificationTemplate('test exporter'); |
498 |
C4::MarcModificationTemplates::AddModificationTemplateAction($template_id, 'add_field', 0, '999', '9', 'Foobar'); |
499 |
|
500 |
my $generated_mrc_file = '/tmp/test_export.mrc'; |
501 |
Koha::Exporter::Record::export({ |
502 |
record_type => 'bibs', |
503 |
record_ids => [ $biblionumber_1 ], |
504 |
format => 'iso2709', |
505 |
marc_modification_template_id => $template_id, |
506 |
output_filepath => $generated_mrc_file, |
507 |
}); |
508 |
|
509 |
my $records = MARC::File::USMARC->in( $generated_mrc_file ); |
510 |
my @records; |
511 |
while ( my $record = $records->next ) { |
512 |
push @records, $record; |
513 |
} |
514 |
is( scalar( @records ), 1, 'Export ISO2709: 1 record should have been exported' ); |
515 |
my $record = $records[0]; |
516 |
is( $record->subfield('999', '9'), 'Foobar', 'Export ISO2709: marc modification template should have added 999$9' ); |
517 |
}; |
518 |
|
439 |
$schema->storage->txn_rollback; |
519 |
$schema->storage->txn_rollback; |