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

(-)a/t/db_dependent/Koha/Biblio.t (-2 / +109 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 37;
20
use Test::More tests => 39;
21
use Test::Exception;
21
use Test::Exception;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 942-947 subtest 'get_volumes_query' => sub { Link Here
942
    );
942
    );
943
};
943
};
944
944
945
subtest 'generate_marc_host_field' => sub {
946
    plan tests => 22;
947
948
    $schema->storage->txn_begin;
949
950
    t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' );
951
952
    my $biblio = $builder->build_sample_biblio();
953
    my $record = $biblio->metadata->record;
954
    $record->append_fields(
955
        MARC::Field->new( '001', '1234' ),
956
        MARC::Field->new( '003', 'FIRST' ),
957
        MARC::Field->new( '240', '', '', a => 'A uniform title' ),
958
        MARC::Field->new( '260', '', '', a => 'Publication' ),
959
        MARC::Field->new( '250', '', '', a => 'Edition a', b => 'Edition b' ),
960
        MARC::Field->new( '022', '', '', a => '0317-8471' ),
961
    );
962
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
963
    $biblio = Koha::Biblios->find( $biblio->biblionumber );
964
965
    t::lib::Mocks::mock_preference( 'UseControlNumber', '0' );
966
    my $link = $biblio->generate_marc_host_field();
967
968
    is( ref($link), 'MARC::Field', "->generate_marc_host_field returns a MARC::Field object" );
969
    is( $link->tag, '773', "MARC::Field->tag returns '773' when marcflavour is 'MARC21" );
970
    is( $link->subfield('a'), 'Some boring author', 'MARC::Field->subfield(a) returns content from 100ab' );
971
    is( $link->subfield('b'), 'Edition a Edition b', 'MARC::Field->subfield(b) returns content from 250ab' );
972
    is( $link->subfield('d'), 'Publication', 'MARC::Field->subfield(c) returns content from 260abc' );
973
    is( $link->subfield('s'), 'A uniform title', 'MARC::Field->subfield(s) returns content from 240a' );
974
    is( $link->subfield('t'), 'Some boring read', 'MARC::Field->subfield(s) returns content from 245ab' );
975
    is( $link->subfield('x'), '0317-8471', 'MARC::Field->subfield(s) returns content from 022a' );
976
    is( $link->subfield('z'), undef, 'MARC::Field->subfield(s) returns undef when 020a is empty' );
977
    is( $link->subfield('w'), undef, 'MARC::Field->subfield(w) returns undef when "UseControlNumber" is disabled' );
978
979
    t::lib::Mocks::mock_preference( 'UseControlNumber', '1' );
980
    $link = $biblio->generate_marc_host_field();
981
    is( $link->subfield('w'), '(FIRST)1234', 'MARC::Field->subfield(w) returns content from 003 and 001 when "UseControlNumber" is enabled' );
982
983
    # UNIMARC tests
984
    t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' );
985
986
    $biblio = $builder->build_sample_biblio();
987
    $record = $biblio->metadata->record;
988
    $record->append_fields(
989
        MARC::Field->new( '001', '1234' ),
990
        MARC::Field->new( '700', '', '', a => 'A nice author' ),
991
        MARC::Field->new( '210', '', '', a => 'A publication', d => 'A date' ),
992
        MARC::Field->new( '205', '', '', a => "Fun things" ),
993
        MARC::Field->new( '856', '', '', u => 'http://myurl.com/' ),
994
        MARC::Field->new( '011', '', '', a => '0317-8471' ),
995
        MARC::Field->new( '545', '', '', a => 'Invisible on OPAC' ),
996
    );
997
    C4::Biblio::ModBiblio( $record, $biblio->biblionumber );
998
    $biblio = Koha::Biblios->find( $biblio->biblionumber );
999
1000
    $link = $biblio->generate_marc_host_field();
1001
1002
    is( ref($link), 'MARC::Field', "->generate_marc_host_field returns a MARC::Field object" );
1003
    is( $link->tag, '461', "MARC::Field->tag returns '461' when marcflavour is 'UNIMARC" );
1004
    is( $link->subfield('a'), 'A nice author', 'MARC::Field->subfield(a) returns content from 700ab' );
1005
    is( $link->subfield('c'), 'A publication', 'MARC::Field->subfield(b) returns content from 210a' );
1006
    is( $link->subfield('d'), 'A date', 'MARC::Field->subfield(c) returns content from 210d' );
1007
    is( $link->subfield('e'), 'Fun things', 'MARC::Field->subfield(s) returns content from 205' );
1008
    is( $link->subfield('t'), 'Some boring read', 'MARC::Field->subfield(s) returns content from 200a' );
1009
    is( $link->subfield('u'), 'http://myurl.com/', 'MARC::Field->subfield(s) returns content from 856u' );
1010
    is( $link->subfield('x'), '0317-8471', 'MARC::Field->subfield(s) returns content from 011a' );
1011
    is( $link->subfield('y'), undef, 'MARC::Field->subfield(w) returns undef if 010a is empty' );
1012
    is( $link->subfield('0'), '1234', 'MARC::Field->subfield(0) returns content from 001' );
1013
1014
    $schema->storage->txn_rollback;
1015
    t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' );
1016
};
1017
1018
subtest 'link_marc_host' => sub {
1019
    plan tests => 6;
1020
    $schema->storage->txn_begin;
1021
1022
    my $host = $builder->build_sample_biblio();
1023
1024
    my $child = $builder->build_sample_biblio();
1025
    my $child_record = $child->metadata->record;
1026
1027
    is($child_record->field('773'), undef, "773 field is undefined before link_marc_host");
1028
    $child->link_marc_host({ host => $host->biblionumber });
1029
    $child->discard_changes;
1030
    $child_record = $child->metadata->record;
1031
    is(ref($child_record->field('773')), 'MARC::Field', '773 field is set after calling link_marc_host({ host => $biblionumber })');
1032
1033
    $child = $builder->build_sample_biblio();
1034
    $child_record = $child->metadata->record;
1035
    is($child_record->field('773'), undef, "773 field is undefined before link_marc_host");
1036
    $child->link_marc_host({ host => $host });
1037
    $child->discard_changes;
1038
    $child_record = $child->metadata->record;
1039
    is(ref($child_record->field('773')), 'MARC::Field', '773 field is set after calling link_marc_host({ host => $biblio })');
1040
1041
    $child = $builder->build_sample_biblio();
1042
    $child_record = $child->metadata->record;
1043
    is($child_record->field('773'), undef, "773 field is undefined before link_marc_host");
1044
    my $link_field = $host->generate_marc_host_field;
1045
    $child->link_marc_host({ field => $link_field });
1046
    $child->discard_changes;
1047
    $child_record = $child->metadata->record;
1048
    is(ref($child_record->field('773')), 'MARC::Field', '773 field is set after calling link_marc_host({ field => $link_field })');
1049
1050
    $schema->storage->txn_rollback;
1051
};
1052
945
subtest '->orders, ->uncancelled_orders and ->acq_status tests' => sub {
1053
subtest '->orders, ->uncancelled_orders and ->acq_status tests' => sub {
946
1054
947
    plan tests => 9;
1055
    plan tests => 9;
948
- 

Return to bug 29560