Bug 19830: Add the Koha::Patron->old_checkouts method
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 18 Dec 2017 17:27:52 +0000 (14:27 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 21 Dec 2017 16:21:11 +0000 (13:21 -0300)
Test plan:
  prove t/db_dependent/Koha/Patrons.t
must return green

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/Patron.pm
t/db_dependent/Koha/Patrons.t

index 92e70a5..db2e9ac 100644 (file)
@@ -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
index bea2a02..c90a9f5 100644 (file)
@@ -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;