Bug 17974: Add the Koha::Item->biblio method
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Sat, 21 Jan 2017 15:45:34 +0000 (16:45 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 17 Feb 2017 12:11:54 +0000 (12:11 +0000)
Test plan:
  prove t/db_dependent/Koha/Items.t
should return green

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Koha/Item.pm
t/db_dependent/Koha/Items.t

index 52a7700..da3d11a 100644 (file)
@@ -77,6 +77,20 @@ sub holding_branch {
     return $self->{_holding_branch};
 }
 
+=head3 biblio
+
+my $biblio = $item->biblio;
+
+Return the bibliographic record of this item
+
+=cut
+
+sub biblio {
+    my ( $self ) = @_;
+    my $biblio_rs = $self->_result->biblio;
+    return Koha::Biblio->_new_from_dbic( $self->_result->biblio );
+}
+
 =head3 get_transfer
 
 my $transfer = $item->get_transfer;
index 843bf44..c9d4bac 100644 (file)
@@ -19,7 +19,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 5;
+use Test::More tests => 6;
 
 use C4::Circulation;
 use Koha::Item;
@@ -74,6 +74,14 @@ subtest 'get_transfer' => sub {
     is( $transfer->itemnumber, $new_item_1->itemnumber, 'Koha::Item->get_transfer should return a valid Koha::Item::Transfers object' );
 };
 
+subtest 'biblio' => sub {
+    plan tests => 2;
+
+    my $biblio = $retrieved_item_1->biblio;
+    is( ref( $biblio ), 'Koha::Biblio', 'Koha::Item->bilio should return a Koha::Biblio' );
+    is( $biblio->biblionumber, $retrieved_item_1->biblionumber, 'Koha::Item->biblio should return the correct biblio' );
+};
+
 $retrieved_item_1->delete;
 is( Koha::Items->search->count, $nb_of_items + 1, 'Delete should have deleted the item' );