From f22017888c014c5d01b56d442b6bacafd4019fb1 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 18 Jan 2019 10:50:15 -0500 Subject: [PATCH] Bug 22144 [QA Followup]: Move Koha::Biblio::marc to Koha::Biblio::Metadata::record --- Koha/Biblio.pm | 26 +++++++++++--------------- Koha/Biblio/Metadata.pm | 24 ++++++++++++++++++++++++ t/db_dependent/Koha/Biblio.t | 11 +++++++---- 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 8ce19ef02d..d2e4d4d321 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -28,12 +28,13 @@ use Koha::DateUtils qw( dt_from_string ); use base qw(Koha::Object); -use Koha::Items; -use Koha::Biblioitems; -use Koha::ArticleRequests; use Koha::ArticleRequest::Status; +use Koha::ArticleRequests; +use Koha::Biblio::Metadatas; +use Koha::Biblioitems; use Koha::IssuingRules; use Koha::Item::Transfer::Limits; +use Koha::Items; use Koha::Libraries; use Koha::Subscriptions; @@ -61,25 +62,20 @@ sub store { return $self->SUPER::store; } -=head3 marc - -my @marc = $biblio->marc($params); +=head3 metadata -Returns a MARC::Record object for a record. +my $metadata = $biblio->metadata(); -This method accepts the same paramters as C4::Biblio::GetMarcBiblio, -but does not require the 'biblionumber' parameter. +Returns a Koha::Biblio::Metadata object =cut -sub marc { - my ( $self, $params ) = @_; - - $params->{biblionumber} = $self->id; +sub metadata { + my ( $self ) = @_; - my $marc = C4::Biblio::GetMarcBiblio($params); + $self->{_metadata} ||= Koha::Biblio::Metadatas->find( { biblionumber => $self->id } ); - return $marc; + return $self->{_metadata}; } =head3 subtitles diff --git a/Koha/Biblio/Metadata.pm b/Koha/Biblio/Metadata.pm index f271f6f824..cf553731b0 100644 --- a/Koha/Biblio/Metadata.pm +++ b/Koha/Biblio/Metadata.pm @@ -19,6 +19,8 @@ use Modern::Perl; use Carp; +use C4::Biblio qw(); + use Koha::Database; use base qw(Koha::Object); @@ -33,6 +35,28 @@ Koha::Metadata - Koha Metadata Object class =cut +=head3 record + +my @record = $biblio->record($params); + +Returns a MARC::Record object for a record. + +This method accepts the same paramters as C4::Biblio::GetMarcBiblio, +but does not require the 'biblionumber' parameter. + +=cut + +sub record { + my ( $self, $params ) = @_; + + $params->{biblionumber} = $self->biblionumber; + + my $record = C4::Biblio::GetMarcBiblio($params); + + return $record; +} + + =head3 type =cut diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index 8984ae8454..5605f79028 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -36,7 +36,7 @@ $schema->storage->txn_begin; my $dbh = C4::Context->dbh; subtest 'Test Koha::Biblio::marc()' => sub { - plan tests => 3; + plan tests => 4; my $title = 'Oranges and Peaches'; @@ -48,10 +48,13 @@ subtest 'Test Koha::Biblio::marc()' => sub { my $biblio = Koha::Biblios->find( $biblionumber ); is( ref $biblio, 'Koha::Biblio', 'Found a Koha::Biblio object' ); - my $marc = $biblio->marc(); - is( ref $marc, 'MARC::Record', 'Method marc() returned a MARC::Record object' ); + my $metadata = $biblio->metadata; + is( ref $metadata, 'Koha::Biblio::Metadata', 'Method metadata() returned a Koha::Biblio::Metadata object' ); - is( $marc->field('245')->subfield("a"), $title, 'Title in 245$a matches title from original record object' ); + my $record2 = $metadata->record(); + is( ref $record2, 'MARC::Record', 'Method record() returned a MARC::Record object' ); + + is( $record2->field('245')->subfield("a"), $title, 'Title in 245$a matches title from original record object' ); }; $schema->storage->txn_rollback; -- 2.17.2 (Apple Git-113)