Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl; |
|
|
2 |
|
3 |
use Modern::Perl; |
4 |
use Test::More tests => 4; |
5 |
use Test::MockModule; |
6 |
use MARC::Record; |
7 |
use MARC::Field; |
8 |
use Text::CSV::Encoded; |
9 |
|
10 |
use C4::Biblio qw( AddBiblio ); |
11 |
use C4::Context; |
12 |
use C4::Record; |
13 |
|
14 |
my $dbh = C4::Context->dbh; |
15 |
$dbh->{AutoCommit} = 0; |
16 |
$dbh->{RaiseError} = 1; |
17 |
|
18 |
my $module_biblio = Test::MockModule->new('C4::Biblio'); |
19 |
|
20 |
my $record = new_record(); |
21 |
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, q|| ); |
22 |
$module_biblio->mock( 'GetMarcBiblio', sub{ $record } ); |
23 |
|
24 |
my $csv_content = q(Title=245$a|Author=245$c|Subject=650$a); |
25 |
my $csv_profile_id_1 = insert_csv_profile({ csv_content => $csv_content }); |
26 |
my $csv = Text::CSV::Encoded->new(); |
27 |
|
28 |
my $csv_output = C4::Record::marcrecord2csv( $biblionumber, $csv_profile_id_1, 1, $csv ); |
29 |
|
30 |
is( $csv_output, q[Title|Author|Subject |
31 |
"The art of computer programming,The art of another title"|"Donald E. Knuth.,Donald E. Knuth. II"|"Computer programming.,Computer algorithms." |
32 |
], q|normal way: display headers and content| ); |
33 |
|
34 |
$csv_output = C4::Record::marcrecord2csv( $biblionumber, $csv_profile_id_1, 0, $csv ); |
35 |
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." |
36 |
], q|normal way: don't display headers| ); |
37 |
|
38 |
$csv_content = q(245|650); |
39 |
my $csv_profile_id_2 = insert_csv_profile({ csv_content => $csv_content }); |
40 |
|
41 |
$csv_output = C4::Record::marcrecord2csv( $biblionumber, $csv_profile_id_2, 1, $csv ); |
42 |
is( $csv_output, q["TITLE STATEMENT"|"SUBJECT ADDED ENTRY--TOPICAL TERM" |
43 |
"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" |
44 |
], q|normal way: headers retrieved from the DB| ); |
45 |
|
46 |
$csv_output = C4::Record::marcrecord2csv( $biblionumber, $csv_profile_id_2, 0, $csv ); |
47 |
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" |
48 |
], q|normal way: headers are not display if not needed| ); |
49 |
|
50 |
sub insert_csv_profile { |
51 |
my ( $params ) = @_; |
52 |
my $csv_content = $params->{csv_content}; |
53 |
$dbh->do(q| |
54 |
INSERT INTO export_format(profile, description, content, csv_separator, field_separator, subfield_separator, encoding, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?) |
55 |
|, {}, ("TEST_PROFILE4", "my desc", $csv_content, '|', ';', ',', 'utf8', 'marc') |
56 |
); |
57 |
return $dbh->last_insert_id( undef, undef, 'export_format', undef ); |
58 |
} |
59 |
|
60 |
sub new_record { |
61 |
my $record = MARC::Record->new; |
62 |
$record->leader('03174nam a2200445 a 4500'); |
63 |
my @fields = ( |
64 |
MARC::Field->new( |
65 |
'008', "140211b xxu||||| |||| 00| 0 eng d" |
66 |
), |
67 |
MARC::Field->new( |
68 |
100, '1', ' ', |
69 |
a => 'Knuth, Donald Ervin', |
70 |
d => '1938', |
71 |
), |
72 |
MARC::Field->new( |
73 |
245, '1', '4', |
74 |
a => 'The art of computer programming', |
75 |
c => 'Donald E. Knuth.', |
76 |
9 => '0', |
77 |
), |
78 |
MARC::Field->new( |
79 |
245, '1', '4', |
80 |
a => 'The art of another title', |
81 |
c => 'Donald E. Knuth. II', |
82 |
9 => '1', |
83 |
), |
84 |
MARC::Field->new( |
85 |
650, ' ', '1', |
86 |
a => 'Computer programming.', |
87 |
9 => '462', |
88 |
), |
89 |
MARC::Field->new( |
90 |
650, ' ', '0', |
91 |
a => 'Computer algorithms.', |
92 |
9 => '499', |
93 |
), |
94 |
MARC::Field->new( |
95 |
952, ' ', ' ', |
96 |
p => '3010023917', |
97 |
y => 'BK', |
98 |
c => 'GEN', |
99 |
d => '2001-06-25', |
100 |
), |
101 |
); |
102 |
$record->append_fields(@fields); |
103 |
return $record; |
104 |
} |