From 8ba9d887e32a3f623072ab2db3fed39d1659d15f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 15 Nov 2016 11:37:30 +0000 Subject: [PATCH] Bug 17630: Add the Koha::Biblio->holds method This method will be useful to get the current holds placed on a given bibliographic record. Test plan: prove t/db_dependent/Koha/Biblios.t should return green Signed-off-by: Josef Moravec Signed-off-by: Marcel de Rooy --- Koha/Biblio.pm | 15 ++++++++++++ t/db_dependent/Koha/Biblios.t | 57 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 t/db_dependent/Koha/Biblios.t diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index d9b26b0..d5ca370 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -249,6 +249,21 @@ sub itemtype { return $self->biblioitem()->itemtype(); } +=head3 holds + +my $holds = $biblio->holds(); + +return the current holds placed on this record + +=cut + +sub holds { + my ( $self ) = @_; + + my $holds_rs = $self->_result->reserves; + return Koha::Holds->_new_from_dbic( $holds_rs ); +} + =head3 biblioitem my $field = $self->biblioitem()->itemtype diff --git a/t/db_dependent/Koha/Biblios.t b/t/db_dependent/Koha/Biblios.t new file mode 100644 index 0000000..2498b86 --- /dev/null +++ b/t/db_dependent/Koha/Biblios.t @@ -0,0 +1,57 @@ +#!/usr/bin/perl + +# Copyright 2016 Koha Development team +# +# This file is part of Koha +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Test::More tests => 1; + +use C4::Reserves; + +use Koha::Biblios; +use Koha::Patrons; +use t::lib::TestBuilder; +use t::lib::Mocks; + +my $schema = Koha::Database->new->schema; +$schema->storage->txn_begin; + +my $builder = t::lib::TestBuilder->new; +my $patron = $builder->build( { source => 'Borrower' } ); +$patron = Koha::Patrons->find( $patron->{borrowernumber} ); + +my $biblio = Koha::Biblio->new()->store(); + +my $biblioitem = $schema->resultset('Biblioitem')->new( + { + biblionumber => $biblio->id + } +)->insert(); + +subtest 'holds' => sub { + plan tests => 3; + C4::Reserves::AddReserve( $patron->branchcode, $patron->borrowernumber, $biblio->biblionumber ); + my $holds = $biblio->holds; + is( ref($holds), 'Koha::Holds', '->holds should return a Koha::Holds object' ); + is( $holds->count, 1, '->holds should only return 1 hold' ); + is( $holds->next->borrowernumber, $patron->borrowernumber, '->holds should return the correct hold' ); +}; + +$schema->storage->txn_rollback; + +1; -- 2.9.3