Bugzilla – Attachment 53223 Details for
Bug 10407
Allow MARCXML records to be imported with Tools/Stage MARC records for import
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 10407: Add two subtests to t/ImportBatch.t
Bug-10407-Add-two-subtests-to-tImportBatcht.patch (text/plain), 3.74 KB, created by
Marcel de Rooy
on 2016-07-08 12:09:09 UTC
(
hide
)
Description:
Bug 10407: Add two subtests to t/ImportBatch.t
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2016-07-08 12:09:09 UTC
Size:
3.74 KB
patch
obsolete
>From fa409cbf5cd2f0744f92f2c13372d64092761110 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Fri, 8 Jul 2016 13:17:36 +0200 >Subject: [PATCH] Bug 10407: Add two subtests to t/ImportBatch.t >Content-Type: text/plain; charset=utf-8 > >Creates a few simple tests for the two new subroutines in ImportBatch.pm. > >Test plan: >Run t/ImportBatch.t. > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > t/ImportBatch.t | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- > 1 file changed, 76 insertions(+), 4 deletions(-) > >diff --git a/t/ImportBatch.t b/t/ImportBatch.t >index 70a40af..9db2c27 100644 >--- a/t/ImportBatch.t >+++ b/t/ImportBatch.t >@@ -17,13 +17,85 @@ > > use Modern::Perl; > >-use Test::More tests => 1; >+use File::Temp qw|tempfile|; >+use MARC::Field; >+use MARC::File::XML; >+use MARC::Record; >+use Test::More tests => 3; > use t::lib::Mocks; > > BEGIN { >- # Mock the DB connexion and C4::Context >- my $context = t::lib::Mocks::mock_dbh; > use_ok('C4::ImportBatch'); > } > >-1; >+t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); >+ >+subtest 'RecordsFromISO2709File' => sub { >+ plan tests => 4; >+ >+ my ( $errors, $recs ); >+ my $file = create_file({ whitespace => 1, format => 'marc' }); >+ ( $errors, $recs ) = C4::ImportBatch::RecordsFromISO2709File( $file, 'biblio', 'UTF-8' ); >+ is( @$recs, 0, 'No records from empty marc file' ); >+ >+ $file = create_file({ garbage => 1, format => 'marc' }); >+ ( $errors, $recs ) = C4::ImportBatch::RecordsFromISO2709File( $file, 'biblio', 'UTF-8' ); >+ is( @$recs, 1, 'Garbage returns one record' ); >+ my @fields = @$recs? $recs->[0]->fields: (); >+ is( @fields, 0, 'That is an empty record' ); >+ >+ $file = create_file({ two => 1, format => 'marc' }); >+ ( $errors, $recs ) = C4::ImportBatch::RecordsFromISO2709File( $file, 'biblio', 'UTF-8' ); >+ is( @$recs, 2, 'File contains 2 records' ); >+ >+}; >+ >+subtest 'RecordsFromMARCXMLFile' => sub { >+ plan tests => 3; >+ >+ my ( $errors, $recs ); >+ my $file = create_file({ whitespace => 1, format => 'marcxml' }); >+ ( $errors, $recs ) = C4::ImportBatch::RecordsFromMARCXMLFile( $file, 'UTF-8' ); >+ is( @$recs, 0, 'No records from empty marcxml file' ); >+ >+ $file = create_file({ garbage => 1, format => 'marcxml' }); >+ ( $errors, $recs ) = C4::ImportBatch::RecordsFromMARCXMLFile( $file, 'UTF-8' ); >+ is( @$recs, 0, 'Garbage returns no records' ); >+ >+ $file = create_file({ two => 1, format => 'marcxml' }); >+ ( $errors, $recs ) = C4::ImportBatch::RecordsFromMARCXMLFile( $file, 'UTF-8' ); >+ is( @$recs, 2, 'File has two records' ); >+ >+}; >+ >+sub create_file { >+ my ( $params ) = @_; >+ my ( $fh, $name ) = tempfile( SUFFIX => '.' . $params->{format} ); >+ if( $params->{garbage} ) { >+ print $fh "Just some garbage\n\nAnd another line"; >+ } elsif( $params->{whitespace} ) { >+ print $fh " "; >+ } elsif ( $params->{two} ) { >+ my $rec1 = MARC::Record->new; >+ my $rec2 = MARC::Record->new; >+ my $fld1 = MARC::Field->new('245','','','a','Title1'); >+ my $fld2 = MARC::Field->new('245','','','a','Title2'); >+ $rec1->append_fields( $fld1 ); >+ $rec2->append_fields( $fld2 ); >+ if( $params->{format} eq 'marcxml' ) { >+ my $str = $rec1->as_xml; >+ # remove ending collection tag >+ $str =~ s/<\/collection>//; >+ print $fh $str; >+ $str = $rec2->as_xml_record; # no collection tag >+ # remove <?xml> line from 2nd record, add collection >+ $str =~ s/<\?xml.*\n//; >+ $str .= '</collection>'; >+ print $fh $str; >+ } else { >+ print $fh $rec1->as_formatted, "\x1D", $rec2->as_formatted; >+ } >+ } >+ close $fh; >+ return $name; >+} >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 10407
:
38101
|
38127
|
38129
|
38133
|
42831
|
53164
|
53165
|
53218
|
53219
|
53220
|
53221
|
53223
|
53306
|
53765
|
53766
|
53767
|
53768
|
53769
|
53937
|
53938
|
53939
|
53940
|
53941