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

(-)a/t/db_dependent/Exporter/Record.t (-34 / +54 lines)
Lines 36-41 use Koha::Biblioitem; Link Here
36
use Koha::Exporter::Record;
36
use Koha::Exporter::Record;
37
use Koha::Biblio::Metadatas;
37
use Koha::Biblio::Metadatas;
38
38
39
use t::lib::TestBuilder;
40
41
my $builder = t::lib::TestBuilder->new;
42
39
my $schema  = Koha::Database->new->schema;
43
my $schema  = Koha::Database->new->schema;
40
$schema->storage->txn_begin;
44
$schema->storage->txn_begin;
41
45
Lines 43-68 my $dbh = C4::Context->dbh; Link Here
43
47
44
my $biblio_1_title = 'Silence in the library';
48
my $biblio_1_title = 'Silence in the library';
45
my $biblio_2_title = 'The art of computer programming ກ ຂ ຄ ງ ຈ ຊ ຍ é';
49
my $biblio_2_title = 'The art of computer programming ກ ຂ ຄ ງ ຈ ຊ ຍ é';
46
my $biblio_1 = MARC::Record->new();
50
my $biblio_1 = $builder->build_sample_biblio(
47
$biblio_1->leader('00266nam a22001097a 4500');
51
    {
48
$biblio_1->append_fields(
52
        title => $biblio_1_title,
49
    MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'),
53
        author => 'Moffat, Steven',
50
    MARC::Field->new('245', ' ', ' ', a => $biblio_1_title),
54
    }
51
);
55
);
52
my ($biblionumber_1, $biblioitemnumber_1) = AddBiblio($biblio_1, '');
56
my $biblionumber_1 = $biblio_1->biblionumber;
53
my $biblio_2 = MARC::Record->new();
57
my $biblio_2 = $builder->build_sample_biblio(
54
$biblio_2->leader('00266nam a22001097a 4500');
58
    {
55
$biblio_2->append_fields(
59
        title => $biblio_2_title,
56
    MARC::Field->new('100', ' ', ' ', a => 'Knuth, Donald Ervin'),
60
        author => 'Knuth, Donald Ervin',
57
    MARC::Field->new('245', ' ', ' ', a => $biblio_2_title),
61
    }
58
);
62
);
59
my ($biblionumber_2, $biblioitemnumber_2) = AddBiblio($biblio_2, '');
63
my $biblionumber_2 = $biblio_2->biblionumber;
64
65
my $marcflavour = C4::Context->preference('marcflavour');
66
my ($title_field_tag, $item_field_tag, $barcode_subfield_code, $homebranch_subfield_code);
67
if ($marcflavour eq 'UNIMARC') {
68
    $title_field_tag = '200';
69
    $item_field_tag = '995';
70
    $barcode_subfield_code = 'f';
71
    $homebranch_subfield_code = 'b';
72
} else {
73
    $title_field_tag = '245';
74
    $item_field_tag = '952';
75
    $barcode_subfield_code = 'p';
76
    $homebranch_subfield_code = 'a';
77
}
60
78
61
my $bad_biblio = Koha::Biblio->new()->store();
79
my $bad_biblio = Koha::Biblio->new()->store();
62
Koha::Biblio::Metadata->new( { biblionumber => $bad_biblio->id, format => 'marcxml', metadata => 'something wrong', schema => C4::Context->preference('marcflavour') } )->store();
80
Koha::Biblio::Metadata->new( { biblionumber => $bad_biblio->id, format => 'marcxml', metadata => 'something wrong', schema => $marcflavour } )->store();
63
my $bad_biblionumber = $bad_biblio->id;
81
my $bad_biblionumber = $bad_biblio->id;
64
82
65
my $builder = t::lib::TestBuilder->new;
66
my $item_1_1 = $builder->build_sample_item(
83
my $item_1_1 = $builder->build_sample_item(
67
    {
84
    {
68
        biblionumber => $biblionumber_1,
85
        biblionumber => $biblionumber_1,
Lines 87-93 my $bad_item = $builder->build({ # Cannot call build_sample_item, we want incons Link Here
87
104
88
subtest 'export csv' => sub {
105
subtest 'export csv' => sub {
89
    plan tests => 3;
106
    plan tests => 3;
90
    my $csv_content = q{Title=245$a|Barcode=952$p};
107
    my $csv_content = "Title=$title_field_tag\$a|Barcode=$item_field_tag\$$barcode_subfield_code";
91
    $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');
108
    $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');
92
    my $csv_profile_id = $dbh->last_insert_id( undef, undef, 'export_format', undef );
109
    my $csv_profile_id = $dbh->last_insert_id( undef, undef, 'export_format', undef );
93
    my $generated_csv_file = '/tmp/test_export_1.csv';
110
    my $generated_csv_file = '/tmp/test_export_1.csv';
Lines 160-166 subtest 'export xml' => sub { Link Here
160
    }
177
    }
161
    is( scalar( @records ), 2, 'Export XML: 2 records should have been exported' );
178
    is( scalar( @records ), 2, 'Export XML: 2 records should have been exported' );
162
    my $second_record = $records[1];
179
    my $second_record = $records[1];
163
    my $title = $second_record->subfield(245, 'a');
180
    my $title = $second_record->subfield($title_field_tag, 'a');
164
    $title = Encode::encode('UTF-8', $title);
181
    $title = Encode::encode('UTF-8', $title);
165
    is( $title, $biblio_2_title, 'Export XML: The title is correctly encoded' );
182
    is( $title, $biblio_2_title, 'Export XML: The title is correctly encoded' );
166
};
183
};
Lines 187-193 subtest 'export iso2709' => sub { Link Here
187
    }
204
    }
188
    is( scalar( @records ), 2, 'Export ISO2709: 2 records should have been exported' );
205
    is( scalar( @records ), 2, 'Export ISO2709: 2 records should have been exported' );
189
    my $second_record = $records[1];
206
    my $second_record = $records[1];
190
    my $title = $second_record->subfield(245, 'a');
207
    my $title = $second_record->subfield($title_field_tag, 'a');
191
    $title = Encode::encode('UTF-8', $title);
208
    $title = Encode::encode('UTF-8', $title);
192
    is( $title, $biblio_2_title, 'Export ISO2709: The title is correctly encoded' );
209
    is( $title, $biblio_2_title, 'Export ISO2709: The title is correctly encoded' );
193
};
210
};
Lines 207-219 subtest 'export without record_type' => sub { Link Here
207
subtest '_get_biblio_for_export' => sub {
224
subtest '_get_biblio_for_export' => sub {
208
    plan tests => 4;
225
    plan tests => 4;
209
226
210
    my $biblio = MARC::Record->new();
227
    my $biblio = $builder->build_sample_biblio(
211
    $biblio->leader('00266nam a22001097a 4500');
228
        {
212
    $biblio->append_fields(
229
            title => 'The 13 Clocks',
213
        MARC::Field->new( '100', ' ', ' ', a => 'Thurber, James' ),
230
            author => 'Thurber, James',
214
        MARC::Field->new( '245', ' ', ' ', a => "The 13 Clocks" ),
231
        }
215
    );
232
    );
216
    my ( $biblionumber, $biblioitemnumber ) = AddBiblio( $biblio, '' );
233
    my $biblionumber = $biblio->biblionumber;
217
    my $branch_a = $builder->build({source => 'Branch',});
234
    my $branch_a = $builder->build({source => 'Branch',});
218
    my $branch_b = $builder->build({source => 'Branch',});
235
    my $branch_b = $builder->build({source => 'Branch',});
219
    my $item_branch_a = $builder->build_sample_item(
236
    my $item_branch_a = $builder->build_sample_item(
Lines 236-242 subtest '_get_biblio_for_export' => sub { Link Here
236
            only_export_items_for_branches => undef
253
            only_export_items_for_branches => undef
237
        }
254
        }
238
    );
255
    );
239
    my @items = $record->field('952');
256
    my @items = $record->field($item_field_tag);
240
    is( scalar @items, 2, "We should retrieve all items if we don't pass specific branches and request items" );
257
    is( scalar @items, 2, "We should retrieve all items if we don't pass specific branches and request items" );
241
258
242
    $record = Koha::Exporter::Record::_get_biblio_for_export(
259
    $record = Koha::Exporter::Record::_get_biblio_for_export(
Lines 246-255 subtest '_get_biblio_for_export' => sub { Link Here
246
            only_export_items_for_branches => [ $branch_b->{branchcode} ]
263
            only_export_items_for_branches => [ $branch_b->{branchcode} ]
247
        }
264
        }
248
    );
265
    );
249
    @items = $record->field('952');
266
    @items = $record->field($item_field_tag);
250
    is( scalar @items, 1, "We should retrieve only item for branch_b item if we request items and pass branch" );
267
    is( scalar @items, 1, "We should retrieve only item for branch_b item if we request items and pass branch" );
251
    is(
268
    is(
252
        $items[0]->subfield('a'),
269
        $items[0]->subfield($homebranch_subfield_code),
253
        $branch_b->{branchcode},
270
        $branch_b->{branchcode},
254
        "And the homebranch for that item should be branch_b branchcode"
271
        "And the homebranch for that item should be branch_b branchcode"
255
    );
272
    );
Lines 261-267 subtest '_get_biblio_for_export' => sub { Link Here
261
            only_export_items_for_branches => [ $branch_b->{branchcode} ]
278
            only_export_items_for_branches => [ $branch_b->{branchcode} ]
262
        }
279
        }
263
    );
280
    );
264
    @items = $record->field('952');
281
    @items = $record->field($item_field_tag);
265
    is( scalar @items, 0, "We should not have any items if we don't request items and pass a branch");
282
    is( scalar @items, 0, "We should not have any items if we don't request items and pass a branch");
266
283
267
};
284
};
Lines 269-285 subtest '_get_biblio_for_export' => sub { Link Here
269
subtest '_get_record_for_export MARC field conditions' => sub {
286
subtest '_get_record_for_export MARC field conditions' => sub {
270
    plan tests => 11;
287
    plan tests => 11;
271
288
272
    my $biblio = MARC::Record->new();
289
    my $biblio = $builder->build_sample_biblio(
273
    $biblio->leader('00266nam a22001097a 4500');
290
        {
274
    $biblio->append_fields(
291
            title => 'The 13 Clocks',
275
        MARC::Field->new( '100', ' ', ' ', a => 'Thurber, James' ),
292
            author => 'Thurber, James',
276
        MARC::Field->new( '245', ' ', ' ', a => 'The 13 Clocks' ),
293
        }
294
    );
295
    my $record = $biblio->metadata->record;
296
    $record->append_fields(
277
        MARC::Field->new( '080', ' ', ' ', a => '12345' ),
297
        MARC::Field->new( '080', ' ', ' ', a => '12345' ),
278
        MARC::Field->new( '035', ' ', ' ', a => '(TEST)123' ),
298
        MARC::Field->new( '035', ' ', ' ', a => '(TEST)123' ),
279
        MARC::Field->new( '035', ' ', ' ', a => '(TEST)1234' ),
299
        MARC::Field->new( '035', ' ', ' ', a => '(TEST)1234' ),
280
    );
300
    );
281
    my ( $biblionumber ) = AddBiblio( $biblio, '' );
301
    $biblio->metadata->metadata($record->as_xml)->store;
282
    my $record;
302
    my $biblionumber = $biblio->biblionumber;
283
303
284
    $record = Koha::Exporter::Record::_get_record_for_export(
304
    $record = Koha::Exporter::Record::_get_record_for_export(
285
        {
305
        {
(-)a/t/lib/TestBuilder.pm (-2 / +1 lines)
Lines 177-183 sub build_sample_biblio { Link Here
177
        MARC::Field->new( $tag, ' ', ' ', $subfield => $author ),
177
        MARC::Field->new( $tag, ' ', ' ', $subfield => $author ),
178
    );
178
    );
179
179
180
    ( $tag, $subfield ) = $marcflavour eq 'UNIMARC' ? ( 995, 'r' ) : ( 942, 'c' );
180
    ( $tag, $subfield ) = $marcflavour eq 'UNIMARC' ? ( '099', 't' ) : ( 942, 'c' );
181
    $record->append_fields(
181
    $record->append_fields(
182
        MARC::Field->new( $tag, ' ', ' ', $subfield => $itemtype )
182
        MARC::Field->new( $tag, ' ', ' ', $subfield => $itemtype )
183
    );
183
    );
184
- 

Return to bug 25508