View | Details | Raw Unified | Return to bug 31791
Collapse All | Expand All

(-)a/Koha/Biblio/Metadata.pm (+18 lines)
Lines 23-30 use Scalar::Util qw( blessed ); Link Here
23
use C4::Biblio qw( GetMarcFromKohaField );
23
use C4::Biblio qw( GetMarcFromKohaField );
24
use C4::Charset qw( StripNonXmlChars );
24
use C4::Charset qw( StripNonXmlChars );
25
use C4::Items qw( GetMarcItem );
25
use C4::Items qw( GetMarcItem );
26
26
use Koha::Database;
27
use Koha::Database;
27
use Koha::Exceptions::Metadata;
28
use Koha::Exceptions::Metadata;
29
use Koha::RecordSources;
28
30
29
use base qw(Koha::Object);
31
use base qw(Koha::Object);
30
32
Lines 187-192 sub source_allows_editing { Link Here
187
    return $rs->can_be_edited;
189
    return $rs->can_be_edited;
188
}
190
}
189
191
192
=head3 record_source
193
194
    my $record_source = $metadata->record_source;
195
196
Returns a I<Koha::RecordSource> object for the linked record source.
197
198
=cut
199
200
sub record_source {
201
    my ($self) = @_;
202
203
    my $rs = $self->_result->record_source;
204
    return unless $rs;
205
    return Koha::RecordSource->_new_from_dbic($rs);
206
}
207
190
=head2 Internal methods
208
=head2 Internal methods
191
209
192
=head3 _embed_items
210
=head3 _embed_items
(-)a/t/db_dependent/Koha/Biblio/Metadata.t (-3 / +7 lines)
Lines 267-275 subtest '_embed_items' => sub { Link Here
267
    $schema->storage->txn_rollback;
267
    $schema->storage->txn_rollback;
268
};
268
};
269
269
270
subtest 'source_allows_editing() tests' => sub {
270
subtest 'record_source() and source_allows_editing() tests' => sub {
271
271
272
    plan tests => 4;
272
    plan tests => 7;
273
273
274
    $schema->storage->txn_begin;
274
    $schema->storage->txn_begin;
275
275
Lines 278-288 subtest 'source_allows_editing() tests' => sub { Link Here
278
    my $metadata = $biblio->metadata;
278
    my $metadata = $biblio->metadata;
279
    is( $metadata->record_source_id, undef, 'No record source defined for metatada object' );
279
    is( $metadata->record_source_id, undef, 'No record source defined for metatada object' );
280
    ok( $metadata->source_allows_editing, 'No record source, can be edited' );
280
    ok( $metadata->source_allows_editing, 'No record source, can be edited' );
281
    is( $metadata->record_source, undef );
281
282
282
    my $source = $builder->build_object( { class => 'Koha::RecordSources', value => { can_be_edited => 1 } } );
283
    my $source = $builder->build_object( { class => 'Koha::RecordSources', value => { can_be_edited => 1 } } );
283
    $metadata->record_source_id( $source->id )->store();
284
    $metadata->record_source_id( $source->id )->store();
284
285
286
    my $retrieved_source = $metadata->record_source;
287
285
    ok( $metadata->source_allows_editing, 'Record source allows, can be edited' );
288
    ok( $metadata->source_allows_editing, 'Record source allows, can be edited' );
289
    is( ref($retrieved_source), 'Koha::RecordSource' );
290
    is( $retrieved_source->id,  $source->id );
286
291
287
    $source->can_be_edited(0)->store();
292
    $source->can_be_edited(0)->store();
288
    $metadata->discard_changes;
293
    $metadata->discard_changes;
289
- 

Return to bug 31791