From 0b0b37860978653016e5d71a24ffed19065c3de9 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Sat, 21 Jan 2017 16:47:03 +0100 Subject: [PATCH] Bug 17973: Add the Koha::Checkout->item method Test plan: prove t/db_dependent/Koha/Checkouts.t should return green --- Koha/Checkout.pm | 15 +++++++++++++++ t/db_dependent/Koha/Checkouts.t | 9 ++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Koha/Checkout.pm b/Koha/Checkout.pm index a1a67d6..40a7ad7 100644 --- a/Koha/Checkout.pm +++ b/Koha/Checkout.pm @@ -25,6 +25,7 @@ use Carp; use Koha::Database; use DateTime; use Koha::DateUtils; +use Koha::Items; use base qw(Koha::Object); @@ -59,6 +60,20 @@ sub is_overdue { return $is_overdue; } +=head3 item + +my $item = $checkout->item; + +Return the checked out item + +=cut + +sub item { + my ( $self ) = @_; + my $item_rs = $self->_result->item; + return Koha::Item->_new_from_dbic( $item_rs ); +} + =head3 type =cut diff --git a/t/db_dependent/Koha/Checkouts.t b/t/db_dependent/Koha/Checkouts.t index ba85bb2..a8eaa69 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 => 5; +use Test::More tests => 6; use Koha::Checkouts; use Koha::Database; @@ -86,6 +86,13 @@ subtest 'is_overdue' => sub { 0, 'In Ten days, the item due yesterday will still be late' ); }; +subtest 'item' => sub { + plan tests => 2; + my $item = $retrieved_checkout_1->item; + is( ref( $item ), 'Koha::Item', 'Koha::Checkout->item should return a Koha::Item' ); + is( $item->itemnumber, $item_1->{itemnumber}, 'Koha::Checkout->item should return the correct item' ); +}; + $retrieved_checkout_1->delete; is( Koha::Checkouts->search->count, $nb_of_checkouts + 1, 'Delete should have deleted the checkout' ); -- 2.1.4