Bug 16284: Add Koha::Biblio->is_serial method
authorJosef Moravec <josef.moravec@gmail.com>
Thu, 18 Apr 2019 07:19:34 +0000 (07:19 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 13 Aug 2019 13:36:04 +0000 (14:36 +0100)
Test plan:
prove t/db_dependent/Koha/Biblio.t

Should return green

Signed-off-by: Michal Denar <black23@gmail.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Koha/Biblio.pm
t/db_dependent/Koha/Biblio.t

index 22adee7..0401268 100644 (file)
@@ -640,6 +640,25 @@ sub get_openurl {
     return $OpenURLResolverURL;
 }
 
+=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
index 7f04ca1..bdf65bd 100644 (file)
@@ -17,7 +17,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 6;
+use Test::More tests => 7;
 
 use C4::Biblio;
 use Koha::Database;
@@ -146,3 +146,27 @@ subtest 'get_coins and get_openurl' => 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;
+};