From 86ce722b88a406ee527dc9c14e2b880f379eb75e Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Thu, 18 Apr 2019 07:19:34 +0000 Subject: [PATCH] Bug 16284: Add Koha::Biblio->is_serial method Test plan: prove t/db_dependent/Koha/Biblio.t should return green --- Koha/Biblio.pm | 19 +++++++++++++++++++ t/db_dependent/Koha/Biblio.t | 27 ++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 56f91859d5..50a6a09398 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -467,6 +467,25 @@ sub has_items_waiting_or_intransit { return 0; } +=head3 is_serial + +my $serial = $biblio->is_serial + +Return boolean true if this bibbliographic record is continuing resource + +=cut + +sub is_serial { + my ( $self ) = @_; + + return 1 if $self->serial; + + my $record = $self->metadata->record; + return 1 if substr($record->leader, 7, 1) eq 's'; + + return 0; +} + =head3 type =cut diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index 72c06e04f9..71f1ea52ed 100644 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; use t::lib::TestBuilder; @@ -86,3 +86,28 @@ subtest 'hidden_in_opac() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'is_serial() tests' => sub { + + plan tests => 3; + + $schema->storage->txn_begin; + + my $biblio = $builder->build_sample_biblio(); + + $biblio->serial( 1 )->store->discard_changes; + ok( $biblio->is_serial, 'Bibliographic record is serial' ); + + $biblio->serial( 0 )->store->discard_changes; + ok( !$biblio->is_serial, 'Bibliographic record is not serial' ); + + my $record = $biblio->metadata->record; + $record->leader('00142nas a22 7a 4500'); + ModBiblio($record, $biblio->biblionumber ); + $biblio = Koha::Biblios->find($biblio->biblionumber); + + ok( $biblio->is_serial, 'Bibliographic record is serial' ); + + $schema->storage->txn_rollback; +}; + -- 2.11.0