From 69d1b97242e6559e714738c2a8b635018261d840 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 8 Sep 2017 09:41:21 -0300 Subject: [PATCH] Bug 19277: Make sure the tests will pass even if they are slow 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. --- C4/Members.pm | 9 +++++---- t/db_dependent/Letters/TemplateToolkit.t | 14 ++++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 166b051e74..f31ef8d40c 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -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); diff --git a/t/db_dependent/Letters/TemplateToolkit.t b/t/db_dependent/Letters/TemplateToolkit.t index f85825f8a7..611b936d6a 100644 --- a/t/db_dependent/Letters/TemplateToolkit.t +++ b/t/db_dependent/Letters/TemplateToolkit.t @@ -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} ); -- 2.11.0