Bug 19277: Make sure the tests will pass even if they are slow
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 8 Sep 2017 12:41:21 +0000 (09:41 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 12 Sep 2017 14:29:11 +0000 (11:29 -0300)
This patch was my first attempt to fix the issue.
I think it is good to have it, if issue.timestamp and issue.issuedate are the same,
the result will be orderd by issue_id.
The tests highlight the fact that checkouts must be displayed in the
correct order.

Signed-off-by: Lee Jamison <ldjamison@marywood.edu>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
C4/Members.pm
t/db_dependent/Letters/TemplateToolkit.t

index 166b051..f31ef8d 100644 (file)
@@ -1129,11 +1129,12 @@ sub IssueSlip {
         }
     }
 
-    # Sort on timestamp then on issuedate (useful for tests and could be if modified in a batch
+    # Sort on timestamp then on issuedate then on issue_id
+    # useful for tests and could be if modified in a batch
     @issues = sort {
-        my $s = $b->{timestamp} <=> $a->{timestamp};
-        $s == 0 ?
-             $b->{issuedate} <=> $a->{issuedate} : $s;
+            $b->{timestamp} <=> $a->{timestamp}
+         or $b->{issuedate} <=> $a->{issuedate}
+         or $b->{issue_id}  <=> $a->{issue_id}
     } @issues;
 
     my ($letter_code, %repeat, %loops);
index f85825f..611b936 100644 (file)
@@ -600,6 +600,8 @@ EOF
         plan tests => 2;
 
         my $code = 'ISSUESLIP';
+        my $now = dt_from_string;
+        my $one_minute_ago = dt_from_string->subtract( minutes => 1 );
 
         my $branchcode = $library->{branchcode};
 
@@ -647,10 +649,12 @@ EOF
 
         reset_template( { template => $template, code => $code, module => 'circulation' } );
 
-        C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout
+        my $checkout = C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout
+        $checkout->set_columns( { timestamp => $now, issuedate => $one_minute_ago } )->update; # FIXME $checkout is a Koha::Schema::Result::Issues, must be a Koha::Checkout
         my $first_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} );
 
-        C4::Circulation::AddIssue( $patron, $item2->{barcode} ); # Add a second checkout
+        $checkout = C4::Circulation::AddIssue( $patron, $item2->{barcode} ); # Add a second checkout
+        $checkout->set_columns( { timestamp => $now, issuedate => $now } )->update;
         my $yesterday = dt_from_string->subtract( days => 1 );
         C4::Circulation::AddIssue( $patron, $item3->{barcode}, $yesterday ); # Add an overdue
         my $second_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} );
@@ -705,10 +709,12 @@ EOF
 
         reset_template( { template => $tt_template, code => $code, module => 'circulation' } );
 
-        C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout
+        $checkout = C4::Circulation::AddIssue( $patron, $item1->{barcode} ); # Add a first checkout
+        $checkout->set_columns( { timestamp => $now, issuedate => $one_minute_ago } )->update;
         my $first_tt_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} );
 
-        C4::Circulation::AddIssue( $patron, $item2->{barcode} ); # Add a second checkout
+        $checkout = C4::Circulation::AddIssue( $patron, $item2->{barcode} ); # Add a second checkout
+        $checkout->set_columns( { timestamp => $now, issuedate => $now } )->update;
         C4::Circulation::AddIssue( $patron, $item3->{barcode}, $yesterday ); # Add an overdue
         my $second_tt_slip = C4::Members::IssueSlip( $branchcode, $patron->{borrowernumber} );