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

(-)a/t/db_dependent/Exporter/Record.t (-37 / +48 lines)
Lines 438-465 subtest '_get_record_for_export MARC field conditions' => sub { Link Here
438
438
439
subtest 'export csv with marc modification template' => sub {
439
subtest 'export csv with marc modification template' => sub {
440
    plan tests => 1;
440
    plan tests => 1;
441
    my $csv_content = qq{Title=$title_field\$$title_subfield|Test=999\$9};
441
    my $csv_content = "Title=$title_field_tag\$a|Test=998\$9";
442
    $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');
442
    $dbh->do(
443
        q|INSERT INTO export_format(profile, description, content, csv_separator, field_separator, subfield_separator, encoding, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?)|,
444
        {}, "TEST_PROFILE_Records.t", "my useless desc", $csv_content, '|', ';', ',', 'utf8', 'marc'
445
    );
443
    my $csv_profile_id = $dbh->last_insert_id( undef, undef, 'export_format', undef );
446
    my $csv_profile_id = $dbh->last_insert_id( undef, undef, 'export_format', undef );
444
447
445
    my $template_id = C4::MarcModificationTemplates::AddModificationTemplate('test exporter');
448
    my $template_id = C4::MarcModificationTemplates::AddModificationTemplate('test exporter');
446
    C4::MarcModificationTemplates::AddModificationTemplateAction($template_id, 'add_field', 0, '999', '9', 'Foobar');
449
    C4::MarcModificationTemplates::AddModificationTemplateAction( $template_id, 'add_field', 0, '998', '9', 'Foobar' );
447
450
448
    my $generated_csv_file = '/tmp/test_export_1.csv';
451
    my $generated_csv_file = '/tmp/test_export_1.csv';
449
    Koha::Exporter::Record::export({
452
    Koha::Exporter::Record::export(
450
        record_type     => 'bibs',
453
        {
451
        record_ids      => [ $biblionumber_1 ],
454
            record_type                   => 'bibs',
452
        format          => 'csv',
455
            record_ids                    => [$biblionumber_1],
453
        csv_profile_id  => $csv_profile_id,
456
            format                        => 'csv',
454
        marc_modification_template_id => $template_id,
457
            csv_profile_id                => $csv_profile_id,
455
        output_filepath => $generated_csv_file,
458
            marc_modification_template_id => $template_id,
456
    });
459
            output_filepath               => $generated_csv_file,
460
        }
461
    );
457
462
458
    my $expected_csv = <<EOF;
463
    my $expected_csv = <<EOF;
459
Title|Test
464
Title|Test
460
"$biblio_1_title"|Foobar
465
"$biblio_1_title"|Foobar
461
EOF
466
EOF
462
    my $generated_csv_content = read_file( $generated_csv_file );
467
    my $generated_csv_content = read_file($generated_csv_file);
463
    is( $generated_csv_content, $expected_csv, "Export CSV: Modification template should have been applied" );
468
    is( $generated_csv_content, $expected_csv, "Export CSV: Modification template should have been applied" );
464
};
469
};
465
470
Lines 467-484 subtest 'export xml with marc modification template' => sub { Link Here
467
    plan tests => 2;
472
    plan tests => 2;
468
473
469
    my $template_id = C4::MarcModificationTemplates::AddModificationTemplate('test exporter');
474
    my $template_id = C4::MarcModificationTemplates::AddModificationTemplate('test exporter');
470
    C4::MarcModificationTemplates::AddModificationTemplateAction($template_id, 'add_field', 0, '999', '9', 'Foobar');
475
    C4::MarcModificationTemplates::AddModificationTemplateAction( $template_id, 'add_field', 0, '998', '9', 'Foobar' );
471
476
472
    my $generated_xml_file = '/tmp/test_export.xml';
477
    my $generated_xml_file = '/tmp/test_export.xml';
473
    Koha::Exporter::Record::export({
478
    Koha::Exporter::Record::export(
474
        record_type     => 'bibs',
479
        {
475
        record_ids      => [ $biblionumber_1 ],
480
            record_type                   => 'bibs',
476
        format          => 'xml',
481
            record_ids                    => [$biblionumber_1],
477
        marc_modification_template_id => $template_id,
482
            format                        => 'xml',
478
        output_filepath => $generated_xml_file,
483
            marc_modification_template_id => $template_id,
479
    });
484
            output_filepath               => $generated_xml_file,
480
485
        }
481
    my $generated_xml_content = read_file( $generated_xml_file );
486
    );
487
488
    my $generated_xml_content = read_file($generated_xml_file);
482
    $MARC::File::XML::_load_args{BinaryEncoding} = 'utf-8';
489
    $MARC::File::XML::_load_args{BinaryEncoding} = 'utf-8';
483
    open my $fh, '<', $generated_xml_file;
490
    open my $fh, '<', $generated_xml_file;
484
    my $records = MARC::Batch->new( 'XML', $fh );
491
    my $records = MARC::Batch->new( 'XML', $fh );
Lines 486-519 subtest 'export xml with marc modification template' => sub { Link Here
486
    while ( my $record = $records->next ) {
493
    while ( my $record = $records->next ) {
487
        push @records, $record;
494
        push @records, $record;
488
    }
495
    }
489
    is( scalar( @records ), 1, 'Export XML: 1 record should have been exported' );
496
    is( scalar(@records), 1, 'Export XML: 1 record should have been exported' );
490
    my $record = $records[0];
497
    my $record = $records[0];
491
    is( $record->subfield('999', '9'), 'Foobar', 'Export XML: marc modification template should have added 999$9' );
498
    is( $record->subfield( '998', '9' ), 'Foobar', 'Export XML: marc modification template should have added 998$9' );
492
};
499
};
493
500
494
subtest 'export iso2709 with marc modification template' => sub {
501
subtest 'export iso2709 with marc modification template' => sub {
495
    plan tests => 2;
502
    plan tests => 2;
496
503
497
    my $template_id = C4::MarcModificationTemplates::AddModificationTemplate('test exporter');
504
    my $template_id = C4::MarcModificationTemplates::AddModificationTemplate('test exporter');
498
    C4::MarcModificationTemplates::AddModificationTemplateAction($template_id, 'add_field', 0, '999', '9', 'Foobar');
505
    C4::MarcModificationTemplates::AddModificationTemplateAction( $template_id, 'add_field', 0, '998', '9', 'Foobar' );
499
506
500
    my $generated_mrc_file = '/tmp/test_export.mrc';
507
    my $generated_mrc_file = '/tmp/test_export.mrc';
501
    Koha::Exporter::Record::export({
508
    Koha::Exporter::Record::export(
502
        record_type     => 'bibs',
509
        {
503
        record_ids      => [ $biblionumber_1 ],
510
            record_type                   => 'bibs',
504
        format          => 'iso2709',
511
            record_ids                    => [$biblionumber_1],
505
        marc_modification_template_id => $template_id,
512
            format                        => 'iso2709',
506
        output_filepath => $generated_mrc_file,
513
            marc_modification_template_id => $template_id,
507
    });
514
            output_filepath               => $generated_mrc_file,
508
515
        }
509
    my $records = MARC::File::USMARC->in( $generated_mrc_file );
516
    );
517
518
    my $records = MARC::File::USMARC->in($generated_mrc_file);
510
    my @records;
519
    my @records;
511
    while ( my $record = $records->next ) {
520
    while ( my $record = $records->next ) {
512
        push @records, $record;
521
        push @records, $record;
513
    }
522
    }
514
    is( scalar( @records ), 1, 'Export ISO2709: 1 record should have been exported' );
523
    is( scalar(@records), 1, 'Export ISO2709: 1 record should have been exported' );
515
    my $record = $records[0];
524
    my $record = $records[0];
516
    is( $record->subfield('999', '9'), 'Foobar', 'Export ISO2709: marc modification template should have added 999$9' );
525
    is(
526
        $record->subfield( '998', '9' ), 'Foobar',
527
        'Export ISO2709: marc modification template should have added 998$9'
528
    );
517
};
529
};
518
530
519
$schema->storage->txn_rollback;
531
$schema->storage->txn_rollback;
520
- 

Return to bug 24679