Bug 20310: (follow-up) Rename method to get_marc_host
This method is a mix of database relationship accessor and marc field accessor. We have get_marc_notes already and other patches in the queue are also starting to introduce get_marc_* named methods. This patch updates the method name to conform with that scheme. Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
472538b17d
commit
ea8d8945b7
|
|
@ -891,11 +891,11 @@ sub to_api_mapping {
|
|||
};
|
||||
}
|
||||
|
||||
=head3 host_record
|
||||
=head3 get_marc_host
|
||||
|
||||
$host = $biblio->host_record;
|
||||
$host = $biblio->get_marc_host;
|
||||
# OR:
|
||||
( $host, $relatedparts ) = $biblio->host_record;
|
||||
( $host, $relatedparts ) = $biblio->get_marc_host;
|
||||
|
||||
Returns host biblio record from MARC21 773 (undef if no 773 present).
|
||||
It looks at the first 773 field with MARCorgCode or only a control
|
||||
|
|
@ -906,7 +906,7 @@ sub to_api_mapping {
|
|||
|
||||
=cut
|
||||
|
||||
sub host_record {
|
||||
sub get_marc_host {
|
||||
my ($self, $params) = @_;
|
||||
my $no_items = $params->{no_items};
|
||||
return if C4::Context->preference('marcflavour') eq 'UNIMARC'; # TODO
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ if ( $action eq 'create' ) {
|
|||
}
|
||||
elsif ( !$action && C4::Context->preference('ArticleRequestsHostRedirection') ) {
|
||||
# Conditions: no items, host item entry (MARC21 773)
|
||||
my ( $host, $pageinfo ) = $biblio->host_record( { no_items => 1 } );
|
||||
my ( $host, $pageinfo ) = $biblio->get_marc_host( { no_items => 1 } );
|
||||
if ($host) {
|
||||
$template->param(
|
||||
pageinfo => $pageinfo,
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ my $schema = Koha::Database->new->schema;
|
|||
$schema->storage->txn_begin;
|
||||
our $builder = t::lib::TestBuilder->new;
|
||||
|
||||
subtest 'host_record' => sub {
|
||||
subtest 'get_marc_host' => sub {
|
||||
plan tests => 11;
|
||||
|
||||
t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' );
|
||||
|
|
@ -58,40 +58,40 @@ subtest 'host_record' => sub {
|
|||
$search_mod->mock( 'new', sub { return $engine; } );
|
||||
|
||||
# Case 1: Search engine does not return any results on controlnumber
|
||||
is( $bib1->host_record, undef, 'Empty MARC record' );
|
||||
is( $bib1->get_marc_host, undef, 'Empty MARC record' );
|
||||
$marc->append_fields(
|
||||
MARC::Field->new( '773', '', '', g => 'relpart', w => '(xyz)123' ),
|
||||
);
|
||||
is( $bib1->host_record, undef, '773 looks fine, but no search results' );
|
||||
is( $bib1->get_marc_host, undef, '773 looks fine, but no search results' );
|
||||
|
||||
# Case 2: Search engine returns (at maximum) one result
|
||||
$results = [ $bib1->biblionumber ]; # will be found because 773w is in shape
|
||||
my $host = $bib1->host_record;
|
||||
my $host = $bib1->get_marc_host;
|
||||
is( ref( $host ), 'Koha::Biblio', 'Correct object returned' );
|
||||
is( $host->biblionumber, $bib1->biblionumber, 'Check biblionumber' );
|
||||
$marc->field('773')->update( w => '(xyz) bad data' ); # causes no results
|
||||
$host = $bib1->host_record;
|
||||
is( $bib1->host_record, undef, 'No results for bad 773' );
|
||||
$host = $bib1->get_marc_host;
|
||||
is( $bib1->get_marc_host, undef, 'No results for bad 773' );
|
||||
# Add second 773
|
||||
$marc->append_fields( MARC::Field->new( '773', '', '', g => 'relpart2', w => '234' ) );
|
||||
$host = $bib1->host_record;
|
||||
$host = $bib1->get_marc_host;
|
||||
is( $host->biblionumber, $bib1->biblionumber, 'Result triggered by second 773' );
|
||||
# Replace orgcode
|
||||
($marc->field('773'))[1]->update( w => '(abc)345' );
|
||||
is( $bib1->host_record, undef, 'No results for two 773s' );
|
||||
is( $bib1->get_marc_host, undef, 'No results for two 773s' );
|
||||
# Test no_items flag
|
||||
($marc->field('773'))[1]->update( w => '234' ); # restore
|
||||
$host = $bib1->host_record({ no_items => 1 });
|
||||
$host = $bib1->get_marc_host({ no_items => 1 });
|
||||
is( $host->biblionumber, $bib1->biblionumber, 'Record found with no_items' );
|
||||
$builder->build({ source => 'Item', value => { biblionumber => $bib1->biblionumber } });
|
||||
is( $bib1->host_record({ no_items => 1 }), undef, 'Record not found with no_items flag after adding one item' );
|
||||
is( $bib1->get_marc_host({ no_items => 1 }), undef, 'Record not found with no_items flag after adding one item' );
|
||||
# Test list context
|
||||
my @temp = $bib1->host_record;
|
||||
my @temp = $bib1->get_marc_host;
|
||||
is( $temp[1], 'relpart2', 'Return $g in list context' );
|
||||
|
||||
# Case 3: Search engine returns more results
|
||||
$results = [ 1, 2 ];
|
||||
is( $bib1->host_record, undef, 'host_record returns undef for non-unique control number' );
|
||||
is( $bib1->get_marc_host, undef, 'get_marc_host returns undef for non-unique control number' );
|
||||
};
|
||||
|
||||
sub mocked_search {
|
||||
|
|
|
|||
Loading…
Reference in New Issue