Bugzilla – Attachment 33170 Details for
Bug 12404
CSV profiles improvements (concatenations, substrings, conditions...)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12404: Add UT for marcrecord2csv
Bug-12404-Add-UT-for-marcrecord2csv.patch (text/plain), 4.42 KB, created by
Jonathan Druart
on 2014-11-03 17:27:45 UTC
(
hide
)
Description:
Bug 12404: Add UT for marcrecord2csv
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2014-11-03 17:27:45 UTC
Size:
4.42 KB
patch
obsolete
>From 8a075367106de160d2e3c5c53ad4f9b79879845a Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Tue, 11 Feb 2014 13:21:59 +0100 >Subject: [PATCH] Bug 12404: Add UT for marcrecord2csv > >Verify that these unit tests pass before any changes and after applying >all patches. >--- > t/db_dependent/Record/marcrecord2csv.t | 104 +++++++++++++++++++++++++++++++++ > 1 file changed, 104 insertions(+) > create mode 100644 t/db_dependent/Record/marcrecord2csv.t > >diff --git a/t/db_dependent/Record/marcrecord2csv.t b/t/db_dependent/Record/marcrecord2csv.t >new file mode 100644 >index 0000000..20ee8e6 >--- /dev/null >+++ b/t/db_dependent/Record/marcrecord2csv.t >@@ -0,0 +1,104 @@ >+#!/usr/bin/perl; >+ >+use Modern::Perl; >+use Test::More tests => 4; >+use Test::MockModule; >+use MARC::Record; >+use MARC::Field; >+use Text::CSV::Encoded; >+ >+use C4::Biblio qw( AddBiblio ); >+use C4::Context; >+use C4::Record; >+ >+my $dbh = C4::Context->dbh; >+$dbh->{AutoCommit} = 0; >+$dbh->{RaiseError} = 1; >+ >+my $module_biblio = Test::MockModule->new('C4::Biblio'); >+ >+my $record = new_record(); >+my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, q|| ); >+$module_biblio->mock( 'GetMarcBiblio', sub{ $record } ); >+ >+my $csv_content = q(Title=245$a|Author=245$c|Subject=650$a); >+my $csv_profile_id_1 = insert_csv_profile({ csv_content => $csv_content }); >+my $csv = Text::CSV::Encoded->new(); >+ >+my $csv_output = C4::Record::marcrecord2csv( $biblionumber, $csv_profile_id_1, 1, $csv ); >+ >+is( $csv_output, q[Title|Author|Subject >+"The art of computer programming,The art of another title"|"Donald E. Knuth.,Donald E. Knuth. II"|"Computer programming.,Computer algorithms." >+], q|normal way: display headers and content| ); >+ >+$csv_output = C4::Record::marcrecord2csv( $biblionumber, $csv_profile_id_1, 0, $csv ); >+is( $csv_output, q["The art of computer programming,The art of another title"|"Donald E. Knuth.,Donald E. Knuth. II"|"Computer programming.,Computer algorithms." >+], q|normal way: don't display headers| ); >+ >+$csv_content = q(245|650); >+my $csv_profile_id_2 = insert_csv_profile({ csv_content => $csv_content }); >+ >+$csv_output = C4::Record::marcrecord2csv( $biblionumber, $csv_profile_id_2, 1, $csv ); >+is( $csv_output, q["TITLE STATEMENT"|"SUBJECT ADDED ENTRY--TOPICAL TERM" >+"The art of computer programming,Donald E. Knuth.,0;The art of another title,Donald E. Knuth. II,1"|"Computer programming.,462;Computer algorithms.,499" >+], q|normal way: headers retrieved from the DB| ); >+ >+$csv_output = C4::Record::marcrecord2csv( $biblionumber, $csv_profile_id_2, 0, $csv ); >+is( $csv_output, q["The art of computer programming,Donald E. Knuth.,0;The art of another title,Donald E. Knuth. II,1"|"Computer programming.,462;Computer algorithms.,499" >+], q|normal way: headers are not display if not needed| ); >+ >+sub insert_csv_profile { >+ my ( $params ) = @_; >+ my $csv_content = $params->{csv_content}; >+ $dbh->do(q| >+ INSERT INTO export_format(profile, description, content, csv_separator, field_separator, subfield_separator, encoding, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?) >+ |, {}, ("TEST_PROFILE4", "my desc", $csv_content, '|', ';', ',', 'utf8', 'marc') >+ ); >+ return $dbh->last_insert_id( undef, undef, 'export_format', undef ); >+} >+ >+sub new_record { >+ my $record = MARC::Record->new; >+ $record->leader('03174nam a2200445 a 4500'); >+ my @fields = ( >+ MARC::Field->new( >+ '008', "140211b xxu||||| |||| 00| 0 eng d" >+ ), >+ MARC::Field->new( >+ 100, '1', ' ', >+ a => 'Knuth, Donald Ervin', >+ d => '1938', >+ ), >+ MARC::Field->new( >+ 245, '1', '4', >+ a => 'The art of computer programming', >+ c => 'Donald E. Knuth.', >+ 9 => '0', >+ ), >+ MARC::Field->new( >+ 245, '1', '4', >+ a => 'The art of another title', >+ c => 'Donald E. Knuth. II', >+ 9 => '1', >+ ), >+ MARC::Field->new( >+ 650, ' ', '1', >+ a => 'Computer programming.', >+ 9 => '462', >+ ), >+ MARC::Field->new( >+ 650, ' ', '0', >+ a => 'Computer algorithms.', >+ 9 => '499', >+ ), >+ MARC::Field->new( >+ 952, ' ', ' ', >+ p => '3010023917', >+ y => 'BK', >+ c => 'GEN', >+ d => '2001-06-25', >+ ), >+ ); >+ $record->append_fields(@fields); >+ return $record; >+} >-- >2.1.0
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 12404
:
28767
|
28768
|
28769
|
28770
|
28771
|
33170
|
33171
|
33172
|
33173
|
33174
|
33263
|
33477
|
34288
|
34289
|
34290
|
34291
|
34292
|
34293
|
34294
|
34300
|
34301
|
34302
|
34303
|
34405
|
34406
|
34407
|
34408
|
34409
|
34410
|
34411
|
35048
|
35049
|
35050
|
35051
|
35052
|
35053
|
35054