From d9c08273e34c6e8374e271eaedf636bc1a3d487d Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Tue, 13 Oct 2020 10:11:01 +0200 Subject: [PATCH] Bug 24679: Fix exporter tests Tidy, and use 998 instead of 999 which is used in MARC21 to store biblionumber --- t/db_dependent/Exporter/Record.t | 84 ++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/t/db_dependent/Exporter/Record.t b/t/db_dependent/Exporter/Record.t index 5d1cf83df97..6a01175d1b6 100755 --- a/t/db_dependent/Exporter/Record.t +++ b/t/db_dependent/Exporter/Record.t @@ -438,28 +438,33 @@ subtest '_get_record_for_export MARC field conditions' => sub { subtest 'export csv with marc modification template' => sub { plan tests => 1; - my $csv_content = qq{Title=$title_field\$$title_subfield|Test=999\$9}; - $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'); + my $csv_content = "Title=$title_field_tag\$a|Test=998\$9"; + $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' + ); my $csv_profile_id = $dbh->last_insert_id( undef, undef, 'export_format', undef ); my $template_id = C4::MarcModificationTemplates::AddModificationTemplate('test exporter'); - C4::MarcModificationTemplates::AddModificationTemplateAction($template_id, 'add_field', 0, '999', '9', 'Foobar'); + C4::MarcModificationTemplates::AddModificationTemplateAction( $template_id, 'add_field', 0, '998', '9', 'Foobar' ); my $generated_csv_file = '/tmp/test_export_1.csv'; - Koha::Exporter::Record::export({ - record_type => 'bibs', - record_ids => [ $biblionumber_1 ], - format => 'csv', - csv_profile_id => $csv_profile_id, - marc_modification_template_id => $template_id, - output_filepath => $generated_csv_file, - }); + Koha::Exporter::Record::export( + { + record_type => 'bibs', + record_ids => [$biblionumber_1], + format => 'csv', + csv_profile_id => $csv_profile_id, + marc_modification_template_id => $template_id, + output_filepath => $generated_csv_file, + } + ); my $expected_csv = < sub { plan tests => 2; my $template_id = C4::MarcModificationTemplates::AddModificationTemplate('test exporter'); - C4::MarcModificationTemplates::AddModificationTemplateAction($template_id, 'add_field', 0, '999', '9', 'Foobar'); + C4::MarcModificationTemplates::AddModificationTemplateAction( $template_id, 'add_field', 0, '998', '9', 'Foobar' ); my $generated_xml_file = '/tmp/test_export.xml'; - Koha::Exporter::Record::export({ - record_type => 'bibs', - record_ids => [ $biblionumber_1 ], - format => 'xml', - marc_modification_template_id => $template_id, - output_filepath => $generated_xml_file, - }); - - my $generated_xml_content = read_file( $generated_xml_file ); + Koha::Exporter::Record::export( + { + record_type => 'bibs', + record_ids => [$biblionumber_1], + format => 'xml', + marc_modification_template_id => $template_id, + output_filepath => $generated_xml_file, + } + ); + + my $generated_xml_content = read_file($generated_xml_file); $MARC::File::XML::_load_args{BinaryEncoding} = 'utf-8'; open my $fh, '<', $generated_xml_file; my $records = MARC::Batch->new( 'XML', $fh ); @@ -486,34 +493,39 @@ subtest 'export xml with marc modification template' => sub { while ( my $record = $records->next ) { push @records, $record; } - is( scalar( @records ), 1, 'Export XML: 1 record should have been exported' ); + is( scalar(@records), 1, 'Export XML: 1 record should have been exported' ); my $record = $records[0]; - is( $record->subfield('999', '9'), 'Foobar', 'Export XML: marc modification template should have added 999$9' ); + is( $record->subfield( '998', '9' ), 'Foobar', 'Export XML: marc modification template should have added 998$9' ); }; subtest 'export iso2709 with marc modification template' => sub { plan tests => 2; my $template_id = C4::MarcModificationTemplates::AddModificationTemplate('test exporter'); - C4::MarcModificationTemplates::AddModificationTemplateAction($template_id, 'add_field', 0, '999', '9', 'Foobar'); + C4::MarcModificationTemplates::AddModificationTemplateAction( $template_id, 'add_field', 0, '998', '9', 'Foobar' ); my $generated_mrc_file = '/tmp/test_export.mrc'; - Koha::Exporter::Record::export({ - record_type => 'bibs', - record_ids => [ $biblionumber_1 ], - format => 'iso2709', - marc_modification_template_id => $template_id, - output_filepath => $generated_mrc_file, - }); - - my $records = MARC::File::USMARC->in( $generated_mrc_file ); + Koha::Exporter::Record::export( + { + record_type => 'bibs', + record_ids => [$biblionumber_1], + format => 'iso2709', + marc_modification_template_id => $template_id, + output_filepath => $generated_mrc_file, + } + ); + + my $records = MARC::File::USMARC->in($generated_mrc_file); my @records; while ( my $record = $records->next ) { push @records, $record; } - is( scalar( @records ), 1, 'Export ISO2709: 1 record should have been exported' ); + is( scalar(@records), 1, 'Export ISO2709: 1 record should have been exported' ); my $record = $records[0]; - is( $record->subfield('999', '9'), 'Foobar', 'Export ISO2709: marc modification template should have added 999$9' ); + is( + $record->subfield( '998', '9' ), 'Foobar', + 'Export ISO2709: marc modification template should have added 998$9' + ); }; $schema->storage->txn_rollback; -- 2.39.5