View | Details | Raw Unified | Return to bug 17088
Collapse All | Expand All

(-)a/t/db_dependent/Exporter/Record.t (-29 / +47 lines)
Lines 18-23 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 4;
20
use Test::More tests => 4;
21
use Test::Warn;
21
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
22
23
23
use MARC::Record;
24
use MARC::Record;
Lines 54-59 $biblio_2->append_fields( Link Here
54
);
55
);
55
my ($biblionumber_2, $biblioitemnumber_2) = AddBiblio($biblio_2, '');
56
my ($biblionumber_2, $biblioitemnumber_2) = AddBiblio($biblio_2, '');
56
57
58
my ($bad_biblionumber, $bad_biblioitemnumber) = AddBiblio($biblio_1, '');
59
Koha::Biblioitems->find( $bad_biblionumber )->marcxml("something wrong")->store;
60
57
my $builder = t::lib::TestBuilder->new;
61
my $builder = t::lib::TestBuilder->new;
58
my $item_1_1 = $builder->build({
62
my $item_1_1 = $builder->build({
59
    source => 'Item',
63
    source => 'Item',
Lines 76-99 my $item_2_1 = $builder->build({ Link Here
76
        more_subfields_xml => '',
80
        more_subfields_xml => '',
77
    }
81
    }
78
});
82
});
83
my $bad_item = $builder->build({
84
    source => 'Item',
85
    value => {
86
        biblionumber => $bad_biblionumber,
87
        more_subfields_xml => '',
88
    }
89
});
79
90
80
subtest 'export csv' => sub {
91
subtest 'export csv' => sub {
81
    plan tests => 2;
92
    plan tests => 3;
82
    my $csv_content = q{Title=245$a|Barcode=952$p};
93
    my $csv_content = q{Title=245$a|Barcode=952$p};
83
    $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');
94
    $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');
84
    my $csv_profile_id = $dbh->last_insert_id( undef, undef, 'export_format', undef );
95
    my $csv_profile_id = $dbh->last_insert_id( undef, undef, 'export_format', undef );
85
    my $generated_csv_file = '/tmp/test_export_1.csv';
96
    my $generated_csv_file = '/tmp/test_export_1.csv';
86
97
87
    # Get all item infos
98
    # Get all item infos
88
    Koha::Exporter::Record::export(
99
    warning_like {
89
        {
100
        Koha::Exporter::Record::export(
90
            record_type => 'bibs',
101
            {   record_type     => 'bibs',
91
            record_ids => [ $biblionumber_1, $biblionumber_2 ],
102
                record_ids      => [ $biblionumber_1, $bad_biblionumber, $biblionumber_2 ],
92
            format => 'csv',
103
                format          => 'csv',
93
            csv_profile_id => $csv_profile_id,
104
                csv_profile_id  => $csv_profile_id,
94
            output_filepath => $generated_csv_file,
105
                output_filepath => $generated_csv_file,
95
        }
106
            }
96
    );
107
        );
108
    }
109
    qr|.*Start tag expected.*|, "Export csv with wrong marcxml should raise a warning";
97
    my $expected_csv = <<EOF;
110
    my $expected_csv = <<EOF;
98
Title|Barcode
111
Title|Barcode
99
"$biblio_1_title"|$item_1_1->{barcode},$item_1_2->{barcode}
112
"$biblio_1_title"|$item_1_1->{barcode},$item_1_2->{barcode}
Lines 124-139 EOF Link Here
124
};
137
};
125
138
126
subtest 'export xml' => sub {
139
subtest 'export xml' => sub {
127
    plan tests => 2;
140
    plan tests => 3;
128
    my $generated_xml_file = '/tmp/test_export.xml';
141
    my $generated_xml_file = '/tmp/test_export.xml';
129
    Koha::Exporter::Record::export(
142
    warning_like {
130
        {
143
        Koha::Exporter::Record::export(
131
            record_type => 'bibs',
144
            {   record_type     => 'bibs',
132
            record_ids => [ $biblionumber_1, $biblionumber_2 ],
145
                record_ids      => [ $biblionumber_1, $bad_biblionumber, $biblionumber_2 ],
133
            format => 'xml',
146
                format          => 'xml',
134
            output_filepath => $generated_xml_file,
147
                output_filepath => $generated_xml_file,
135
        }
148
            }
136
    );
149
        );
150
    }
151
    qr|.*Start tag expected.*|, "Export xml with wrong marcxml should raise a warning";
152
137
    my $generated_xml_content = read_file( $generated_xml_file );
153
    my $generated_xml_content = read_file( $generated_xml_file );
138
    $MARC::File::XML::_load_args{BinaryEncoding} = 'utf-8';
154
    $MARC::File::XML::_load_args{BinaryEncoding} = 'utf-8';
139
    open my $fh, '<', $generated_xml_file;
155
    open my $fh, '<', $generated_xml_file;
Lines 153-169 subtest 'export xml' => sub { Link Here
153
};
169
};
154
170
155
subtest 'export iso2709' => sub {
171
subtest 'export iso2709' => sub {
156
    plan tests => 2;
172
    plan tests => 3;
157
    my $generated_mrc_file = '/tmp/test_export.mrc';
173
    my $generated_mrc_file = '/tmp/test_export.mrc';
158
    # Get all item infos
174
    # Get all item infos
159
    Koha::Exporter::Record::export(
175
    warning_like {
160
        {
176
        Koha::Exporter::Record::export(
161
            record_type => 'bibs',
177
            {   record_type     => 'bibs',
162
            record_ids => [ $biblionumber_1, $biblionumber_2 ],
178
                record_ids      => [ $biblionumber_1, $bad_biblionumber, $biblionumber_2 ],
163
            format => 'iso2709',
179
                format          => 'iso2709',
164
            output_filepath => $generated_mrc_file,
180
                output_filepath => $generated_mrc_file,
165
        }
181
            }
166
    );
182
        );
183
    }
184
    qr|.*Start tag expected.*|, "Export iso2709 with wrong marcxml should raise a warning";
185
167
    my $records = MARC::File::USMARC->in( $generated_mrc_file );
186
    my $records = MARC::File::USMARC->in( $generated_mrc_file );
168
    my @records;
187
    my @records;
169
    while ( my $record = $records->next ) {
188
    while ( my $record = $records->next ) {
170
- 

Return to bug 17088