From 11947098a250de500e458af75c88948afa7cd330 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 5 Apr 2017 16:42:26 -0300 Subject: [PATCH] Bug 18401: Add new method Koha::Checkout->patron MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Return the patron related to a given checkout Test plan: prove t/db_dependent/Koha/Checkouts.t should return green Signed-off-by: Marc VĂ©ron --- Koha/Checkout.pm | 14 ++++++++++++++ t/db_dependent/Koha/Checkouts.t | 9 ++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Koha/Checkout.pm b/Koha/Checkout.pm index 40a7ad7..b7a752c 100644 --- a/Koha/Checkout.pm +++ b/Koha/Checkout.pm @@ -74,6 +74,20 @@ sub item { return Koha::Item->_new_from_dbic( $item_rs ); } +=head3 patron + +my $patron = $checkout->patron + +Return the patron for who the checkout has been done + +=cut + +sub patron { + my ( $self ) = @_; + my $patron_rs = $self->_result->borrower; + return Koha::Patron->_new_from_dbic( $patron_rs ); +} + =head3 type =cut diff --git a/t/db_dependent/Koha/Checkouts.t b/t/db_dependent/Koha/Checkouts.t index a8eaa69..89b0126 100644 --- a/t/db_dependent/Koha/Checkouts.t +++ b/t/db_dependent/Koha/Checkouts.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 6; +use Test::More tests => 7; use Koha::Checkouts; use Koha::Database; @@ -93,6 +93,13 @@ subtest 'item' => sub { is( $item->itemnumber, $item_1->{itemnumber}, 'Koha::Checkout->item should return the correct item' ); }; +subtest 'patron' => sub { + plan tests => 2; + my $p = $new_checkout_1->patron; + is( ref($p), 'Koha::Patron', 'Koha::Checkout->patron should return a Koha::Patron' ); + is( $p->borrowernumber, $patron->{borrowernumber}, 'Koha::Checkout->patron should return the correct patron' ); +}; + $retrieved_checkout_1->delete; is( Koha::Checkouts->search->count, $nb_of_checkouts + 1, 'Delete should have deleted the checkout' ); -- 2.1.4