@@ -, +, @@ $ ktd --shell k$ prove t/db_dependent/Koha/Biblio/Metadata.t --- Koha/Biblio/Metadata.pm | 18 ++++++++++++++++++ t/db_dependent/Koha/Biblio/Metadata.t | 9 +++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) --- a/Koha/Biblio/Metadata.pm +++ a/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 --- a/t/db_dependent/Koha/Biblio/Metadata.t +++ a/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; --