From cf5523f7f3ad791703b5aa8d24f0a485e3c1ee3b 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 Return the patron related to a given checkout Test plan: prove t/db_dependent/Koha/Checkouts.t should return green --- 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.9.3