|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 16; |
20 |
use Test::More tests => 17; |
| 21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
| 22 |
use Test::Warn; |
22 |
use Test::Warn; |
| 23 |
use List::MoreUtils qw( uniq ); |
23 |
use List::MoreUtils qw( uniq ); |
|
Lines 759-764
subtest 'ModBiblio called from linker test' => sub {
Link Here
|
| 759 |
is($called,0,"We didn't call to link bibs because from linker"); |
759 |
is($called,0,"We didn't call to link bibs because from linker"); |
| 760 |
}; |
760 |
}; |
| 761 |
|
761 |
|
|
|
762 |
subtest "LinkBibHeadingsToAuthorities tests" => sub { |
| 763 |
plan tests => 5; |
| 764 |
|
| 765 |
# Set up mocks to return more than 1 match |
| 766 |
my $biblio_mod = Test::MockModule->new( 'C4::Linker::Default' ); |
| 767 |
$biblio_mod->mock( 'get_link', sub { |
| 768 |
return (undef, undef, 2); |
| 769 |
}); |
| 770 |
# UNIMARC return values should be consistent with MARC21 |
| 771 |
# testing with MARC21 should be sufficient for now |
| 772 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
| 773 |
t::lib::Mocks::mock_preference('AutoCreateAuthorities', '0'); |
| 774 |
|
| 775 |
my $linker = C4::Linker::Default->new(); |
| 776 |
my $biblio = $builder->build_sample_biblio(); |
| 777 |
my $record = $biblio->metadata->record; |
| 778 |
|
| 779 |
# Generate a field, no current link |
| 780 |
my $field = MARC::Field->new('650','','','a' => 'Duplicated' ); |
| 781 |
|
| 782 |
$record->append_fields($field); |
| 783 |
my ( $num_headings_changed, $results ) = LinkBibHeadingsToAuthorities( $linker, $record, "", undef, 650, 1 ); |
| 784 |
is( $num_headings_changed, 0, 'We did not make any changes because we found 2' ); |
| 785 |
is_deeply( $results->{unlinked}, |
| 786 |
{"Duplicated" => 1 }, |
| 787 |
"The heading was not linked" |
| 788 |
); |
| 789 |
is_deeply( $results->{details}[0], |
| 790 |
{ |
| 791 |
tag => 650, |
| 792 |
authid => undef, |
| 793 |
status => 'MULTIPLE_MATCH', |
| 794 |
auth_type => 'TOPIC_TERM', |
| 795 |
tag_to_report => 150 |
| 796 |
}, |
| 797 |
"The heading was not linked" |
| 798 |
); |
| 799 |
|
| 800 |
t::lib::Mocks::mock_preference('AutoCreateAuthorities', '1'); |
| 801 |
( $num_headings_changed, $results ) = LinkBibHeadingsToAuthorities( $linker, $record, "", undef, 650, 1 ); |
| 802 |
is( $num_headings_changed, 0, 'We did not make any changes because we found 2' ); |
| 803 |
is_deeply( $results->{details}[0], |
| 804 |
{ |
| 805 |
tag => 650, |
| 806 |
authid => undef, |
| 807 |
status => 'MULTIPLE_MATCH', |
| 808 |
auth_type => 'TOPIC_TERM', |
| 809 |
tag_to_report => 150 |
| 810 |
}, |
| 811 |
"When AutoCreateAuthorities is enabled, multiple results are reported" |
| 812 |
); |
| 813 |
|
| 814 |
}; |
| 815 |
|
| 762 |
subtest "LinkBibHeadingsToAuthorities record generation tests" => sub { |
816 |
subtest "LinkBibHeadingsToAuthorities record generation tests" => sub { |
| 763 |
plan tests => 12; |
817 |
plan tests => 12; |
| 764 |
|
818 |
|
| 765 |
- |
|
|