@@ -, +, @@ $ ktd k$ prove t/db_dependent/Koha/Biblio/Metadata.t --- Koha/Biblio/Metadata.pm | 17 +++++++++++++++++ t/db_dependent/Koha/Biblio/Metadata.t | 27 ++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) --- a/Koha/Biblio/Metadata.pm +++ a/Koha/Biblio/Metadata.pm @@ -170,6 +170,23 @@ sub record_strip_nonxml { return $self->record( { %$params, record => $record } ); } +=head3 source_allows_editing + + if ( $metadata->source_allows_editing ) { ... } + +Returns a boolean denoting whether the metadata's record source allows +it to be edited. + +=cut + +sub source_allows_editing { + my ($self) = @_; + + my $rs = $self->_result->record_source; + return 1 unless $rs; + return $rs->can_be_edited; +} + =head2 Internal methods =head3 _embed_items --- a/t/db_dependent/Koha/Biblio/Metadata.t +++ a/t/db_dependent/Koha/Biblio/Metadata.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; use Test::Exception; use Test::Warn; @@ -266,3 +266,28 @@ subtest '_embed_items' => sub { $schema->storage->txn_rollback; }; + +subtest 'source_allows_editing() tests' => sub { + + plan tests => 4; + + $schema->storage->txn_begin; + + my $biblio = $builder->build_sample_biblio; + + 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' ); + + my $source = $builder->build_object( { class => 'Koha::RecordSources', value => { can_be_edited => 1 } } ); + $metadata->record_source_id( $source->id )->store(); + + ok( $metadata->source_allows_editing, 'Record source allows, can be edited' ); + + $source->can_be_edited(0)->store(); + $metadata->discard_changes; + + ok( !$metadata->source_allows_editing, 'Record source does not allow, cannot be edited' ); + + $schema->storage->txn_rollback; +}; --