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( |
982 |
$link->subfield('w'), '(FIRST)1234', |
983 |
'MARC::Field->subfield(w) returns content from 003 and 001 when "UseControlNumber" is enabled' |
984 |
); |
985 |
|
986 |
# UNIMARC tests |
987 |
t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' ); |
988 |
|
989 |
$biblio = $builder->build_sample_biblio(); |
990 |
$record = $biblio->metadata->record; |
991 |
$record->append_fields( |
992 |
MARC::Field->new( '001', '1234' ), |
993 |
MARC::Field->new( '700', '', '', a => 'A nice author' ), |
994 |
MARC::Field->new( '210', '', '', a => 'A publication', d => 'A date' ), |
995 |
MARC::Field->new( '205', '', '', a => "Fun things" ), |
996 |
MARC::Field->new( '856', '', '', u => 'http://myurl.com/' ), |
997 |
MARC::Field->new( '011', '', '', a => '0317-8471' ), |
998 |
MARC::Field->new( '545', '', '', a => 'Invisible on OPAC' ), |
999 |
); |
1000 |
C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); |
1001 |
$biblio = Koha::Biblios->find( $biblio->biblionumber ); |
1002 |
|
1003 |
$link = $biblio->generate_marc_host_field(); |
1004 |
|
1005 |
is( ref($link), 'MARC::Field', "->generate_marc_host_field returns a MARC::Field object" ); |
1006 |
is( $link->tag, '461', "MARC::Field->tag returns '461' when marcflavour is 'UNIMARC" ); |
1007 |
is( $link->subfield('a'), 'A nice author', 'MARC::Field->subfield(a) returns content from 700ab' ); |
1008 |
is( $link->subfield('c'), 'A publication', 'MARC::Field->subfield(b) returns content from 210a' ); |
1009 |
is( $link->subfield('d'), 'A date', 'MARC::Field->subfield(c) returns content from 210d' ); |
1010 |
is( $link->subfield('e'), 'Fun things', 'MARC::Field->subfield(s) returns content from 205' ); |
1011 |
is( $link->subfield('t'), 'Some boring read', 'MARC::Field->subfield(s) returns content from 200a' ); |
1012 |
is( $link->subfield('u'), 'http://myurl.com/', 'MARC::Field->subfield(s) returns content from 856u' ); |
1013 |
is( $link->subfield('x'), '0317-8471', 'MARC::Field->subfield(s) returns content from 011a' ); |
1014 |
is( $link->subfield('y'), undef, 'MARC::Field->subfield(w) returns undef if 010a is empty' ); |
1015 |
is( $link->subfield('0'), '1234', 'MARC::Field->subfield(0) returns content from 001' ); |
1016 |
|
1017 |
$schema->storage->txn_rollback; |
1018 |
t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); |
1019 |
}; |
1020 |
|
1021 |
subtest 'link_marc_host' => sub { |
1022 |
plan tests => 6; |
1023 |
$schema->storage->txn_begin; |
1024 |
|
1025 |
my $host = $builder->build_sample_biblio(); |
1026 |
|
1027 |
my $child = $builder->build_sample_biblio(); |
1028 |
my $child_record = $child->metadata->record; |
1029 |
|
1030 |
is( $child_record->field('773'), undef, "773 field is undefined before link_marc_host" ); |
1031 |
$child->link_marc_host( { host => $host->biblionumber } ); |
1032 |
$child->discard_changes; |
1033 |
$child_record = $child->metadata->record; |
1034 |
is( |
1035 |
ref( $child_record->field('773') ), 'MARC::Field', |
1036 |
'773 field is set after calling link_marc_host({ host => $biblionumber })' |
1037 |
); |
1038 |
|
1039 |
$child = $builder->build_sample_biblio(); |
1040 |
$child_record = $child->metadata->record; |
1041 |
is( $child_record->field('773'), undef, "773 field is undefined before link_marc_host" ); |
1042 |
$child->link_marc_host( { host => $host } ); |
1043 |
$child->discard_changes; |
1044 |
$child_record = $child->metadata->record; |
1045 |
is( |
1046 |
ref( $child_record->field('773') ), 'MARC::Field', |
1047 |
'773 field is set after calling link_marc_host({ host => $biblio })' |
1048 |
); |
1049 |
|
1050 |
$child = $builder->build_sample_biblio(); |
1051 |
$child_record = $child->metadata->record; |
1052 |
is( $child_record->field('773'), undef, "773 field is undefined before link_marc_host" ); |
1053 |
my $link_field = $host->generate_marc_host_field; |
1054 |
$child->link_marc_host( { field => $link_field } ); |
1055 |
$child->discard_changes; |
1056 |
$child_record = $child->metadata->record; |
1057 |
is( |
1058 |
ref( $child_record->field('773') ), 'MARC::Field', |
1059 |
'773 field is set after calling link_marc_host({ field => $link_field })' |
1060 |
); |
1061 |
|
1062 |
$schema->storage->txn_rollback; |
1063 |
}; |
1064 |
|
945 |
subtest '->orders, ->uncancelled_orders and ->acq_status tests' => sub { |
1065 |
subtest '->orders, ->uncancelled_orders and ->acq_status tests' => sub { |
946 |
|
1066 |
|
947 |
plan tests => 9; |
1067 |
plan tests => 9; |
948 |
- |
|
|