From cf57457d34eed3a5fe3aff86ad5fbc9c1147cd81 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 18 Dec 2017 14:27:52 -0300 Subject: [PATCH] Bug 19830: Add the Koha::Patron->old_checkouts method Test plan: prove t/db_dependent/Koha/Patrons.t must return green Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart --- Koha/Patron.pm | 18 +++++++++++++++--- t/db_dependent/Koha/Patrons.t | 26 +++++++++++++++++++++----- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 92e70a5b91..db2e9acad8 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -512,14 +512,26 @@ sub add_enrolment_fee_if_needed { =head3 checkouts -my $issues = $patron->checkouts +my $checkouts = $patron->checkouts =cut sub checkouts { my ($self) = @_; - my $issues = $self->_result->issues; - return Koha::Checkouts->_new_from_dbic( $issues ); + my $checkouts = $self->_result->issues; + return Koha::Checkouts->_new_from_dbic( $checkouts ); +} + +=head3 old_checkouts + +my $old_checkouts = $patron->old_checkouts + +=cut + +sub old_checkouts { + my ($self) = @_; + my $old_checkouts = $self->_result->old_issues; + return Koha::Old::Checkouts->_new_from_dbic( $old_checkouts ); } =head3 get_overdues diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index bea2a02cbb..c90a9f5a0f 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -430,8 +430,8 @@ subtest 'add_enrolment_fee_if_needed' => sub { $patron->delete; }; -subtest 'checkouts + get_overdues' => sub { - plan tests => 8; +subtest 'checkouts + get_overdues + old_checkouts' => sub { + plan tests => 12; my $library = $builder->build( { source => 'Branch' } ); my ($biblionumber_1) = AddBiblio( MARC::Record->new, '' ); @@ -441,7 +441,9 @@ subtest 'checkouts + get_overdues' => sub { value => { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, - biblionumber => $biblionumber_1 + biblionumber => $biblionumber_1, + itemlost => 0, + withdrawn => 0, } } ); @@ -451,7 +453,9 @@ subtest 'checkouts + get_overdues' => sub { value => { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, - biblionumber => $biblionumber_1 + biblionumber => $biblionumber_1, + itemlost => 0, + withdrawn => 0, } } ); @@ -462,7 +466,9 @@ subtest 'checkouts + get_overdues' => sub { value => { homebranch => $library->{branchcode}, holdingbranch => $library->{branchcode}, - biblionumber => $biblionumber_2 + biblionumber => $biblionumber_2, + itemlost => 0, + withdrawn => 0, } } ); @@ -477,6 +483,9 @@ subtest 'checkouts + get_overdues' => sub { my $checkouts = $patron->checkouts; is( $checkouts->count, 0, 'checkouts should not return any issues for that patron' ); is( ref($checkouts), 'Koha::Checkouts', 'checkouts should return a Koha::Checkouts object' ); + my $old_checkouts = $patron->old_checkouts; + is( $old_checkouts->count, 0, 'old_checkouts should not return any issues for that patron' ); + is( ref($old_checkouts), 'Koha::Old::Checkouts', 'old_checkouts should return a Koha::Old::Checkouts object' ); # Not sure how this is useful, but AddIssue pass this variable to different other subroutines $patron = Koha::Patrons->find( $patron->borrowernumber )->unblessed; @@ -499,6 +508,13 @@ subtest 'checkouts + get_overdues' => sub { is( $overdues->next->itemnumber, $item_1->{itemnumber}, 'The issue should be returned in the same order as they have been done, first is correct' ); is( $overdues->next->itemnumber, $item_2->{itemnumber}, 'The issue should be returned in the same order as they have been done, second is correct' ); + + C4::Circulation::AddReturn( $item_1->{barcode} ); + C4::Circulation::AddReturn( $item_2->{barcode} ); + $old_checkouts = $patron->old_checkouts; + is( $old_checkouts->count, 2, 'old_checkouts should return 2 old checkouts that patron' ); + is( ref($old_checkouts), 'Koha::Old::Checkouts', 'old_checkouts should return a Koha::Old::Checkouts object' ); + # Clean stuffs Koha::Checkouts->search( { borrowernumber => $patron->borrowernumber } )->delete; $patron->delete; -- 2.39.5