From 7e64e01515c58961cb9e70a30e74305605db5afe Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 20 Mar 2024 09:50:39 -0300 Subject: [PATCH] Bug 31791: Add Koha::Biblio::Metadata->record_source This patch adds a method for retrieving the related *Koha::RecordSource* from a *Koha::Biblio::Metadata* object. The method is covered by tests: 1. Apply this patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/Biblio/Metadata.t => SUCCESS: Tests pass! 3. Sign off :-D Sponsored-by: ByWater Solutions Signed-off-by: Lucas Gass Signed-off-by: Arthur Suzuki Signed-off-by: Katrin Fischer --- Koha/Biblio/Metadata.pm | 18 ++++++++++++++++++ t/db_dependent/Koha/Biblio/Metadata.t | 9 +++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Koha/Biblio/Metadata.pm b/Koha/Biblio/Metadata.pm index 926beda2c5..1b6854f0bf 100644 --- a/Koha/Biblio/Metadata.pm +++ b/Koha/Biblio/Metadata.pm @@ -23,8 +23,10 @@ use Scalar::Util qw( blessed ); use C4::Biblio qw( GetMarcFromKohaField ); use C4::Charset qw( StripNonXmlChars ); use C4::Items qw( GetMarcItem ); + use Koha::Database; use Koha::Exceptions::Metadata; +use Koha::RecordSources; use base qw(Koha::Object); @@ -187,6 +189,22 @@ sub source_allows_editing { return $rs->can_be_edited; } +=head3 record_source + + my $record_source = $metadata->record_source; + +Returns a I object for the linked record source. + +=cut + +sub record_source { + my ($self) = @_; + + my $rs = $self->_result->record_source; + return unless $rs; + return Koha::RecordSource->_new_from_dbic($rs); +} + =head2 Internal methods =head3 _embed_items diff --git a/t/db_dependent/Koha/Biblio/Metadata.t b/t/db_dependent/Koha/Biblio/Metadata.t index 7a45993861..172fd2bb04 100755 --- a/t/db_dependent/Koha/Biblio/Metadata.t +++ b/t/db_dependent/Koha/Biblio/Metadata.t @@ -267,9 +267,9 @@ subtest '_embed_items' => sub { $schema->storage->txn_rollback; }; -subtest 'source_allows_editing() tests' => sub { +subtest 'record_source() and source_allows_editing() tests' => sub { - plan tests => 4; + plan tests => 7; $schema->storage->txn_begin; @@ -278,11 +278,16 @@ subtest 'source_allows_editing() tests' => sub { my $metadata = $biblio->metadata; is( $metadata->record_source_id, undef, 'No record source defined for metatada object' ); ok( $metadata->source_allows_editing, 'No record source, can be edited' ); + is( $metadata->record_source, undef ); my $source = $builder->build_object( { class => 'Koha::RecordSources', value => { can_be_edited => 1 } } ); $metadata->record_source_id( $source->id )->store(); + my $retrieved_source = $metadata->record_source; + ok( $metadata->source_allows_editing, 'Record source allows, can be edited' ); + is( ref($retrieved_source), 'Koha::RecordSource' ); + is( $retrieved_source->id, $source->id ); $source->can_be_edited(0)->store(); $metadata->discard_changes; -- 2.39.5